[완료] log4cxx에서 UTF-8 한글 문제

emptynote의 이미지

log4cxx를 받아서 테스를 하는 과정에서 한글 출력이 안되네요.

우분투 설치시 UTF-8로 설치를 하고 잘사용하고 있습니다.
참고 ) echo $LANG => ko_KR.utf8

그런데 log4cxx를 받아서 컴파일 하면 한글이 ? 로 표시됩니다.

구글신께 "loc4cxx 한글" 로 찾아 보니

소스 build할때 문자셋을 결정하는 헤더파일을 수정하던지 아니면,
소스 build할때 $ ./configure --with-charset=iso-8859-1 요렇게 하라는 글이있네요.

참고1) http://empty79.egloos.com/12877

제가 원하는 방법은 apt-get install로 받은거는 수정하지 않고,

제가 작성하는 소스상에서 문자셋을 수정하는 것을 원합니다.

참고) log4cxx.h 파일을 보면 #define LOG4CXX_LOGCHAR_IS_UTF8 1
이렇게 되어 있는데도 불구하고 UTF-8상태에서 입력한 한글은 ??? 로 표시되네요.

emptynote의 이미지

소스상에서 한문장을 추가하면 되네요.

추가할 문장 ==> setlocale(LC_ALL,"");

http://logging.apache.org/log4cxx/faq.html 에서 보면
------ 인용 -----------
Does Apache log4cxx support Unicode?

Yes. Apache log4cxx exposes API methods in multiple string flavors const char*, std::string, wchar_t*, std::wstring, CFStringRef et al. const char* and std::string are interpreted according to the current locale settings. Applications should call setlocale(LC_ALL, "") on startup or the C RTL will assume US-ASCII. Before being processed internally, all these are converted to the LogString type which is one of several supported Unicode representations selected by the --with-logchar option. When using methods that take LogString arguments, the LOG4CXX_STR() macro can be used to convert ASCII literals to the current LogString type. FileAppenders support an encoding property which should be explicitly specified to "UTF-8" or "UTF-16" for XML files.
----------------------------------

"Applications should call setlocale(LC_ALL, "") on startup" 라고 설명을 하고 있네요.
진정 제가 원하는 방향인지는 좀더 작업?을 진행해 봐야겠지만 기쁘네요.
2틀정도 날렸네요 이거 찾는라고 ㅠ.ㅠ
영어가 딸린것이 아니라 집중력이 딸리는듯합니다.

jnheon의 이미지

덕분에 저는 이틀을 절약할 수 있었습니다 :)

복 받으실 거예요

PS. 혹시 같은 문제를 맞닥뜨리게 될 분들을 위해 내용 추가합니다
윈도우에서 멀티바이트 사용 버전으로 개발 중인데 멀티바이트 한글은 뒷부분이 중복해서 나오는 이슈가 생겼습니다
"안녕하세요?" -> "안녕하세요?세요???"

해결은 log4cxx 소스 중에 charsetdecoder.cpp 파일을 수정했습니다

MbstowcsCharsetDecoder::decode 에서

size_t converted = mbsrtowcs(buf,
&src,
requested,
&mbstate);
if (converted == (size_t) -1) {
stat = APR_BADARG;
in.position(src - in.data());
break;
} else {
stat = append(out, buf);
in.position(in.position() + converted);
}

이 부분에서 converted 와 실제 디코딩된 소스 문자열의 길이가 다른점이 문제가 되고 있어서
in.position(in.position() + converted); -> in.position(in.position() + requested);
로 수정했습니다
converted != -1 이라면 변환성공이니 requested를 사용해도 될 듯 합니다

https://issues.apache.org/jira/browse/LOGCXX-399

:) :( :p

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.