Fix Version/s: None
Team:Data Access and Database
DM-1005 I found that initialization of log package causes me a lot of trouble. I hope we can improve that.
Currently log can be initialized in one of the following ways:
- calling LOG_CONFIG(file_name) where file name has to be passed somehow to the initialization code, configures loggers according to given config file
- calling LOG_CONFIG() defines some basic configuration which kind of works but isn't usually what I want
- not calling any of the above but setting environment variable LOG4CXX_CONFIGURATION to a config file name, which is equivalent to first option (this may not be intended use case but it works now)
- if I don't do any of the above then log4cxx prints error messages and disables logging completely
Our use cases for log may be non-conventional but I have to implement them anyways. There are basically two cases where I have troubles:
- plugins for xrootd (implemented as libraries), these do not have a simple way to pass configuration file name except through environment variable, I could use LOG4CXX_CONFIGURATION for that (without calling LOG_CONFIG() but I also want to produce reasonable output when I forget to set LOG4CXX_CONFIGURATION. Another complication is that there may be more than one plugin loaded at the same time, deciding which one has to initialize logging is complicated.
- a (potentially large) number of unit tests. We could add LOG_CONFIG() to each one of them but I'd like to avoid that for a number of reasons.
So I think what I'd like to have is an option to not call LOG_CONFIG() which would still produce reasonable output even without LOG4CXX_CONFIGURATION (in other words make call to LOG_CONFIG() implicit). But I would also like to be able to change logger configuration via LOG4CXX_CONFIGURATION when LOG_CONFIG() is called (explicitly or implicitly).
I propose to modify log to do following:
- any call to logger methods implicitly initializes it (via call to LOG_CONFIG()) if it has not been initialized.
- if LOG_CONFIG() is called without file name and LOG4CXX_CONFIGURATION is set then it should be equivalent to LOG_CONFIG(getenv("LOG4CXX_CONFIGURATION"))