|
<?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"> <showChannel>false</showChannel> <showThreadName>false</showThreadName> <showHostName>false</showHostName> <dateFormat>HH:mm:ss MM/dd</dateFormat> <dateFormatCacheTime>1000</dateFormatCacheTime> <dateFormatTimeZone>America/Denver</dateFormatTimeZone> </Format> <Policy class="com.protomatter.syslog.SimpleLogPolicy"> <channels>ALL_CHANNEL</channels> <logMask>INHERIT_MASK</logMask> </Policy> <stream>System.err</stream> </Logger> </Syslog> |
java com.protomatter.syslog.xml.SyslogXML |
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 java.io.File; import com.protomatter.syslog.xml.SyslogXML; ... SyslogXML.configure(new File("filename.xml")); |
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:
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).
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.