8

I'm just start using logback for logging my Java project running on glassfish3 AS, and I'm noticing some strange thing. This string of code

LOG.error("Вычисление {} уже произведено.", calc);

generates normal expected output if I'm running my application on windows. But if I'm the same configuration on Mac, I'm having question marks instead of words, like so:

15:37:29.083 ERROR r.g.g.c.TotalNachController - ?????????? [id=8871] ??? ???????????.

my logback configuration is:

<appender name="FILE" class="ch.qos.logback.core.FileAppender">
    <file>../logs/logback.log</file>
    <encoder>
        <pattern>%d{HH:mm:ss.SSS} %-5level %logger{35} - %msg%n</pattern>
    </encoder>
</appender>

Could someone please tell me, what I'm doing wrong?

Alex
  • 7,460
  • 2
  • 40
  • 51

2 Answers2

17

Try to define charset for encoder:

<appender name="FILE" class="ch.qos.logback.core.FileAppender">
    <file>../logs/logback.log</file>
    <encoder>
        <charset>utf-8</charset>
        <pattern>%d{HH:mm:ss.SSS} %-5level %logger{35} - %msg%n</pattern>
    </encoder>
</appender>

Sadly it's not described in documentation, but you can always lookup properties in source code. Specyfing <encoder> instantize PatternLayoutEncoder. Going up to its parent LayoutWrappingEncoder you can find method setCharset(). When specified it is used, as you can see in http://logback.qos.ch/xref/ch/qos/logback/core/encoder/LayoutWrappingEncoder.html#120

Kangur
  • 7,823
  • 3
  • 30
  • 32
0

You need to check if the used text editor is supporting your character set. Also the used terminal may affect the displayed characters also.

I suggest using more or less UNIX commands from Terminal application, that should support your charset, to validate if the characters are printed ok.

dan
  • 13,132
  • 3
  • 38
  • 49
  • It's neither textEditor nor Terminal problem, as I can see. My Terminal have no problems viewing this string if it's shown by log4j for example. Same with textEditor, I'm using Sublime Text 2 that supports multiple text encodings, but all of them showing question marks. – Alex Nov 07 '12 at 08:15