I am using the Boost 1.63.0 Log library in an application. To initialize the various log files I am making use of the boost::log::init_from_stream(...)
method to configure the sinks from a configuration INI file.
I originally had an issue with the file rotation behavior of the boost log. The file was being created in the current working directory and then moved to the "Target" directory on the file rotation trigger or application close. The desired behavior was for the file to be created directly in the "Target" directory. I corrected this with help from this post: boost::log add_file_log not writing if app exits with CTRL_CLOSE_EVENT
In short, it says to provide the "FileName" keyword with the full path information not just the name. This works but I was wondering if there is a nice way to "clean up" the configuration file.
For example, the INI file currently requires you to specify both the "Target" and "FileName" keywords as such:
Target="C:\\ProgramData\\MyApplication\\Logs"
FileName="C:\\ProgramData\\MyApplication\\Logs\\AppLog_%N.log"
It would be really nice to be able to only specify the "Target" directory and then use that variable in the "FileName" variable definition. This would make any future changes much simpler by only having to change one thing. Something like:
#Define Target Directory for file rotation
Target="C:\\ProgramData\\MyApplication\\Logs"
#Define File Name pattern
FileName="%Target%\\AppLog_%N.log"
--- OR ---
FileName="$(Target)\\AppLog_%N.log"
Is this possible to do?
Boost.Log does not perform variable expansion, you will have to do this yourself. You can load the settings file into settings
by calling parse_settings
. Then you can operate on that container and expand the variables. When you're done, you can use it to initialize the logging library by calling init_from_settings
.