Syslog: White Paper FAQ Examples JavaDoc

Protomatter Syslog FAQ

Nate Sammons - November, 2001
Covers Release 1.1.6

  1. Do you have any examples of XML configuration files?
  2. Yes. They are over here.


  3. I can't see any output and I'm calling and Syslog.debug()
  4. By default, Syslog ignores messages below the WARNING level. To change this, you must reconfigure the policy. The default syslog configuration looks like this:

        <?xml version="1.0" encoding="UTF-8"?>
        <Syslog defaultMask="WARNING">
          <Logger name="PrintWriterLog.err" class="com.protomatter.syslog.PrintWriterLog">  
            <Format class="com.protomatter.syslog.SimpleSyslogTextFormatter">
              <dateFormat>HH:mm:ss MM/dd</dateFormat>
            <Policy class="com.protomatter.syslog.SimpleLogPolicy">

    You can get this default configuration from Syslog by typing the following command:

        java com.protomatter.syslog.xml.SyslogXML  

    The areas to change are highlighted in red. If you change the WARNING value, it will affect all loggers that have their logMask value set to INHERIT_MASK. If you change just the INHERIT_MASK value, then it just affects the logger you change it on.

    If you set this value to the name of a log level (DEBUG, INFO, WARNING, ERROR or FATAL), then messages at or above that level will be logged.

    You can also set it to a list of levels to pay attention to. If, for example, you set it to "=INFO,=ERROR" then only message at the INFO or ERROR levels are logged.

    After saving a changed version of the configuration file, you can configure Syslog at runtime using the file by executing the following code in your application:

        import com.protomatter.syslog.xml.SyslogXML;
        SyslogXML.configure(new File("filename.xml"));  


  5. What's the story with buffering and file-related loggers?
  6. In version 1.1.6, by default each logger flushes it's buffer every time a message is sent to it. This was not the case in 1.1.5, where buffering was on by default. Loggers that write to files (FileLog, LengthRolloverLog and TimeRolloverLog) can also use buffered output streams to be more efficient while writing to files.

    The problem with using buffers is that if messages suddenly stop coming into the logger (your web application gets less traffic, for instance), it won't flush its buffer. There's no good way to determine if a buffer should be flushed (because it's impossible to know that a log message will be coming soon).

    To solve this problem, you can do a couple of things:

    1. Add the <autoFlush>true</autoFlush> configuration element to the XML configuration info for the loggers. This will cause the log to be written to each time a message comes in. This is the same as calling the setAutoFlush() method on the logger if you're configuring things programatically.
    2. Add the flushThreadInterval attribute to your XML file's <Syslog> element. This has the same effect as calling the Syslog.setFlushThreadInterval() method.

    If you choose to turn off buffering (the default) then the log will always be completely up to date with the latest messages that have arrived. If you want to do buffering, using the flush thread sleep interval parameter will cause syslog to start a background thread that continuously flushes the buffers in all loggers and then sleeps for the number of milliseconds you tell it to.

    The effect of using this is that you'll get buffered I/O to log files, and the log will never be farther behind than the sleep interval. Be careful not to set this value too low (below 5000 is probably not a good idea).


  7. Does Syslog work with <insert-random-application-server-here>?
  8. Almost certainly. However, the only application server that Syslog has a hook into is BEA WebLogic Server (using the SyslogT3Startup class).

    If the application server you're working with supports the idea of a class that's loaded and run when the server starts, you should be able to write your own Syslog initializer class to tie into your application server. Basically, the class should call SyslogXML.configure(...) to configure Syslog from an XML file.

    If your application server supports the Servlet 2.2 specification, then you can use the SyslogInitServlet to initialize syslog when a WebApp starts. Please see the JavaDoc for that class for more information. Please note that even if you aren't building a web-based application, you can still use the servlet to configure Syslog when your app server boots.