« Return to Thread: LogString conversion

Re: LogString conversion

by Madhu Gowda :: Rate this Message:

| View in Thread

Hi,

I tried the following in my sample program.
std::string sLogFile = "TestLog.txt";
LogString sFileName;
log4cxx::helpers::Transcoder::decode( sLogFile, sFileName);

But, it gives the sFileName as "".

I tried to debug and saw that in the function
void Transcoder::decode(const std::string& src, LogString& dst) {

the value of src is coming as <Bad Ptr>

Kindly advise on this.

Regards,
Madhu Gowda

--- On Fri, 5/9/08, Curt Arnold <carnold@...> wrote:
From: Curt Arnold <carnold@...>
Subject: Re: LogString conversion
To: "Log4CXX User" <log4cxx-user@...>
Date: Friday, May 9, 2008, 2:25 PM

On May 9, 2008, at 7:46 AM, Mehta,
 Jenica wrote:

> Hi All,
>
> Please let me know if log4cxx 0.10.0 provides any API for converting
> std::string to log4cxx::LogString and vice versa.
>
> Thanks & Regards,
>
> Jenica Mehta
>
>

LogString is the internal string representation within log4cxx which
is either an std::basic_string<char> where the characters are UTF-8
codes (default build on non-Windows platforms) or
std::basic_string<wchar_t> (default on Windows). Most of the commonly
used methods are written accept many flavors of strings (std::string
in current code page, wstrings, CFString, etc), but less frequently
used methods require that the user explicitly between their desired
string type and LogString.

The simplest way to convert, is the use the LOGCXX_ENCODE_CHAR and
LOG4CXX_DECODE_CHAR macros defined in log4cxx/helpers/transcoder.h.
ENCODE creates a std::string from a LogString and DECODE creates a
LogString from a char. If log4cxx is build with --with-charset=utf-8
and --with-logchar=utf-8, the macros will simply be a reference
definition since there is no need for conversion. Here is an example
(don't actually run it for obvious reasons):

void bar(LogString& param) {
LOG4CXX_ENCODE_CHAR(string, param);
foo(string);
}

void foo(std::string& param) {
LOG4CXX_DECODE_CHAR(logstring, param);
bar(logstring);
}


Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now.

Bad_Ptr.JPG (291K) Download Attachment

 « Return to Thread: LogString conversion