I am using Logback for logging. Scribe appenders send the logs in real time to a central Scribe aggregator. But I don't know how to add source machine IP in the logs for each log events. Looking at the aggregated central Scribe logs, it is almost impossible to know which machine is sending the logs. Hence, appending the IP of source machine to each log event will be helpful, and will be really great if we can control that through logback configuration.
Asked
Active
Viewed 2.6k times
18
-
5Ok.. I got it. I need to use ${HOSTNAME} in the pattern layout. – Nipun Talukdar May 12 '14 at 09:48
-
I used %contextName in patternLayout and it works. – Sundararaj Govindasamy Jul 27 '16 at 15:25
3 Answers
14
It's possible to pass down hostname to remote receiver thru contextName.
Add following to logback.xml on all appenders:
<contextName>${HOSTNAME}</contextName>
Then, on aggregator instance, it will be available for inclusion in the pattern:
<pattern>%contextName %d %-5level %logger{35} - %msg %n</pattern>

iTake
- 4,082
- 3
- 33
- 26
9
According to the Logback docs, there's now a CanonicalHostNamePropertyDefiner
expressly to add a hostname to your logs. Add a define to your project:
<define name="hostname"
class="ch.qos.logback.core.property.CanonicalHostNamePropertyDefiner"/>
and access it as ${hostname}

Ron Romero
- 9,211
- 8
- 43
- 64
-
I'm puzzled by the link. It's clearly documented there, but I'm using the latest non-beta version and that class doesn't exist. – Ickster Sep 19 '18 at 01:32
-
1@Ickster That's because it was added in 1.3.0-alpha2, not yet released, see https://github.com/qos-ch/logback/commit/7209b1fb3d50180af97550a82b1acf67ad196a9d – Alin Pandichi Feb 26 '19 at 14:06
-
2
well if you are working on a client server project then u can use MDC feature of slf4j/logback full document here and in this case you can have a well structured log file that you can identify which log is for which client
hope this helps!

Mr.Q
- 4,316
- 3
- 43
- 40