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: add ability to specify labels for all loggers #105

Merged
merged 2 commits into from
Feb 26, 2021

Conversation

lanzafame
Copy link
Contributor

Resolves #104.

setup.go Outdated
@@ -33,6 +33,7 @@ const (
envLoggingURL = "GOLOG_URL" // url that will be processed by sink in the zap

envLoggingOutput = "GOLOG_OUTPUT" // possible values: stdout|stderr|file combine multiple values with '+'
envLoggingLabels = "GOLOG_LOG_LABELS" // comma-separated key-value pairs, i.e. "app,example_app,dc,sjc-1"
Copy link
Member

Choose a reason for hiding this comment

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

How about app:example_app,dc=sjc-1, or app=example_app dc=sjc-1, etc. The current syntax will be very easy to get wrong.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is app=example_app,dc=sjc-1 suitable? You mixed the assignment operator in the first example and I am not sure if that is on purpose.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, sorry, that wasn't on purpose. Your solution also works. Really, anything where I can easily read the labels and understand what's going on.

setup.go Outdated
@@ -122,6 +126,13 @@ func SetupLogging(cfg Config) {
}

newPrimaryCore := newCore(primaryFormat, ws, LevelDebug) // the main core needs to log everything.

if len(cfg.Labels) > 0 {
Copy link
Member

Choose a reason for hiding this comment

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

This condition isn't necessary (the loop will catch it).

setup.go Outdated
@@ -122,6 +126,13 @@ func SetupLogging(cfg Config) {
}

newPrimaryCore := newCore(primaryFormat, ws, LevelDebug) // the main core needs to log everything.

if len(cfg.Labels) > 0 {
for i := 0; i < len(cfg.Labels); i=i+2 {
Copy link
Member

Choose a reason for hiding this comment

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

nit: i+=2.

setup.go Outdated
@@ -61,6 +62,9 @@ type Config struct {

// URL with schema supported by zap. Use zap.RegisterSink
URL string

// Labels is a set of key-values to apply to all loggers
Labels []string
Copy link
Member

Choose a reason for hiding this comment

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

This should be a map (or a slice of Label{Key, Value string} structs). The format we use in environment variables shouldn't leak into the go API.

Copy link
Member

@Stebalien Stebalien left a comment

Choose a reason for hiding this comment

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

LGTM! Merge and release when ready.

@Stebalien
Copy link
Member

(well, except the tests, not sure what's up with those)

@lanzafame
Copy link
Contributor Author

I can confirm the tests pass locally. I haven't dug into what the circleci issue is...

@Stebalien
Copy link
Member

Hm. The CircleCI deploy key got deleted.

@Stebalien Stebalien merged commit d21354f into master Feb 26, 2021
@Stebalien Stebalien deleted the feat/label-env-var branch February 26, 2021 01:41
@Stebalien Stebalien mentioned this pull request May 11, 2021
27 tasks
@aschmahmann aschmahmann mentioned this pull request May 14, 2021
71 tasks
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.

Add ability to specify global zap logger With labels
2 participants