Re: [Log4cplus-devel] use configuration file for rolling appender, but set filename inside applicat
Logging Framework for C++
Brought to you by:
wilx
From: Václav Z. <vha...@gm...> - 2012-06-18 08:14:44
|
On 18 June 2012 09:09, Václav Zeman wrote: > On 18 June 2012 07:23, Václav Zeman wrote: >> On 06/18/2012 07:03 AM, Ulrich Heinicke wrote: >>> Hi, >>> i want to use a configuration file like this: >>> >>> # switch on general logging (reports ALL levels to ROLLFILE and OUTPUT) >>> log4cplus.rootLogger=ALL, ROLLFILE, OUTPUT >>> >>> # switch on release-logging (reports only warnings and errors levels to >>> ROLLFILE) >>> #log4cplus.rootLogger=WARN, ROLLFILE >>> >>> # switch off general logging >>> #log4cplus.rootLogger=OFF >>> >>> # explicitely enable loggers (even if general logging is off) >>> #log4cplus.logger.IBHStatik=ALL, ROLLFILE >>> #log4cplus.logger.IBHCore=ALL, ROLLFILE >>> >>> # setup the ROLLFILE >>> log4cplus.appender.ROLLFILE=log4cplus::RollingFileAppender >>> log4cplus.appender.ROLLFILE.MaxFileSize=1000KB >>> log4cplus.appender.ROLLFILE.MaxBackupIndex=50 >>> log4cplus.appender.ROLLFILE.layout=log4cplus::PatternLayout >>> log4cplus.appender.ROLLFILE.layout.ConversionPattern=%d %-5p (%F:%L) - %m%n >>> >>> but the filename for the RollingFileAppender i will set in my application. >>> >>> How can i do this? >> This is not supported directly but it is doable. You can load the >> properties file first: >> >> log4cplus::helpers::Properties props (LOG4CPLUS_TEXT ("foo.properties")); >> >> Then you can modify the properties set and add additional property with >> the file name: >> >> props.setProperty (LOG4CPLUS_TEXT ("log4cplus.appender.ROLLFILE.File"), file_path_string_here); >> >> After this you can do the configuration process as usual but with the props variable as argument to the PropertyConfigurator ctor: >> >> log4cplus::PropertyConfigurator conf (props); >> >> Depending on you application, you might want to use or not use the fShadowEnvironment flag to the PropertyConfigurator to give higher priority to the property rather than to environment variables. By default, environment variables override properties. > Actually, this is not relevant to the above solution. I had this in > mind when I thought about a slightly different solution. In this > different solution you would add a line like this to the properties > file: > > log4cplus.appender.ROLLFILE.File=${FILENAME} > > Then you would set the property's value in your code. > > props.setPropery (LOG4CPLUS_TEXT ("FILENAME"), file_path_string_here); > > Depending on the fShadowEnvironment flag absence or presence, it could > be or could not be overridden using same name environment variable. > >> >> I have not tested this but I think it should work this way. HTH. I am resending the answer to the list. -- VZ |