Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

6. Logging in Tomcat 7 > Loggers, appenders, and layouts

Loggers, appenders, and layouts

There are some important components of logging which we use at the time of implementing the logging mechanism for applications. Each term has its individual importance in tracking the events of the application. Let's discuss each term individually to find out their usage:

  • Loggers: It can be defined as the logical name for the log file. This logical name is written in the application code. We can configure an independent logger for each application.
  • Appenders: The process of generating logs is handled by appenders. There are many types of appenders, such as FileAppender, ConsoleAppender, SocketAppender, and so on, which are available in log4j. The following are some examples of appenders for log4j:
    log4j.appender.CATALINA=org.apache.log4j.DailyRollingFileAppender
    log4j.appender.CATALINA.File=${catalina.base}/logs/catalina.out
    log4j.appender.CATALINA.Append=true
    log4j.appender.CATALINA.Encoding=UTF-8
    

    The previous four lines of appender define the DailyRollingFileAppender in log4j, where the filename is catalina.out. These logs will have UTF-8 encoding enabled.

    Note

    If log4j.appender.CATALINA.append=false, then logs will not get updated in the log files.

    # Roll-over the log once per day
    log4j.appender.CATALINA.DatePattern='.'dd-MM-yyyy'.log'
    log4j.appender.CATALINA.layout = org.apache.log4j.PatternLayout
    log4j.appender.CATALINA.layout.ConversionPattern = %d [%t] %-5p %c- %m%n
    

    The previous three lines of code show the roll-over of the log once per day.


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial