[logback-user] Servername in SocketAppender

Ceki Gülcü ceki at qos.ch
Thu Mar 4 10:34:54 CET 2010

Hello Ingo,

Properties of the logger context are part of each logging event sent
to the SocketAppender. You can set a context property 'k' to value 'v'
as follows:

   LoggerContext lc = (LoggerContext)
   lc.putProperty("k", "v");

You can have the value of property 'k' printed using the "%property"
conversion word. In PatternLayout set the pattern to for example
"%property{k} ... - %m%n"

As of logback 0.9.19, the HOSTNAME property is defined automatically.
Also note that the name of the context can be retrieved with the
%contextName or %cn conversion words. You can set the name of the
context either programmatically as


or in the configuration file:



On 04/03/2010 10:17 AM, Ingo Siebert wrote:
> Hi,
> I want to use the SocketAppender to collect log messages from more than
> one application server.
> It general it works fine, but I'm missing the servername or IP address
> of the server who sent the LoggingEvent.
> That means I need a layout like this: %date %servername %m%n
> In the documentation, I see a SocketAppender property called
> IncludeCallerData.
> But in the example it only prints %file and %line.
> What is the best practise to add the name/IP of the server which sent
> the logging event to the remote SimpleSocketServer?
> Best regards,
> Ingo

More information about the Logback-user mailing list