Separate logger?

All other questions regarding DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
st80rules
Posts: 190
Joined: Tue, 2007-05-08, 17:45

Separate logger?

#1 Post by st80rules »

Hi,

I have a thread in my app for which I'm trying to create a new output log file, but the output always goes to the same logger as dcmnet.

An excerpt of the code:

Code: Select all

#define HTTP_LOGGER_NAME "ors.http"

static OFLogger HTTPLogger = OFLog::getLogger(HTTP_LOGGER_NAME);

#define HTTP_TRACE(msg) OFLOG_TRACE(HTTPLogger, msg)
#define HTTP_DEBUG(msg) OFLOG_DEBUG(HTTPLogger, msg)
#define HTTP_INFO(msg)  OFLOG_INFO(HTTPLogger, msg)
#define HTTP_WARN(msg)  OFLOG_WARN(HTTPLogger, msg)
#define HTTP_ERROR(msg) OFLOG_ERROR(HTTPLogger, msg)
#define HTTP_FATAL(msg) OFLOG_FATAL(HTTPLogger, msg)

// later

dcmtk::log4cplus::SharedAppenderPtr logFile(new dcmtk::log4cplus::FileAppender((const char*)sOut));  // sOut is a valid filename
dcmtk::log4cplus::Logger::getInstance(HTTP_LOGGER_NAME).addAppender(logFile);

// Later
HTTP_WARN("some text");
I have another thread that uses DCMNET_WARN(), and it gets the text output from HTTP_WARN().

What's wrong with this code?

Thanks

J. Riesmeier
DCMTK Developer
Posts: 2512
Joined: Tue, 2011-05-03, 14:38
Location: Oldenburg, Germany
Contact:

Re: Separate logger?

#2 Post by J. Riesmeier »

Did you already check the HOWTO page? E.g. the section "Redirecting log output to a file" on the following page: http://support.dcmtk.org/wiki/dcmtk/howto/logprogram

st80rules
Posts: 190
Joined: Tue, 2007-05-08, 17:45

Re: Separate logger?

#3 Post by st80rules »

Yes I have checked that HOWTO page (and other pages), but that's not my problem. My problem is that I have 2 threads running, and I want them to log to different files. I think I have code that creates a new logger in the second thread, but all the output goes to both files (in both threads).

One thread uses the DCMNET_XXX macros, and the other thread uses my own macros, yet all the output goes to the DCMNET_XXX output file as well.

Uli Schlachter
DCMTK Developer
Posts: 120
Joined: Thu, 2009-11-26, 08:15

Re: Separate logger?

#4 Post by Uli Schlachter »

Hi,

so if I understand this correctly, you have the following situation:
  • Some code logs to the ors.http logger
  • Some code logs to the dcmtk.dcmnet logger
  • There is a FileAppender attached to the ors.http logger
  • There is another FileAppender attached to the root logger
Since each logger "gives" log messages to its parents, log messages that are sent to the ors.http logger also go to the ors logger and the root logger. This last one will then cause this to be written to the file. (But earlier, the ors.http-logger should have written it to your other log file. So do you get log messages in both files...?)

You can disable this "pass log messages towards the root of the hierachy"-behavior via dcmtk::log4cplus::Logger::getInstance(HTTP_LOGGER_NAME).setAdditivity(false).

Hope this helps,
Uli

st80rules
Posts: 190
Joined: Tue, 2007-05-08, 17:45

Re: Separate logger?

#5 Post by st80rules »

That did the trick, thanks!

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 0 guests