log4c - how can I ONLY see INFO messages?

1.6k views Asked by At

I am using the latest version of LOG4C and am a little confused why I cannot control the INFO, WARN, DEBUG statements coming out to the screen? I have used LOG4J and it seemed to be easy to control whether DEBUG, INFO , WARN messages came out.

Here is my test code:

#include <stdio.h>
#include <stdlib.h>
#include "log4c.h"

int main(){
  int rc = 0;
  log4c_category_t* mycat = NULL;

  if (log4c_init()){
    printf("log4c_init() failed");
    rc = 1;
  }else{
      mycat = log4c_category_get("test.program");          
      log4c_category_log(mycat, LOG4C_PRIORITY_ERROR, "Some ERROR message...!");
      log4c_category_log(mycat, LOG4C_PRIORITY_INFO, "Some INFO message...!");
      log4c_category_log(mycat, LOG4C_PRIORITY_WARN, "Some WARN message...!");
      log4c_category_log(mycat, LOG4C_PRIORITY_ALERT, "Some ALERT message...!");
      log4c_category_log(mycat, LOG4C_PRIORITY_CRIT, "Some CRITICAL message...!");
      log4c_category_log(mycat, LOG4C_PRIORITY_FATAL, "Some FATAL message...!");
      log4c_category_log(mycat, LOG4C_PRIORITY_NOTICE, "Some NOTICE message...!");

    if ( log4c_fini()){
      printf("log4c_fini() failed");
    }
  }
  return 0;
}

And here is the "log4rc" file in the same folder as the running app..

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE log4c SYSTEM "">

<log4c version="1.2.1">

    <config>
        <bufsize>0</bufsize>
        <debug level="INFO3"/>
        <nocleanup>0</nocleanup>
        <reread>1</reread>
    </config>       
     <category name="test.program" priority="info" appender="stdout"/> 
</log4c>

So you can see above I set it to "info", but then why when I run the program do I still see everything on the screen?

lynton@lynton-Latitude-E5400 ~/Desktop/log4c/LogTest/LogTest $ ./LogTest 
[stdout] ERROR    test.program - Some ERROR message...!
[stdout] INFO     test.program - Some INFO message...!
[stdout] WARN     test.program - Some WARN message...!
[stdout] ALERT    test.program - Some ALERT message...!
[stdout] CRIT     test.program - Some CRITICAL message...!
[stdout] FATAL    test.program - Some FATAL message...!
[stdout] NOTICE   test.program - Some NOTICE message...!
lynton@lynton-Latitude-E5400 ~/Desktop/log4c/LogTest/LogTest $ 

Am I doing something wrong here?

Any help or advise would be greatly appreciated ;-)

Lynton

1

There are 1 answers

0
paxdiablo On

Putting this in as an answer since, if original asker hasn't done this in the last nine months, they probably aren't intending to.

This behaviour is identical to log4j. The debug level configured is the minimum level of messages that will be enabled for output. In other words, if you select error, you'll get error AND fatal messages.

From the log4j online manual:

Basic Selection Rule: A log request of level P in a logger with (either assigned or inherited, whichever is appropriate) level Q, is enabled if P is greater than or equal to Q.