Caucho Technology
  • resin 4.0
  • log


    Resin can perform access logging, specify where JDK logging interface messages go, and redirect the stderr and stdout for your applications.

    descriptionschemaattributesexample

    <log-handler>

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

    <log-handler> Attributes
    ATTRIBUTEDESCRIPTIONDEFAULT
    archive-formatthe format for the archive filename when a rollover occurs, see Rollovers. see below
    classconfigures a custom Handler class
    formatAn EL expression string to format the current output line.
    formatterConfigures a custom java.util.logging.Formatter to format the output.
    levelThe log level for the handler. Typically, the handler's level will be finer than the logger's levelinfo
    mbean-namean mbean name, see MBean control.no mbean name, no mbean registration
    nameA hierarchical name, typically aligned with the Java packaging names. The handler will be registered with the Logger with the matching name.match all names
    pathOutput path for the log messages, see "Log Paths"required
    path-formatSelects a format for generating path names. The syntax is the same as for archive-formatoptional
    timestampa timestamp format string to use at the beginning of each log line. "[%Y/%m/%d %H:%M:%S.%s] "
    rollover-countmaximum number of rollover files before the oldest ones get overwritten. See Rollovers. none
    rollover-croncron-style specification on rollover times.none
    rollover-periodhow often to rollover the log. Specify in days (15D), weeks (2W), months (1M), or hours (1h). See Rollovers. none
    rollover-sizemaximum size of the file before a rollover occurs, in bytes (50000), kb (128kb), or megabytes (10mb). See Rollovers. 1mb
    <log-handler> schema
    element log-handler {
      archive-format?
      & class?
      & filter?
      & format?
      & formatter?
      & level?
      & mbean-name?
      & name
      & path?
      & path-format?
      & rollover-count?
      & rollover-period?
      & rollover-size?
      & timestamp?
      & use-parent-handlers?
    }
    

    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.

    Example: logging to a rollover file
    <web-app xmlns="http://caucho.com/ns/resin">
    
      <log-handler name="" level="all"
           timestamp="[%Y/%m/%d %H:%M:%S.%s] {%{thread}} "/>
    
      <logger name="com.caucho" level="info"/>
    
    </web-app>
    

    Log format string

    The format for log tags is used to specify a format string for each log message. format recognizes EL-expressions. The EL variable log is a com.caucho.log.ELFormatter.ELFormatterLogRecord object.

    log format string
    
    <log name='' level='all' path='stderr:' timestamp="[%H:%M:%S.%s]"
         format=" ${log.level} ${log.loggerName} ${log.message}"/>
    
    
    log EL variable 'log' is a LogRecord
    ACCESSORVALUE
    ${log.level}The level of the log record
    ${log.name}The source loggers name
    ${log.shortName}A shorter version of the source loggers name, "Foo" instead of "com.hogwarts.Foo"
    ${log.message}The message, with no formatting or localization
    ${log.millis}event time in milliseconds since 1970
    ${log.sourceClassName}Get the name of the class that issued the logging request (may not be available at runtime)
    ${log.sourceMethodName}Get the name of the method that issued the logging request (may not be available at runtime)
    ${log.threadID}Get an int identifier of the thread where the logging request originated
    ${log.thrown}Get any java.lang.Throwable associated with the logging request

    You can also use the Environment EL variables in your format string:

    log format string using an Environment EL variable.
    <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:

    fmt.sprintf() in log format string
    <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:

    CSV log 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"
    

    Copyright © 1998-2011 Caucho Technology, Inc. All rights reserved.
    Resin ® is a registered trademark, and Quercustm, Ambertm, and Hessiantm are trademarks of Caucho Technology.