c++logginglog4cpp

Configuring log4cpp Logging level Priority


In an application we are using log4cpp-0.3.5rc3 for logging. The application is installed on linux devices. There is a bug in application and I want to set the log level of application to debug but I don't find anyway to do it on the remote device. In the application configuration I couldn't find anything about log level just this line:

log4cpp_include_dir_default=${system_lib_dir}/log4cpp/log4cpp-0.3.5rc3/include
log4cpp_include_dir=${log4cpp_include_dir_default}

AC_ARG_ENABLE(debug, AC_HELP_STRING([--enable-debug], [have GCC compile with symbols (default = no)]), enable_debug=$enableval, enable_debug=no)

Is it so that I have to build application with debug configuration and install a new build for setting Log level to debug? I wonder if log4cpp has any configuration file for logging like log4j in Java where we can easily change the log level.


Solution

  • Sure, log4cpp uses a log4cpp.properties file to configure the logger.

    The path to this file will be passed to log4pp::PropertyConfigurator::configure(<path_to_file>)

    when you configure your logger (usually at application startup); therefore, it could be stored anywhere in your filesystem, so you'll need to see what path is passed in to find the file.

    A simple example properties file:

    log4cpp.rootCategor=DEBUG, A1 log4cpp.main=INFO, A1

    # A1 is to the console

    log4cpp.appender.A1=org.apache.log4j.ConsoleAppender log4cpp.appender.A1.layout=PatternLayout log4cpp.appender.A1.ImmediateFlush=true log4cpp.appender.A1.layout.ConversionPattern=Console %d [%t] %-5p %c - %m%n