#235 Setting up logger from Properties fails (?)

v1.1.3
closed
None
5
2016-03-26
2010-09-10
No

Hi all,

I was investigating what troubles I would get myself in to when upgrading from log4cplus 1.0.2 to 1.0.3 or later. One thing that baffled me is the change in behavior of defining a logger using Properties. The code below shows the initialization code that I use to make sure that there's always a trace logger TRC available when running a program. This code snippet is part of an initialization function that is called right after main() has started.

The weird thing is that, with log4cplus 1.0.2, I get the output I expect, however whit 1.0.3 or later I get the error that no appender could be found for logger TRC. In both cases, the initialization function is executed, because I see the line "TRACE module activated".

Any ideas what might cause the difference?

void initTraceModule (void)
{
// Register our own loglevels
getLogLevelManager().pushToStringMethod(traceLevel2String);
getLogLevelManager().pushFromStringMethod(string2TraceLevel);

// Setup a property object to initialise the TRACE Logger
helpers::Properties  prop;
prop.setProperty("log4cplus.logger.TRC", "DEBUG, STDERR");
prop.setProperty("log4cplus.additivity.TRC", "false");
prop.setProperty("log4cplus.appender.STDERR", "log4cplus::ConsoleAppender");
prop.setProperty("log4cplus.appender.STDERR.logToStdErr", "true");
prop.setProperty("log4cplus.appender.STDERR.ImmediateFlush", "true");
prop.setProperty("log4cplus.appender.STDERR.layout", "log4cplus::PatternLayout");
prop.setProperty("log4cplus.appender.STDERR.layout.ConversionPattern", "%D{%y%m%d %H%M%S,%q} [%i] %-6p %c{3} [%F:%L] - %m%n");
PropertyConfigurator(prop).configure();
Logger::getInstance("TRC").forcedLog(0, "TRACE module activated");
}

Discussion

  • Václav Haisman

    Václav Haisman - 2010-09-10
    • assigned_to: nobody --> wilx
     
  • Václav Haisman

    Václav Haisman - 2010-09-13

    I am getting "100913 184407,248 [3292] TRACE TRC [:] - TRACE module activated" when I put all of the code you have provided (with custom traceLevel2String() and string2TraceLevel()) when the code reaches the last line, with head of PRODUCTION_1_0_x branch. Please try the latest 1.0.4 RC with your test case if you are using 1.0.3 release. If you are still seeing the same problems then please try to produce more complete testcase.

     
  • Václav Haisman

    Václav Haisman - 2010-09-13
    • milestone: --> 954441
    • status: open --> pending
     
  • Marcel Loose

    Marcel Loose - 2010-09-14

    I figured out that the problem is a little more complicated than I described earlier.

    I use the code above to initialize the tracer. As you can see, it is initialized at DEBUG level.
    With log4cplus 1.0.2 I can override the setting for logger.TRC in a property file, which is loaded after initTraceModule() was called. The loglevel for TRC is then modified appropriately. With log4cplus 1.0.3 and higher this fails. So, it's not so much that initializing the TRC logger doesn't work across versions of log4cplus; changing the loglevel of a previously initialized logger using a property file seems to fail.

    I've reduced this problem to a hopefully manageable size. I've put together relevant snippets of code into one source file. I'll upload it, together with a properties file that modifies the settings of TRC. It should be possible to reproduce the problem.

     
  • Marcel Loose

    Marcel Loose - 2010-09-14
    • status: pending --> open
     
  • Marcel Loose

    Marcel Loose - 2010-09-14

    Seems I cannot upload a file? Am I missing something, or is that option disabled?

     
  • Václav Haisman

    Václav Haisman - 2010-09-14

    It should be possible to upload the file. Have you clicked on the "Add a file" text in the "Attached File" section below?

     
  • Marcel Loose

    Marcel Loose - 2010-09-14

    Demo program showing the trace problem

     
  • Marcel Loose

    Marcel Loose - 2010-09-24

    We're you able to reproduce the problem with the code I uploaded?

     
  • Václav Haisman

    Václav Haisman - 2010-09-24

    I think this is related to fix of bug [bugs:#28]. His and your use are conflicting. There is probably some middle way that could satisfy both but I will have to think about. I will probably end up adding some sort of flags that would allow you to select different behaviour.

     

    Related

    Bugs: #28


    Last edit: Václav Haisman 2013-03-17
  • Marcel Loose

    Marcel Loose - 2010-09-25

    Hmm, it's probably my lack of understanding how loggers and appenders exactly relate to one another. I had the impression that each logger keeps a map of appenders. If that's indeed the case, I don't understand why you'd have to remove all appenders during (re)configuration (your fix in commit 660). Each appender can be uniquely identified by its name. If a certain appender is already in the map of appenders for a given logger, then it cannot be added again; if not, it can and will be added to the map.

     
  • Václav Haisman

    Václav Haisman - 2012-05-10

    The fix for #852513 was done similarly to how log4j does things, IIRC. I will try to review the approach to use per-logger appenders set.

     
  • Václav Haisman

    Václav Haisman - 2012-05-10
    • milestone: 954441 --> v1.1.0
     
  • Václav Haisman

    Václav Haisman - 2013-03-17
    • Description has changed:

    Diff:

    --- old
    +++ new
    @@ -6,23 +6,23 @@
    
     Any ideas what might cause the difference?
    
    -<code>
    -void initTraceModule \(void\)
    -\{
    +~~~~
    +void initTraceModule (void)
    +{
     // Register our own loglevels
    -getLogLevelManager\(\).pushToStringMethod\(traceLevel2String\);
    -getLogLevelManager\(\).pushFromStringMethod\(string2TraceLevel\);
    +getLogLevelManager().pushToStringMethod(traceLevel2String);
    +getLogLevelManager().pushFromStringMethod(string2TraceLevel);
    
     // Setup a property object to initialise the TRACE Logger
     helpers::Properties  prop;
    -prop.setProperty\("log4cplus.logger.TRC", "DEBUG, STDERR"\);
    -prop.setProperty\("log4cplus.additivity.TRC", "false"\);
    -prop.setProperty\("log4cplus.appender.STDERR", "log4cplus::ConsoleAppender"\);
    -prop.setProperty\("log4cplus.appender.STDERR.logToStdErr", "true"\);
    -prop.setProperty\("log4cplus.appender.STDERR.ImmediateFlush", "true"\);
    -prop.setProperty\("log4cplus.appender.STDERR.layout", "log4cplus::PatternLayout"\);
    -prop.setProperty\("log4cplus.appender.STDERR.layout.ConversionPattern", "%D\{%y%m%d %H%M%S,%q\} \[%i\] %-6p %c\{3\} \[%F:%L\] - %m%n"\);
    -PropertyConfigurator\(prop\).configure\(\);
    -Logger::getInstance\("TRC"\).forcedLog\(0, "TRACE module activated"\);
    -\}
    -</code>
    +prop.setProperty("log4cplus.logger.TRC", "DEBUG, STDERR");
    +prop.setProperty("log4cplus.additivity.TRC", "false");
    +prop.setProperty("log4cplus.appender.STDERR", "log4cplus::ConsoleAppender");
    +prop.setProperty("log4cplus.appender.STDERR.logToStdErr", "true");
    +prop.setProperty("log4cplus.appender.STDERR.ImmediateFlush", "true");
    +prop.setProperty("log4cplus.appender.STDERR.layout", "log4cplus::PatternLayout");
    +prop.setProperty("log4cplus.appender.STDERR.layout.ConversionPattern", "%D{%y%m%d %H%M%S,%q} [%i] %-6p %c{3} [%F:%L] - %m%n");
    +PropertyConfigurator(prop).configure();
    +Logger::getInstance("TRC").forcedLog(0, "TRACE module activated");
    +}
    +~~~~
    
     
  • Václav Haisman

    Václav Haisman - 2013-07-14

    Ticket moved from /p/log4cplus/support-requests/22/

     
  • Václav Haisman

    Václav Haisman - 2016-03-26
    • status: open --> closed
    • Group: v1.1.0 --> v1.1.3
     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks