I use Boost.Log in C++ to log, and use configuration files. I added some custom attributes and use them in the configuration file. Here is the registration of the attributes in C++:
namespace logging = boost::log;
namespace attrs = boost::log::attributes;
namespace src = boost::log::sources;
namespace sinks = boost::log::sinks;
namespace expr = boost::log::expressions;
namespace keywords = boost::log::keywords;
attr1 myProcessID("");
attr2 myThreadID("");
attr3 myThreadIndex("")
attr4 theCorrelationId("");
attr5 theMiscInfos("");
slg_mt::get().add_attribute("Process_ID", myProcessID);
slg_mt::get().add_attribute("Thread_ID", myThreadID);
slg_mt::get().add_attribute("Thread_Index", myThreadIndex);
slg_mt::get().add_attribute("Correlation_ID", theCorrelationId);
slg_mt::get().add_attribute("MiscInfos", theMiscInfos);
I define a configuration file, and initialize the configuration file the normal way using boost::log::init_from_stream
.
If I use the following configuration, it works well :
[Sinks.TRACE]
Destination="TextFile"
Asynchronous="true"
AutoFlush="true"
Format="[TimeStamp %TimeStamp(format=\"%Y-%m-%d %H:%M:%S.%f\")%][UpTime
%Uptime(format=\"%O:%M:%S.%f\")%][ProcessID: %Process_ID%][ThreadID: %Thread_ID% %Thread_Index%] %Message%"
Target="C:\BoostLogTrace"
FileName="C:\BoostLogTrace\REST_%N.log"
RotationSize="10485760"
ScanForFiles="Matching"
Filter="%Severity% = trace"
Everything works well. Except that I would like to use my custom-defined attributes not only in the log entries, but also in the log target and filename.
When I try with the following FileName, it does not work:
FileName="C:\BoostLogTrace\REST_%THREAD_ID%.log"
Is there a way to change the target and filename using custom attributes, with attributes values changing from one log entry to another?
From a higher perspective, I need to log each individual user session in a different log file. How can I do this with Boost.log ?
Thanks!