Does OFLog provide different character sets?

All other questions regarding DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
Misi
Posts: 12
Joined: Wed, 2012-11-07, 09:31

Does OFLog provide different character sets?

#1 Post by Misi »

Hi,

a simple question: Is OFLog capable to produce logs in other languages/charctersets than Latin1?
For example I'd like to append a message like:

OFLogger my_log = OFLog::getLogger("dcmtk.apps.sample");
OFLOG_ERROR(my_log, "Can't identify patient with name Микки Маус"); // <- russian patient name

But the output in the log file looks like this:
"121106:185723062 ERROR Can't identify patient with name 038A7058"

So for me it seems like OFLog does not provide this capability. Or did I make something wrong in my project? Of course it is a Unicode-project.

Thanks in advance,
Michael

Misi
Posts: 12
Joined: Wed, 2012-11-07, 09:31

Re: Does OFLog provide different character sets?

#2 Post by Misi »

Doesn't anybody have an advice?

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

Re: Does OFLog provide different character sets?

#3 Post by J. Riesmeier »

Currently, OFLog does not do any character set conversions, i.e. the output is just a byte stream of what has been added to the logger. On Unix systems, using UTF-8 would be a good idea. On Windows system compiling with UNICODE defined does not help since DCMTK will not compile any more. From the INSTALL file of the current snapshot:

Code: Select all

5. DCMTK does not compile when UNICODE or _UNICODE is defined because the
   VisualStudio compiler then uses the Unicode version instead of the ANSI
   version for all Windows API functions (i.e. type wchar_t instead of char
   for all character string parameters and return values).
So, in your case: Make sure that the file viewer/editor, which is used to open the log file, has support the required character set (and that this encoding is enabled).

Misi
Posts: 12
Joined: Wed, 2012-11-07, 09:31

Re: Does OFLog provide different character sets?

#4 Post by Misi »

Thank you for the explanation. I tried "Notepad++" to convert the generated log file to Utf-8. Unfortunately, without success. Have you ever successfully viewed a log file with unicode characters inside & generated by OFLog? Can you recommend another editor/viewer which is able to do that?
I just want to make sure that this is really possible...

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

Re: Does OFLog provide different character sets?

#5 Post by J. Riesmeier »

What kind of character set are you using in your program? I have successfully used UTF-8 encoding for the log output and could open such file e.g. with UltraEdit on Windows.

Misi
Posts: 12
Joined: Wed, 2012-11-07, 09:31

Re: Does OFLog provide different character sets?

#6 Post by Misi »

In a nutshell, I use:
- Visual Studio 2010
- QT4
- DCMTK 3.6.0

My program:
- Character Set is MBCS (multi byte character set)
- I also tried Unicode without success
- DCMTK is also MBCS-compiled
- "Treat WChar_t As Built in Type" option of visual studio is disabled (required for using QT unicode conversion in Visual Studio)

This is my code:

Code: Select all

class StringAppender : public log4cplus::FileAppender 
{
public:
    log4cplus::tofstream    & out;
    StringAppender(const log4cplus::tstring &name) : log4cplus::FileAppender (name), out(log4cplus::FileAppender::out){}
    virtual void append (const log4cplus::spi::InternalLoggingEvent &event)
    {
        log4cplus::FileAppender::append(event);
    }
    std::string retrieve_last_message(){/*to implement*/}
    virtual void close (){}
    virtual     ~StringAppender () {}
};


...
const log4cplus::tstring filename = "test.log";
log4cplus::SharedAppenderPtr append_1(new StringAppender(filename));
log4cplus::Logger log = log4cplus::Logger::getRoot();
log.addAppender(append_1);
OFLOG_WARN(log, L"Микки Маус"); //<- russian
...

And finally, this is the output of the log file:
WARN - 011A4548

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

Re: Does OFLog provide different character sets?

#7 Post by J. Riesmeier »

I would recommend that you convert your strings to UTF-8 encoding (either using Qt or the OFCharacterEncoding class of the DCMTK snapshot) prior to outputting them to the logger. The latest DCMTK snapshot also supports converting Microsoft's wchar_t* (i.e. UTF-16) to char* (e.g. UTF-8) directly.

Misi
Posts: 12
Joined: Wed, 2012-11-07, 09:31

Re: Does OFLog provide different character sets?

#8 Post by Misi »

After several frustrating hours of unsuccessfull trying & testing of different configurations as well as all kinds of character transformations possible by DCMTK & QT, I decided to abandon OFLog. Instead I use Log4Qt now, whose character encoding can be set individually and which also bases on Log4j:

http://log4qt.sourceforge.net/


Thanks,
MiSi

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 1 guest