Logback on mac returns question marks instead of words

I'm just starting to use logback to register my Java project running on glassfish3 AS, and I notice some strange thing. This line of code

LOG.error(" {}  .", calc); 

generates the normal expected result if I run my application in windows. But if I have the same configuration on a Mac, I have question marks instead of words, for example:

 15:37:29.083 ERROR rggcTotalNachController - ?????????? [id=8871] ??? ???????????. 

my log configuration:

 <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> 

Can someone please tell me what I am doing wrong?

+6
source share
2 answers

Try to determine the encoding for the 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> 

Unfortunately, this is not described in the documentation, but you can always look for properties in the source code. Specyfing <encoder> creates an instance of PatternLayoutEncoder. Approaching the parent LayoutWrappingEncoder , you can find the setCharset () method. When specified, it is used, as you can see in http://logback.qos.ch/xref/ch/qos/logback/core/encoder/LayoutWrappingEncoder.html#120

+15
source

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

I suggest using the more or less UNIX commands from the Terminal application, which should support your encoding to verify that characters are printed correctly.

0
source

All Articles