[logback-user] SocketAppender application property

haukex hauke at zero-g.net
Thu Aug 20 13:08:33 CEST 2009


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?

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.

What am I doing wrong? :)

Thanks,
-- Hauke D


Ceki Gulcu wrote:
> 
> Hello Hauke,
> 
> 
> For application-wide values, you don't need to use MDC. Logback offers
> a better suited alternative in the form of context properties. Every
> logger is attached to a context, you can obtain it as:
> 
> LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
> 
> you can then write:
> 
> lc.putProperty("key", "val");
> 
> Context properties can also be set via configuration files. See
> http://logback.qos.ch/manual/configuration.html#variableSubstitution
> 
> Moreover, every logging event generated by logback will contain the
> properties contained in the context, i.e. they are available to all
> appenders. Context information is also serialized with each outgoing
> logging event.
> 
> If you are only interested in setting the name of the application, you
> can set the name of the context in the configuration file. See
> http://logback.qos.ch/manual/configuration.html#contextName
> 
> The %contextName conversion word in PatternLayout will output the name
> of the logger context.
> 
> I think the above meets the requirements you mentioned, doesn't it?
> 
> HTH,
> 

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



More information about the Logback-user mailing list