Resin Documentationapp server |
log
Resin can perform access logging, specify where JDK logging interface messages go, and redirect the stderr and stdout for your applications. Logger: Application loggingYou can take advantage of the JDK's logging facility to add logging to your application. Choosing a good logging name and levels are important for troubleshooting and debugging your code. Logging to much can be almost as confusing as logging too little. The logging name should be the full class name of the class you're instrumenting. Although other schemes are possible, the class name is more maintainable. The logging level should be consistent across your application. For Resin, we use the following level conventions: import java.util.logging.Logger; import java.util.logging.Level; public class Foo { private static final Logger log = Logger.getLogger(Foo.class.getName()); ... void doFoo(String bar) { // check for log level if your logging call does anything more // than pass parameters if (log.isLoggable(Level.FINER)) log.finer(this + "doFoo(" + bar + ")"); ... log.info(...); try { ... } catch (ExpectedException ex) { log.log(Level.FINEST, "expected exception", ex); } } ... } Log namesThe JDK logging api uses a hierarchical naming scheme. Typically the name
is aligned with a java class name. When you specify a name, all logging
requests that use a name that starts with the name you have specified are
matched. For example: Resin's logging is based on Resin's source class names. The following are useful logs.
Log levelsfor log tags matches the levels in the JDK
<log-handler>child of resin, server, host-default, host, web-app-default, web-appConfigure a log handler for the JDK java.util.logging.* API. java.util.logging has two steps: configure a set of log handlers, and configure the levels for each logger. The <log-handler> creates a destination for logs, sets a minimum logging level for the handler, and attaches the handler to a logging name. In addition to configuring custom handlers, <log-handler> has the most common configuration build-in: logging to a rotating file. Most of the configuration attributes are used for the rotating file and are shared with the other logging configuration.
element log-handler { archive-format? & class? & filter? & format? & formatter? & init? & level? & mbean-name? & name & path? & path-format? & rollover-count? & rollover-period? & rollover-size? & timestamp? & uri? & use-parent-handlers? } The following example sends warning messages to a JMS queue. The
<web-app xmlns="http://caucho.com/ns/resin"> <jms-queue name="myQueue" uri="memory:"/> <log-handler name="qa.test" level="warning" uri="jms:"> <init target="${myQueue}"/> <formatter uri="timestamp:"/> </log-handler> </web-app> The following example is a standard log handler writing to a rollover file. Because the handler's level is "all", the <logger> configuration will set the actual logging level. <web-app xmlns="http://caucho.com/ns/resin"> <jms-queue name="myQueue" uri="memory:"/> <log-handler name="" level="all" timestamp="[%Y/%m/%d %H:%M:%S.%s] {%{thread}} "/> <logger name="com.caucho" level="info"/> </web-app> <log>child of resin, server, host-default, host, web-app-default, web-appConfigure the amount and destination of debug logging for the JDK java.util.logging.* API.
The default archive format is + ".%Y%m%d" if rollover-period >= 1 day. + ".%Y%m%d.%H" if rollover-period < 1 day. For example, to log everything to standard error use: <resin xmlns="http://caucho.com/ns/resin"> <log name='' level='all' path='stderr:' timestamp="[%H:%M:%S.%s]"/> ... </resin> A useful technique is to enable full debug logging to track down a problem: <resin> ... <log name='' level='finer' path='log/debug.log' timestamp="[%H:%M:%S.%s]" rollover-period='1h' rollover-count='1'/> ... </resin> More examples of debug logging are in the Troubleshooting section. The class that corresponds to <log> is . Log format stringThe <log name='' level='all' path='stderr:' timestamp="[%H:%M:%S.%s]" format=" ${log.level} ${log.loggerName} ${log.message}"/> You can also use the Environment EL variables in your format string: <host ...> <web-app> <log name='' level='all' path='log/debug.log' timestamp="[%H:%M:%S.%s]" format=" [${'${'}app.contextPath}] ${'${'}log.message}"/> ... </web-app> ... </host> [14:55:10.189] [/foo] `null' returning JNDI java: model for EnvironmentClassLoader[web-app:http://localhost:8080/foo] [14:55:10.189] [/foo] JNDI lookup `java:comp/env/caucho/auth' exception javax.naming.NameNotFoundException: java:comp/env/caucho/auth [14:55:10.199] [/foo] Application[http://localhost:8080/foo] starting The fmt.sprintf() function can space pad the values and make the results look a little nicer: <log name='' level='all' path='stderr:' timestamp="[%H:%M:%S.%s]" format=" ${fmt.sprintf('%-7s %45s %s',log.level,log.loggerName,log.message)}"/> [14:28:08.137] INFO com.caucho.vfs.QJniServerSocket Loaded Socket JNI library. [14:28:08.137] INFO com.caucho.server.port.Port http listening to *:8080 [14:28:08.137] INFO com.caucho.server.resin.ServletServer ServletServer[] starting [14:28:08.307] INFO com.caucho.server.port.Port hmux listening to localhost:6802 [14:28:08.437] INFO com.caucho.server.host.Host Host[] starting fmt.sprintf() and fmt.timestamp() can be used to produce CSV files: <log name='' level='all' path='log/debug.csv' timestamp="" format="${fmt.sprintf('%vs,%d,%d,%vs,%vs',fmt.timestamp('%Y-%m-%d %H:%M:%S.%s'), log.threadID, log.level.intLevel(), log.loggerName, log.message)}"/> "2003-11-17 14:46:14.529",10,800,"com.caucho.vfs.QJniServerSocket", "Loaded Socket JNI library." "2003-11-17 14:46:14.549",10,800,"com.caucho.server.port.Port", "http listening to *:8080" "2003-11-17 14:46:14.549",10,800,"com.caucho.server.resin.ServletServer", "ServletServer[] starting" "2003-11-17 14:46:14.719",10,800,"com.caucho.server.port.Port", "hmux listening to localhost:6802" "2003-11-17 14:46:14.850",10,800,"com.caucho.server.host.Host", "Host[] starting" "2003-11-17 14:46:15.100",10,800,"com.caucho.server.webapp.Application", "Application[http://localhost:8080/freelistbm] starting" Log HandlersResin provides a number of predefined custom log handlers for common logging patterns, including sending messages to JMS, HMTP, and the syslog service. Creating your own custom handler is also straightforward. EventHandler, uri='event:'The event handler publishes a <web-app xmlns="http://caucho.com/ns/resin"> <log-handler name="com.foo" level="warning" uri="event:"/> </web-app> HmtpHandler, uri='hmtp:'The HMTP handler publishes the log message to a HMTP
agent. The agent can be a custom HMTP service to process log messages.
The <web-app xmlns="http://caucho.com/ns/resin"> <log-handler name="com.foo" level="warning" uri="hmtp:"> <init> <to>test@localhost</to> </init> </log-handler> </web-app> JmsHandler, uri='jms:'The JMS handler publishes the log message to a JMS queue. <web-app xmlns="http://caucho.com/ns/resin"> <jms-queue name="myQueue" uri="memory:"/> <log-handler name="com.foo" level="warning" uri="jms:"> <init> <target>${myQueue}</target> </init> </log-handler> </web-app> SyslogHandler, uri='syslog:'On Unix systems, the SyslogHandler lets you log messages to syslog. <resin xmlns="http://caucho.com/ns/resin"> <log-handler name="" level="warning" uri="syslog:"> <init> <facility>daemon</facility> <severity>notice</severity> </init> </log-handler> The possible values for are user, mail, daemon, auth, lpr, news, uucp, cron, authpriv, ftp, local0, local1, local2, local3, local4, local5, local6, local7. The default is daemon.The possible values for are emerg, alert, crit, err, warning, notice, info, debug. The default is info.See also ` custom handler<web-app xmlns="http://caucho.com/ns/resin"> <log-handler name="" level="warning" class="demo.MyHandler"/> </web-app> package demo; import java.util.logging.*; public class MyHandler extends Handler { @Override public void publish(LogRecord record) { System.out.println(getFormatter().format(record)); } @Override public void flush(); { } @Override public void close(); { } } Log FormattingSites may wish to change the formatting of log messages to gather information more appropriate for the site. The formatter can be custom-configured just like the handlers. custom handler<web-app xmlns="http://caucho.com/ns/resin"> <log-handler name="com.foo" level="warning" path="WEB-INF/log.log"> <formatter class="qa.MyFormatter"/> </log-handler> </web-app> package demo; import java.util.logging.*; public class MyFormatter extends Formatter { @Override public String format(LogRecord record) { return "[" + record.getLevel() + "] " + record.getMessage(); } } stdout-logchild of resin, server, host-default, web-app-default, web-appdefault use the JDK's destination for System.out Configure the destination for .Usage of the Warning The overrides a previous usage. For example, specifying as a child of a <web-app> causes a redirection of for that web application only, and will override the location in the enclosing <host>. must not be the same as the path specified on the command line with-stdout . If it is, there will be conflicts with
which process owns the file.
The default archive format is + ".%Y%m%d" or + ".%Y%m%d.%H" if rollover-period < 1 day. The following example configures ... <host id='foo.com'> <stdout-log path='/var/log/foo/stdout.log' rollover-period='1W'/> ... </host> ... stderr-logchild of resin, server, host-default, web-app-default, web-appdefault use the JDK's destination for System.err Configure the destination for .Usage of the Warning The overrides a previous usage. For example, specifying as a child of a <web-app> causes a redirection of for that web application only, and will override the location in the enclosing <host>. must not be the same as the path specified on the command line with-stderr . If it is, there will be conflicts with
which process owns the file.
The default archive format is + ".%Y%m%d" or + ".%Y%m%d.%H" if rollover-period < 1 day. The following example configures ... <host id='foo.com'> <stderr-log path='/var/log/foo/stderr.log' rollover-period='1W'/> ... </host> ... Specify the access log file. As a child of <web-app>, overrides the definition in the <host> that the web-app is deployed in. As a child of <host>, overrides the definition in the <server> that the host is in.
The default archive format is + ".%Y%m%d" or + ".%Y%m%d.%H" if rollover-period < 1 day. ... <host id=''> <access-log path='log/access.log'> <rollover-period>2W</rollover-period> </access-log> ... </host> ... The access log formatting variables follow the Apache variables:
The default format is: "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" . Bean-style initialization can be used to set bean parameters in the custom class. allows for custom logging. Applications can extend a custom class from... <host id='foo.com'> <access-log resin:type='test.MyLog'> path='$server-root/foo/error.log' rollover-period='1W'> <init> <foo>bar</foo> </init> </access-log> ... </host> ...
<log name="" level="all" path="stdout:"/> You can use the Environment EL variables as part of your filesystem path: <log name="" level="all" path="log/debug-${server.id}.log" rollover-period="1h" rollover-count="1"/> Log rollovers are a way to stop your log files from getting too large. When a rollover is triggered, the existing log file is renamed and a new file is started. Size based rolloverA size based rollover is triggered when the size of the file reaches a certain amount. The default Resin behaviour for log's is to rollover when the file size reaches 1mb.
Time based rolloverA time based rollover is triggered when a certain period of time has passed since the last rollover. The default Resin behaviour is to perform no time based rollover, unless rollover-size has been disabled with a value of -1 in which case the default time period is 1 month.
Archive filesWhen a rollover is triggered, the log file is renamed (archived) and a new log file is started.
The default behaviour depends on the value of rollover-period. If
rollover-period is greater than one day, or is not being used because
rollover-size has been specified, the archive filename is the original path
with Disabling rolloversTo completely disable rollovers, set the <stdout-log path="log//stdout.log" rollover-size="1024mb"/> CompressionRollover log files can be compressed with gzip or zip. The extension of the archive-format determines the compression. <log name="" level="warning" path='log/error.log' archive-format="%Y-%m-%d.error.log.gz" rollover-period="1D"/> <access-log path="log/access.log" archive-format="access-%Y%m%d.log.gz" rollover-period="1D"/> The for log tags is a format string which can contain percent codes which are substituted with time and date values.
<log name='' level='all' path='stderr:' timestamp="[%H:%M:%S.%s]"/> [22:50:11.648] Application[/doc] starting [22:50:11.698] http listening to *:8080 [22:50:11.828] hmux listening to *:6802
|