logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gary Gregory <garydgreg...@gmail.com>
Subject Re: Using log4j SimpleSocketServer with log4j2
Date Wed, 27 Jan 2016 06:05:13 GMT
Nipuni,

For Log4j 2, please see:

org.apache.logging.log4j.core.net.server.TcpSocketServer
org.apache.logging.log4j.core.net.server.UdpSocketServer

Gary

On Tue, Jan 26, 2016 at 9:25 PM, Nipuni Piyabasi Perera <
nipuni880917@gmail.com> wrote:

> Hi all,
>
> I am trying to save logs sent to a server(log4j SimpleSocketserver) via
> SocketAppender. I have tried this with log4j and log4j2 as follows.
>
> *Working scenario: *
> Log4j.properties configuration:
>
> # MY_LOGFILE is set to be a DailyRollingFileAppender using a PatternLayout.
>
> log4j.appender.MY_LOGFILE=org.apache.log4j.net.SocketAppender
>
> log4j.appender.MY_LOGFILE.Port=4712
>
> log4j.appender.MY_LOGFILE.RemoteHost=localhost
>
> log4j.appender.MY_LOGFILE.ReconnectionDelay=10000
>
>
> *Error scenario:*
>
> Log4j2.xml configuration:
>
> <Configuration>
>
>     <Appenders>
>
>        ....
>
>         <Socket name="socket" host="localhost" port="4712">
>
>       <PatternLayout pattern="[%d] %5p {%c} - %m%ex%n" charset="UTF-8"/>
>
>     </Socket>
>
>     </Appenders>
>
>     <Loggers>
>
>         <Root level="info">
>
>             <AppenderRef ref="..."/>
>
>             <AppenderRef ref="..."/>
>
>         </Root>
>
>         <Logger name="org.my.custom.package" level="debug"
> additivity="false">
>
>                 <AppenderRef ref="socket"/>
>
>     </Logger>
>
>     </Loggers>
>
> </Configuration>
>
>
> I am starting the log4j SimpleSocketserver with port 4712 (java -classpath
>  apache-log4j.jar  org.apache.log4j.net.SimpleSocketServer 4712
> configfile/test.properties) with properties below:
>
> log4j.rootLogger=DEBUG, file
>
>
> #Define how the socket server should store the log events
>
> log4j.appender.file=org.apache.log4j.RollingFileAppender
>
> log4j.appender.file.File=application-error.log
>
> log4j.appender.file.MaxFileSize=1MB
>
> log4j.appender.file.MaxBackupIndex=1
>
> log4j.appender.file.layout=org.apache.log4j.PatternLayout
>
> log4j.appender.file.layout.ConversionPattern=[%d] [%t] [%m]%n
>
>
> I could see logs from my custom package with the first (I.e., log4j older)
> configuratuon and I am receiving an error[1] from at SimpleSocketServer
> side with the log4j2 configuration.  I assume that the SimpleSocketServer
> may not compatible with log4j2. If that is the issue is there a log4j
> server compatible with log4j2 SocketAppender?. Or am I missing something
> here with the log4j2 configuration?
>
> [1]   [2016-01-27 09:49:57,299] [main] [Connected to client at /127.0.0.1]
>        [2016-01-27 09:49:57,299] [main] [Starting new socket node.]
>        [2016-01-27 09:49:57,300] [main] [Waiting to accept a new client.]
>        [2016-01-27 09:49:57,479] [Thread-1] [Unexpected exception. Closing
> conneciton.]
>        java.lang.ClassNotFoundException:
> org.apache.logging.log4j.core.impl.Log4jLogEvent$LogEventProxy
> at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
> at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
> at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
> at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
> at java.lang.Class.forName0(Native Method)
> at java.lang.Class.forName(Class.java:348)
> at java.io.ObjectInputStream.resolveClass(ObjectInputStream.java:626)
> at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1613)
> at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1518)
> at
> java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1774)
> at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1351)
> at java.io.ObjectInputStream.readObject(ObjectInputStream.java:371)
> at org.apache.log4j.net.SocketNode.run(SocketNode.java:67)
> at java.lang.Thread.run(Thread.java:745)
>
> Thanks,
> Nipuni
>
> --
> Nipuni Perera
> Software Engineer; WSO2 Inc.; http://wso2.com
> Email: nipuni@wso2.com
> Git hub profile: https://github.com/nipuni
> Blog : http://nipunipererablog.blogspot.com/
> Mobile: +94 (71) 5626680
>



-- 
E-Mail: garydgregory@gmail.com | ggregory@apache.org
Java Persistence with Hibernate, Second Edition
<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message