Hello,
I use Logs in a lot of my libraries, each one having one or more log sources. When a tool or another library uses other Logs-using libraries, I'd like to be able to set log level for each log source of these libraries.
There are three options, now:
- I can use
Logs.Src.set_level on each log source of each library,
- or I can set the same log level for every log source, using
Logs.set_level,
- or mix the two ways above.
Setting the same log level is not satisfying, because I may want different log levels on different parts of the software.
Using Logs.Src.set_level on each log source of each library can be done programmatically but if I want to give control to the user, I must use either command line options or environment variables, with an option or an environment variable for each source of each library. This is quite heavy and must be done in each new library or tool using other libraries.
It would be more convenient if, when creating a new log source (with Logs.Src.create), an environment variable name could be provided and, if it is, the default log level for this source would be set according to the value of this environment variable (using Logs.level_of_string).
For example:
let src = Logs.Src.create ~env:"MYPKG_LOG_LEVEL" "mypkg"
would create a new source initialized to the value of environment variable MYPKG_LOG_LEVEL if it is set and has a correct value (i.e. a string corresponding to a log level). If no environment variable name is provided or the value of this variable is incorrect (i.e. it does not correspond to a log level), then the initial log level for the created source would be set as it is now. So this change would not break backward-compatibility.
Regarding the environment variable name, the "_LOG_LEVEL" part could be added automatically to provide consistency between packages. So
let src = Logs.Src.create ~env:"MYPKG" "mypkg"
would honor the MYPKG_LOG_LEVEL environment variable.
I can make a PR if you agree with this improvment.
Hello,
I use
Logsin a lot of my libraries, each one having one or more log sources. When a tool or another library uses otherLogs-using libraries, I'd like to be able to set log level for each log source of these libraries.There are three options, now:
Logs.Src.set_levelon each log source of each library,Logs.set_level,Setting the same log level is not satisfying, because I may want different log levels on different parts of the software.
Using
Logs.Src.set_levelon each log source of each library can be done programmatically but if I want to give control to the user, I must use either command line options or environment variables, with an option or an environment variable for each source of each library. This is quite heavy and must be done in each new library or tool using other libraries.It would be more convenient if, when creating a new log source (with
Logs.Src.create), an environment variable name could be provided and, if it is, the default log level for this source would be set according to the value of this environment variable (usingLogs.level_of_string).For example:
would create a new source initialized to the value of environment variable
MYPKG_LOG_LEVELif it is set and has a correct value (i.e. a string corresponding to a log level). If no environment variable name is provided or the value of this variable is incorrect (i.e. it does not correspond to a log level), then the initial log level for the created source would be set as it is now. So this change would not break backward-compatibility.Regarding the environment variable name, the "_LOG_LEVEL" part could be added automatically to provide consistency between packages. So
would honor the
MYPKG_LOG_LEVELenvironment variable.I can make a PR if you agree with this improvment.