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

Graylog uses the level key for its rotation #736

Open
l-vitaly opened this issue Jul 27, 2018 · 8 comments
Open

Graylog uses the level key for its rotation #736

l-vitaly opened this issue Jul 27, 2018 · 8 comments

Comments

@l-vitaly
Copy link

l-vitaly commented Jul 27, 2018

Can you add changes to the key name?

For example: level.Key = "@level"

@ChrisHines
Copy link
Member

Thanks for filing an issue, but I don't understand what you're asking. Are you reporting a bug, asking for a feature, or asking for advice about how to use the existing packages to solve a specific problem. Please clarify.

@l-vitaly
Copy link
Author

Graylog uses the "level" key for its rotation, there is a conflict, I suggest making it possible to change the key name in gokit

@ChrisHines
Copy link
Member

The same feature was requested in #592 and #503. We haven't implemented this as a feature in the log/level package for the reasons explained in the second link. In that discussion I also provided an example workaround you can implement in your own code to get the desired behavior.

Now that we've had three requests for the same feature the argument add it seems stronger. What do you think @peterbourgon?

@peterbourgon
Copy link
Member

peterbourgon commented Aug 1, 2018

I'm keen to see this possible. Unfortunately, I'm not sure how to do it without futzing with package-global state. edit: Maybe we could add the SetLevelKey decorator (or something like it) proposed in #503 to the package.

@awilliams
Copy link

awilliams commented Aug 3, 2018

I'd like to propose an alternative solution. It involves modifying the level package in a way similar to the following:

var (
	keyStr = ""
	key interface{}
)

func init() {
	if envKey := os.Getenv("KIT_LEVELKEY"); envKey != "" {
		keyStr = envKey
	}
	if keyStr == "" {
		keyStr = "level"
	}
	key = keyStr
}

With this modification, users would have the option to change the level key in two ways:

  • At build time using build flags, eg:

    $ go build \
    	-ldflags "-X 'github.com/go-kit/kit/log/level.keyStr=@level'"
  • At runtime via an environment variable, eg:

    $ KIT_LEVELKEY=@level ./my-app

Without modification, the default level key would be used.


Note: When testing this, I ran into an issue with the following structure:

var keyStr = "level"
var key interface{} = keyStr

It seemed like the compiler would make an optimization and remove keyStr, making it impossible to target it via build flags.

@peterbourgon
Copy link
Member

Package global configuration via env var in init is a non-starter, sorry.

@ChrisHines
Copy link
Member

@peterbourgon What do you think of the -ldflags idea, though, if the env var part was removed?

@peterbourgon
Copy link
Member

Ah, interesting, I must have missed that bit. It's clever! I like it. Is it good enough for the users who need it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants