|
You can get this default configuration from Syslog by typing the following command:
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. Maybe there's no messages in it, but maybe
there's 5 or 10 -- who knows? 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 and that it might be better to wait 50ms before
flushing the buffer).
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.
You can test your translation by using the MessageConstants
utility like this:
File file = new File("config.xml");
SyslogXML.configure(file, "org.apache.xerces.parsers.SAXParser");
java com.protomatter.syslog.MessageConstants
Constants class: com.protomatter.syslog.MessageConstants
Locale: en_US
Variable name: FLUSH_LOGGERS_MESSAGE
value: FlushLoggers
property: Flushing all loggers
Variable name: SHUTDOWN_SYSLOG_MESSAGE
value: ShutdownSyslog
property: Shutting down Syslog
...
Variable name: JMX_CANNOT_LOAD_FILE_MESSAGE
value: JMX.CannotLoadFile
property: {0}: Cannot load file "{1}"