Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Added logging #74

Merged
merged 2 commits into from
Apr 10, 2024
Merged

feat: Added logging #74

merged 2 commits into from
Apr 10, 2024

Conversation

thulasirajkomminar
Copy link
Contributor

@thulasirajkomminar thulasirajkomminar commented Apr 3, 2024

Closes #73

Proposed Changes

Briefly describe your proposed changes:

Added log package to solve issue #73

Checklist

  • CHANGELOG.md updated
  • Rebased/mergeable
  • A test has been added if appropriate
  • Tests pass
  • Commit messages are conventional
  • Sign CLA (if not already signed)

Copy link
Member

@bednar bednar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thulasirajkomminar thanks for your PR 👍

We want to keep the client source base as simple as possible, so the logging infrastructure should be also simple.

What do you think about add simple logger implementation like following code?

client.go:

var logger *log.Logger

var logLevels = map[string]bool{
	"debug": true,
	"info":  true,
	"warn":  true,
	"error": true,
}

// ConfigureLogger initializes logger with specified log levels.
// Supported levels: debug, info, warn, error.
func ConfigureLogger(levels map[string]bool) {
	for level, enabled := range levels {
		if _, exists := logLevels[level]; exists {
			logLevels[level] = enabled
		}
	}
}

initialialize this logger in New function:

logger = log.New(os.Stdout, "influxdb3-go: ", log.LstdFlags)
ConfigureLogger(map[string]bool{"debug": true, "info": true, "warn": false, "error": true})

and use it in point_values.go:

func (pv *PointValues) SetTag(name string, value string) *PointValues {
	if value == "" {
		if enabled, ok := logLevels["debug"]; ok && enabled {
			logger.Printf("Empty tags has no effect, tag [%s], measurement [%s]\n", name, pv.MeasurementName)
		}
	} else {
		pv.Tags[name] = value
	}
	return pv
}

also you can enhance the above implementation with enum-like-constants:

type LogLevel int

const (
	Debug LogLevel = iota
	Info
	Warn
	Error
)

@thulasirajkomminar
Copy link
Contributor Author

thulasirajkomminar commented Apr 3, 2024

@bednar Thought about just adding a simple logger but then I wanted to follow the V2 standards :) . So I like this simple implementation so modified my commit.
Should we add log level to ClientConfig or should we override the defaults like this on the user side
influxdb3.ConfigureLogger(map[string]bool{"debug": false, "info": true, "warn": false, "error": true})

@bednar
Copy link
Member

bednar commented Apr 4, 2024

Should we add log level to ClientConfig or should we override the defaults like this on the user side influxdb3.ConfigureLogger(map[string]bool{"debug": false, "info": true, "warn": false, "error": true})

Good catch! 👍 You are right it should be a part of ClientConfig.

@thulasirajkomminar
Copy link
Contributor Author

Should we add log level to ClientConfig or should we override the defaults like this on the user side influxdb3.ConfigureLogger(map[string]bool{"debug": false, "info": true, "warn": false, "error": true})

Good catch! 👍 You are right it should be a part of ClientConfig.

@bednar could you verify?

@thulasirajkomminar thulasirajkomminar changed the title feat: Added log package feat: Added logging Apr 4, 2024
Copy link
Member

@bednar bednar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For simplify our codebase we can use default logger:

influxdb3/point_values.go Outdated Show resolved Hide resolved
@thulasirajkomminar
Copy link
Contributor Author

For simplify our codebase we can use default logger:

@bednar Could you have a look?

Copy link
Member

@bednar bednar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thulasirajkomminar thanks again for your PR 👍

There is only little change in CHANGELOG.md. After that we will be able to merge PR:

CHANGELOG.md Outdated Show resolved Hide resolved
Copy link
Member

@bednar bednar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

We will merge the PR after we fix our CI to support PRs from forked repository.

@alespour
Copy link
Contributor

I think the PR needs to be rebased or main merged into it to use fixed CI and have workflow check pass.

Code coverage check will probably fail because code coverage will decrease as there is quite a few lines not covered by unit tests (#80), but that could be ignored for now...

thulasirajkomminar and others added 2 commits April 10, 2024 13:43
Co-authored-by: Jakub Bednář <jakub.bednar@gmail.com>
Copy link

codecov bot commented Apr 10, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 74.54%. Comparing base (94c8385) to head (bad20af).

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #74      +/-   ##
==========================================
- Coverage   83.09%   74.54%   -8.56%     
==========================================
  Files          12       12              
  Lines         994      994              
==========================================
- Hits          826      741      -85     
- Misses        138      228      +90     
+ Partials       30       25       -5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@bednar bednar merged commit f0bf1b6 into InfluxCommunity:main Apr 10, 2024
8 of 9 checks passed
@bednar bednar added this to the 0.7.0 milestone Apr 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SetTag function uses print function instead of logger
3 participants