romana / rlog

A simple Golang logger without external dependencies
Apache License 2.0
39 stars 14 forks source link

Provide function to change logging parameters programmatically #2

Closed jbrendel closed 6 years ago

jbrendel commented 7 years ago

Currently, all configuration is done via environment variables. Sometimes, however, it may be useful to change the logging parameters at run time.

We already have a function to change the output stream (for example to a new log file), but it would be nice to also be able to change the other logging parameters.

As an extension of this: It might be good to be able to programmatically query the current parameters in an easy manner. The program could just read the environment variables, but rlog itself could provide a convenient facility for that.

imarsman commented 7 years ago

I was very happy to find this project. It is very well suited to a project I am working on. Thank-you! I also would like to be able to set config variables programatically or at least call a reload from a separately specified config file path. Mostly this is due to the application I am working on being encapsulated, needing all of its files to be contained within the shipping directory structure, plus the fact that several clients will be using Windows.

All of this diminishes in comparison with the fact that this is a great simple logging library that will be a drop in replacement for the logging style we had with the perl application I am replacing.

jbrendel commented 7 years ago

Hello imarsman. Thank you for your feedback, I'm glad you like rlog.

If I understand this correctly, the current limitation you run against is that the config file cannot be at the standard "/etc/..." location for you, since (a) the config file needs to be in the shipping directory structure, and (b) some clients will use Windows. You can change the default location of the config file via the RLOG_CONF_FILE environment variable. But I take it you looked into that and found that this not an option for you?

Adding a SetConfFile(<path>) function to rlog would help?

imarsman commented 7 years ago

I believe that SetConfFile(<path>) would work well, yes. From looking at the rlog code I see that it reads in environment variables and attempts to read the config file as soon as the library is first included. Another call that would be useful would be ReadEnvironmentVariables().

jbrendel commented 7 years ago

I have implemented SetConfFile() now. Please pull the latest version and see if this works for you.

imarsman commented 7 years ago

Thank-you very much! I will test it out and let you know how it goes.

imarsman commented 7 years ago

I've tested it out and it does indeed work. In order to be able to dynamically set the log parameters I've had to write the settings to a file then ask rlog to read the config with rlog.SetConfFile(cfgPath). If it would work to allow reading again from environment variables (after they were set in code) that would also be useful. This is not really necessary for me though, as a dynamically produced logging config works.

I imagine that my requests may be beyond the use case you designed this code for. I'd like to stress that I appreciate that you have put this project up for me and others to use. I find it much more straight forward than other Golang logging libraries I've evaluated, which is more in keeping with my requirements.

jbrendel commented 7 years ago

I'm happy rlog is of use to you, and I really appreciate your feedback!

noreabu commented 7 years ago

First, thanks for rlog. I really like it :)

I wrote a handler function for the gin-gonic framework that changes the log level via an HTTP GET call with parameter validation. It requires a config file to be present and writable.

e.g. http://the.service.url/api/logging?level=DEBUG&trace=4

Please let me know if you are interested and i could create a pull request for the examples.

jbrendel commented 7 years ago

Hello!

On Thu, 2017-09-21 at 16:09 +0000, noreabu wrote:

First, thanks for rlog. I really like it :)

Thank you very much! I'm glad you like it.

I wrote a handler function for the gin-gonic framework that changes the log level via an HTTP GET call with parameter validation. It requires a config file to be present and writable.

e.g. http://the.service.url/api/logging?level=DEBUG&trace=4

Please let me know if you are interested and i could create a pull request for the examples.

This sounds really interesting. My concern is, though, that this would increase the footprint of rlog. Currently, rlog has no dependencies on any external packages, besides of what comes standard with Go. I would actually like to keep it that way, if possible.

Maybe if the implementation could be based on "net/http", which comes with Go, instead of Gin?

Juergen

noreabu commented 7 years ago

I understand your concern adding dependencies very well. One of the main reasons i decided for rlog was its lack of external library dependencies.

I think it should also be possible with net/http, but I was thinking more of an "standalone" file in the examples folder, not a change to the code. The entry for gin could be one public function using another one in the background.

jbrendel commented 7 years ago

Well, if it's an example file then by all means, I would love to see the PR!

jbrendel commented 6 years ago

Closed by PR #21