Running a Log4j Socket Server
as a
Windows Service
This document spells out some quick steps for running the socket server
that comes with Log4j
as a Windows service using the
Java Services product.
This is ideal for log servers that collect logging events from multiple
application servers.
Ingredients
To get started, you'll need the following downloads:
Configuration
There are many configuration options for both the Log4j's socket server
and the Java Service Wrapper. These instructions are simply intended to
get things going. Once it works, you can start the relevant product
documentation to start having fun.
- Unzip the Wrapper zip file. The directory created by
expanding this zip file will be hereafter referred to as
{wrapper}.
- Create a new directory to hold the socket server service files.
This directory will be hereafter referred to as {log4j}.
- Copy the following files into the {log4j} directory:
- {wrapper}/bin/Wrapper.exe
- {wrapper}/src/bin/App.bat.in
- {wrapper}/src/bin/InstallApp-NT.bat.in
- {wrapper}/src/bin/UninstallApp-NT.bat.in
- {wrapper}/src/conf/wrapper.conf.in
- For each file ending in ".in", in the {log4j}
directory, rename the file so that "App" is replaced
with "Log4j" and the ".in" is stripped.
- Strip the ".in" extensions from these files that were
copied into the {log4j} directory.
- Replace all occurences of "../conf/wrapper.conf" with
"wrapper.conf" in the *.bat files in the {log4j}
directory since we are not creating a special conf
directory.
- Create a {log4j}/lib directory and copy into it
the following files:
- {wrapper}/lib/wrapper.dll
- {wrapper}/lib/wrapper.jar
- Edit the {log4j}/wrapper.conf.
- wrapper.java.command - Set this property to the
fully qualified path name to the Java executable.
- wrapper.java.mainclass=org.tanukisoftware.wrapper.WrapperSimpleApp
- wrapper.java.classpath.1=lib/wrapper.jar
- wrapper.java.classpath.2=lib/log4j-1.2.8.jar - or
whatever the name of your log4j library.
- wrapper.app.parameter.1=org.apache.log4j.net.SocketServer
- wrapper.app.parameter.2=4445
- wrapper.app.parameter.3=log4j.properties
- wrapper.app.parameter.4=lcf
- wrapper.console.title=Log4j Socket Server
- wrapper.ntservice.name=Log4j
- wrapper.ntservice.displayname=Log4j Socket Server
- wrapper.ntservice.description=Listens for remote Log4j events
- Create an {log4j}/lcf directory and place the
appropriate Location Configuration Files there. Minimally, there
should at least be a generic.lcf.
Testing
The Java Service Wrapper provides a convenient facility for testing
your configuration before installing it as a service. Open a
command line to the {log4j} directory and run
log4j
This will run the socket server in the same manner as it will be run
as a service. You can break out of it with Ctrl-C. If this does every
thing you need, you can proceed to service installation. It's a good
idea to flush the problems out here. Some alterations to the
wrapper.conf file are not recommended once the service has
been installed.
Installing the Service
Just run the InstallLog4j-NT.bat command. The service should then
appear in the Windows services panel.