Hi Wea, Our product has code to dynamically add a console appender, but it is not currently in use. As such, I can't say for sure whether it works or not.
=========== static const LogString DateTimeThreadLevelClassMessagePattern (LOG4CXX_STR("%d{dd/MM HH:mm:ss.SSS} %-5p %c - %m%n")); LogString lsPattern = DateTimeThreadLevelClassMessagePattern; if (!overridePattern.IsEmpty()) { lsPattern = GetLogString(overridePattern); } LoggerPtr root = Logger::getRootLogger(); LayoutPtr layout(new PatternLayout(lsPattern)); AppenderPtr appender(new ConsoleAppender(layout)); root->addAppender(appender); ========== Code to remove a named appender is also untested and I don't know off-hand if this works for "stdout". GetLogString is our function which takes our own String class and creates a LogString ===== LogString strAppenderName = GetLogString(appenderName); LoggerPtr root = Logger::getRootLogger(); root->removeAppender(strAppenderName); return true; ===== Hope this helps, Andy On Thu, May 9, 2013 at 11:03 AM, Wesley J. Miller <wmil...@sdr.com> wrote: > > How would I dynamically turn log4cxx logging to the console on and off in an > application? > > Goal here is to process a used choice, command line parm or GUI input or > whatever. Thus in a hypothetical main loop: > > if ( userWantsToStartConsoleLogger ) > ConsoleLogger( true ); > if ( userWantsToStopConsoleLogger ) > ConsoleLogger( false ); > > My logging setup is: > > #include <log4cxx/logger.h> > #include <log4cxx/propertyconfigurator.h> > #include <log4cxx/helpers/exception.h> > > int main( int argc, char** argv ) > { > const log4cxx::LoggerPtr logger; > log4cxx::PropertyConfigurator::configure("./logs.config"); > } > > where ./logs.config looks like: > > log4j.rootLogger=INFO, File > > log4j.appender.stdout=org.apache.log4j.ConsoleAppender > log4j.appender.stdout.layout=org.apache.log4j.PatternLayout > log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n > > log4j.appender.File=org.apache.log4j.RollingFileAppender > log4j.appender.File.File=logs/system.logs > log4j.appender.File.MaxFileSize=1MB > log4j.appender.File.MaxBackupIndex=10 > log4j.appender.File.layout=org.apache.log4j.PatternLayout > log4j.appender.File.layout.ConversionPattern=%d{MM/dd/yyyy HH:mm:ss:SSS a} > %p %c %m%n > > > NOTE: Presently, I have to add , stdout after FILE in the rootlogger= line to > accomplish this. > > In this context, of course, the question is, what goes in my ConsoleLogger() > function? > > Thanks, > > Wea