Thanks Matt, ThreadContext did the trick.
I really appreciate you taking the time out to answer my question.

Regards,
Anhad

On Fri, Jun 9, 2017 at 8:07 AM, Matt Sicker <boa...@gmail.com> wrote:

> You could add that data to the ThreadContext which would be sent along with
> each log message.
>
> On 9 June 2017 at 01:46, Anhad Singh Bhasin <anhadbha...@gmail.com> wrote:
>
> > Hello everyone,
> >
> > I am new to Log4J2 and unable to find answer to a simple question, which
> am
> > sure would be a simple thing for someone who has worked on Log4J2. I
> tried
> > asking the same question on Stack Overflow but no one replied hence
> asking
> > the same question here. Any help would be deeply appreciated. Thanks a
> lot.
> >
> > The question link on Stack over flow is this -
> https://stackoverflow.com/
> > questions/44445108/log4j2-how-to-pass-application-name-in-
> tcpsocketserver-
> > implementation-from-cli
> >
> > Same Question here : I am running a Log4J2 TCPSocketServer on an edge
> node
> > in a cluster. All the data nodes send log events to the TCPSocketServer
> on
> > the edge node and also log locally in the data node using the log4j2.xml
> > configuration file as shown below. The Application Name is stored as a
> > System property and is accessible in the data node or client's log4j2.xml
> > configuration using ${sys:ABC.appname}. How can I send the same appname
> to
> > the edge node where TCPSocketServer is running using the log4j2.xml. I
> > would be using the same Application Name in the log4j2-server.xml to log
> > events into separate log files just like I am doing locally on data node.
> >
> > Sample snippet from data node or Client - log4j2.xml :
> >
> >     <?xml version="1.0" encoding="UTF-8"?>
> >     <Configuration status="warn" name="MyApp" >
> >     <Appenders>
> >     <Socket name="socket" host="localhost" port="12345" >
> >     <SerializedLayout />
> >     </Socket>
> >     <File name="MyFile" fileName="/var/log/${sys:ABC.appname}.log" >
> >     <PatternLayout>
> >     <Pattern>%d{ISO8601} %p %c{1.} [%t] %m%n</Pattern>
> >     </PatternLayout>
> >     </File>
> >     </Appenders>
> >     <Loggers>
> >     <Root level="debug">
> >     <AppenderRef ref="socket"/>
> >     <AppenderRef ref="MyFile"/>
> >     </Root>
> >     </Loggers>
> >     </Configuration>
> >
> > Sample snippet from edge node or Server - log4j2-server.xml
> >
> >     <?xml version="1.0" encoding="UTF-8"?>
> >     <Configuration status="WARN">
> >     <Appenders>
> >     <File name="MyFile" fileName="/var/log/data/${hostName}-<**This is
> > where I would like to see the appname from data node**>.log" >
> >     <PatternLayout>
> >     <Pattern>%d{ISO8601} %p %c{1.} [%t] %m%n</Pattern>
> >     </PatternLayout>
> >     </File>
> >     <Async name="AsyncFile">
> >     <AppenderRef ref="MyFile" />
> >     </Async>
> >     </Appenders>
> >     <Loggers>
> >     <Root level="WARN">
> >     <AppenderRef ref="AsyncFile"/>
> >     </Root>
> >     </Loggers>
> >     </Configuration>
> >
> >
> > Thank you so much for your time.
> >
> > Regards,
> >
> > Anhad Singh Bhasin
> >
>
>
>
> --
> Matt Sicker <boa...@gmail.com>
>

Reply via email to