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.

  1. Unzip the Wrapper zip file. The directory created by expanding this zip file will be hereafter referred to as {wrapper}.

  2. Create a new directory to hold the socket server service files. This directory will be hereafter referred to as {log4j}.

  3. Copy the following files into the {log4j} directory:

  4. 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.
  5. Strip the ".in" extensions from these files that were copied into the {log4j} directory.

  6. 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.

  7. Create a {log4j}/lib directory and copy into it the following files:

  8. Edit the {log4j}/wrapper.conf.

    1. wrapper.java.command - Set this property to the fully qualified path name to the Java executable.
    2. wrapper.java.mainclass=org.tanukisoftware.wrapper.WrapperSimpleApp

    3. wrapper.java.classpath.1=lib/wrapper.jar
    4. wrapper.java.classpath.2=lib/log4j-1.2.8.jar - or whatever the name of your log4j library.

    5. wrapper.app.parameter.1=org.apache.log4j.net.SocketServer
    6. wrapper.app.parameter.2=4445
    7. wrapper.app.parameter.3=log4j.properties
    8. wrapper.app.parameter.4=lcf

    9. wrapper.console.title=Log4j Socket Server
    10. wrapper.ntservice.name=Log4j
    11. wrapper.ntservice.displayname=Log4j Socket Server
    12. wrapper.ntservice.description=Listens for remote Log4j events

  9. 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.