[logback-user] ConsoleAppender/FileAppender encoding

Ceki Gülcü ceki at qos.ch
Thu Mar 25 19:18:50 CET 2010


Due to a bug, the following snippet which normally should work, fails miserably.

<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
   <encoder>
     <pattern>%d %t [%-5level] - %-40class{40} - %msg%n</pattern>
     <charset>UTF-8</charset>
   </encoder>
</appender>

The fix is in git and will be part of 0.9.20.

On 25/03/2010 6:10 PM, Matthieu Guamis wrote:
> Thank you for quick reply!
>
> Setting the property Charset with a string leads to a new error:
> 17:49:46,884 |-ERROR in
> ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Could not
> find an appropriate class for property [charset]
>
> LayoutWrappingEncoder contains method setCharset(Charset charset) so I
> tried this config:
>
> <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
> <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
> <pattern>%d %t [%-5level] - %-40class{40} - %msg%n</pattern>
> <charset class="java.nio.charset.Charset">UTF-8</charset>
> </encoder>
> </appender>
>
> But the java.nio.charset.Charset class does not allow this king of
> instantiation since its constructor is protected.
> Using Charset.forName("UTF-8") seems the way to do it but I don't know
> how to specify it in configuration file dialect :(
> Any trick?
>
> Regards,
>
>
> *Matthieu Guamis*
> *Logo Axège <http://www.axege.com/>* 	/Axège//
> 23,rue Saint-Simon
> 63000 Clermont-Ferrand/
>
> Tél: +33 (0)4 63 05 95 40
> Fax: +33 (0)4.73.70.65.29
> Email: matthieu.guamis at axege.com <mailto:matthieu.guamis at axege.com>
>
> Le 25/03/2010 17:12, Ceki Gülcü a écrit :
>>
>> Hello Matthieu,
>>
>> The encoding property has been renamed as Charset and now is part of
>> the encoder. The config file snippet becomes:
>>
>> <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
>> <encoder>
>> <pattern>%d %t [%-5level] - %-40class{40} - %msg%n</pattern>
>> <charset>UTF-8</charset>
>> </encoder>
>> </appender>
>>
>> HTH,
>>
>> On 25/03/2010 4:33 PM, Matthieu Guamis wrote:
>>> Hi,
>>>
>>> It seems that element "encoding" is no more recognized in
>>> Console/FileAppender so maybe I missed something (no more reference in
>>> documentation) but I did not find what :(
>>> Here is my (new) configuration (logback 0.9.19)
>>>
>>> <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
>>> <encoding>UTF-8</encoding>
>>> <encoder>
>>> <pattern>%d %t [%-5level] - %-40class{40} - %msg%n</pattern>
>>> </encoder>
>>> </appender>
>>>
>>> And the corresponding output at runtime:
>>>
>>> [...]
>>> 15:58:29,127 |-INFO in ch.qos.logback.core.joran.action.AppenderAction -
>>> About to instantiate appender of type
>>> [ch.qos.logback.core.ConsoleAppender]
>>> 15:58:29,146 |-INFO in ch.qos.logback.core.joran.action.AppenderAction -
>>> Naming appender as [STDOUT]
>>>
>>> 15:58:29,226 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter at 7:13 -
>>> no applicable action for [encoding], current pattern is
>>> [[configuration][appender][encoding]]
>>>
>>> 15:58:29,230 |-INFO in
>>> ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Pushing
>>> component [encoder] on top of the object stack.
>>> 15:58:29,403 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction
>>> - Setting additivity of logger [org.barracudamvc] to true
>>> 15:58:29,403 |-INFO in ch.qos.logback.classic.joran.action.LevelAction -
>>> org.barracudamvc level set to WARN
>>> 15:58:29,403 |-INFO in
>>> ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender
>>> named [STDOUT] to Logger[org.barracudamvc]
>>> [...]
>>>
>>> Any suggestion on what could be wrong?
>>> Thanks
>>>
>>> --
>>> *Matthieu Guamis*
>>> *Logo Axège <http://www.axege.com/>* /Axège//
>>> 23,rue Saint-Simon
>>> 63000 Clermont-Ferrand/
>>>
>>> Tél: +33 (0)4 63 05 95 40
>>> Fax: +33 (0)4.73.70.65.29
>>> Email: matthieu.guamis at axege.com <mailto:matthieu.guamis at axege.com>
>>>
>>>
>>>
>>> _______________________________________________
>>> Logback-user mailing list
>>> Logback-user at qos.ch
>>> http://qos.ch/mailman/listinfo/logback-user
>>
>> _______________________________________________
>> Logback-user mailing list
>> Logback-user at qos.ch
>> http://qos.ch/mailman/listinfo/logback-user
>
>
> _______________________________________________
> Logback-user mailing list
> Logback-user at qos.ch
> http://qos.ch/mailman/listinfo/logback-user



More information about the Logback-user mailing list