[logback-user] SocketAppender application property

haukex hauke at zero-g.net
Thu Aug 20 18:37:29 CEST 2009


Hi Ceki,

Thanks for opening the issue! Do you have an estimate to when this could be
fixed?

Thanks also for the ContextPropertyConverter, I will test that now. Will
this be included in the next release?

Regards,
-- Hauke D


Ceki Gulcu wrote:
> 
> haukex wrote:
>> Hi Ceki,
>> 
>> Thanks for this information! I just tested things out and am having some
>> problems.
>> 
>> I added "<contextName>TestClient</contextName>" to the client's
>> logback.xml
>> and "<contextName>LoggingServer</contextName>" to the server's
>> logback.xml.
>> However, when I used %contextName in the PatternLayout on the server, I
>> am
>> seeing "LoggingServer" being output in the log file instead of
>> "TestClient",
>> so it seems this information is not serialized?
> 
> It's a bug in ContextNameConverter. Instead of reading the context name
> found in 
> the event passed as parameter, it used the context to which it (the 
> ContextNameConverter instance) is attached to. Usually, the context found
> in the 
> event and the context the ContextNameConverter instance is attached to are
> the 
> same. One exception occurs when the event is sent to a remote system.
> Anyway, I 
> entered a jira issue for this: http://jira.qos.ch/browse/LBCLASSIC-149
> 
>> Also, I tried setting <property name="LOGGING_CLIENT" value="TestClient"
>> />
>> on the client (is this the right way to set LoggerContext properties?),
>> and
>> then using ${LOGGING_CLIENT} in the PatternLayout on the server, but I am
>> getting "LOGGING_CLIENT_IS_UNDEFINED" output in the server log. When I
>> set
>> the same property on the server, the value is output.
> 
> There is no converter to display the value of a context parameter.
> However, it 
> should be fairly easy to write one. Here is a possible implementation:
> 
> package apackage.of.yr.choice;
> 
> import java.util.Map;
> 
> import ch.qos.logback.classic.spi.ILoggingEvent;
> import ch.qos.logback.classic.spi.LoggerContextVO;
> 
> public final class ContextPropertyConverter extends ClassicConverter {
> 
>    String propertyName;
> 
>    public void start() {
>      String optStr = getFirstOption();
>      if (optStr != null) {
>        propertyName = optStr;
>        super.start();
>      }
>    }
> 
>    public String convert(ILoggingEvent event) {
>      if(propertyName == null) {
>        return "ContextProperty_HAS_NO_NAME";
>      } else {
>        LoggerContextVO lcvo = event.getLoggerContextVO();
>        Map<String, String> map = lcvo.getPropertyMap();
>        return map.get(propertyName);
>      }
>    }
> }
> 
> Since ContextPropertyConverter does not exist in the current logback
> release 
> (0.9.17), you need to inform logback of its existence. See the
> http://logback.qos.ch/manual/layouts.html and the section entitled
> "Creating a 
> custom conversion specifier". You would need to add a conversion rule
> element 
> similar to the following in your configuration file:
> 
>    <conversionRule conversionWord="property"
>              
> converterClass="apackage.of.yr.choice.ContextPropertyConverter" />
> 
> I hope this helps.  By the way, you would need to add 
> ContextPropertyConverter.class onto your class path.
> 

-- 
View this message in context: http://www.nabble.com/SocketAppender-application-property-tp25009895p25065594.html
Sent from the Logback User mailing list archive at Nabble.com.



More information about the Logback-user mailing list