This tutorial assumes you already have the StackHub daemon up and running with your application token. If you don't have the daemon installed yet, do that first.
Let's say your existing application prints logging events of level INFO and above to stdout using a simple console appender like this:
# Simple log4j.properties file log4j.rootCategory=INFO, dest log4j.appender.dest=org.apache.log4j.ConsoleAppender log4j.appender.dest.layout=org.apache.log4j.PatternLayout log4j.appender.dest.layout.ConversionPattern=%d [%t] %-5p %c - %m%nMake sure your application is happily logging to the console before proceeding.
We are going to keep your existing Log4J configuration the way it is, and just add a new SocketAppender to the mix. The SocketAppender will connect to the StackHub daemon when your application starts up.
# A log4j.properties file using a SocketAppender to connect with the StackHub daemon log4j.rootCategory=INFO, dest, stackhub log4j.appender.dest=org.apache.log4j.ConsoleAppender log4j.appender.dest.layout=org.apache.log4j.PatternLayout log4j.appender.dest.layout.ConversionPattern=%d [%t] %-5p %c - %m%n log4j.appender.stackhub=org.apache.log4j.net.SocketAppender log4j.appender.stackhub.RemoteHost=10.0.1.2 log4j.appender.stackhub.Port=8888 log4j.appender.stackhub.LocationInfo=false log4j.appender.stackhub.ReconnectionDelay=5
You'll need to change RemoteHost to whatever IP address your daemon says it is listening on.
If you have Log4J set up with
configureAndWatch()
then your changes will take effect without having to restart your application. Otherwise, go ahead and restart it.
In your StackHub daemon output, you should see something like this:
INFO stackhub.LoggingReceiver - Starting new socket node with remote client at 10.0.1.17
In the example above, both appenders are logging the same things. So if you don't see anything logged in stdout, you won't see anything at StackHub either!