logging-log4cxx-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ken <yongk...@gmail.com>
Subject How to write Asian character to file?
Date Tue, 28 Feb 2006 06:29:36 GMT
Hi,
  Forgive me if it's bothersome........
  Following is my test source code, I use setEncoding() method to set the
encoding,
  but the Asian character in log still can not output correctly, I only can
get
  question mark in file, I tried US-ASCII, ISO-8859-1, UTF-8, UTF-16BE,
UTF-16LE,
  UTF-16 with setEncoding() call, but all same......
  Anyone can tell me the right way to get the Asian character show in log
file?
  I got the SVN source code on Feb. 19, build the static lib by:
  ant -Ddebug=false -Dlib.type=static build


int main()
{
    PatternLayoutPtr layout = new PatternLayout("%d{ISO8601} [%t] %l %p -
%m%n");
    RollingFileAppenderPtr rfa = new RollingFileAppender();
    rfa->setName("sizeROLLING");
    rfa->setLayout(layout);
    rfa->setFile("tsizeBased-test.log");

    SizeBasedTriggeringPolicyPtr sbtp = new SizeBasedTriggeringPolicy();
    sbtp->setMaxFileSize(1024 * 1024 * 10);

    FixedWindowRollingPolicyPtr swrp = new FixedWindowRollingPolicy();
    swrp->setMaxIndex(10);
    swrp->setMinIndex(1);
    swrp->setFileNamePattern("tsizeBased-test.log.%i");

    rfa->setRollingPolicy(swrp);
    rfa->setTriggeringPolicy(sbtp);
    rfa->setEncoding("UTF-16");
    //cout << __LINE__ << ": " << rfa->getEncoding() << endl;

 Pool p;
 rfa->activateOptions(p);

 LoggerPtr sizeroll = Logger::getLogger("sizeLogger");
 sizeroll -> setLevel(Level::DEBUG);
    sizeroll -> addAppender(rfa);

 logstream lc_logstream(sizeroll, Level::DEBUG);
 // lc_logstream << L"koko你好test12+" << LOG4CXX_ENDMSG;
 lc_logstream << LOG4CXX_STR("koko你好test34-") << LOG4CXX_ENDMSG;
 lc_logstream << LogString("koko你好test56*") << LOG4CXX_ENDMSG;
 LOG4CXX_DEBUG(sizeroll, "koko你好test78/");
 LOG4CXX_DEBUG(sizeroll, LOG4CXX_STR("koko你好test78/"));
 LOG4CXX_DEBUG(sizeroll, LogString("koko你好test78/"));

 exit(1);
}

  Thanks in advance...



--
Ken
Mime
View raw message