KP-Lab logging

There are some ways to easily enable logging for kp-lab purposis. Basically this is done by adding a log4j.properties file to your web application. In the case the logging is done for a package which will lie inside Jetspeed web application, the logging configuration is added to a already existing logfile. See the KP-Lab Logging#JetspeedLogging for that.

Linux users can use tail to watch the log files. You can also view the log files directly from Eclipse

Sample file

Here is a stub file to use for the KP-Lab specific logging.


# KP-Lab Categories # # Default category log4j.category.org.kplab = ERROR, kplab log4j.additivity.org.kplab = false # KP-Lab admin category log4j.category.org.kplab.portlets = DEBUG, kplabadmin log4j.additivity.org.kplab.portlets = false # # KP-Lab Appenders # # Everything from org.kplab will go to kplab.log by default log4j.appender.kplab=org.apache.log4j.RollingFileAppender log4j.appender.kplab.File= /var/kplab/logs/kplab.log log4j.appender.kplab.MaxFileSize=5000KB log4j.appender.kplab.MaxBackupIndex=10 log4j.appender.kplab.layout=org.apache.log4j.PatternLayout log4j.appender.kplab.layout.ConversionPattern=%d %p [%c] - %m%n # KP-Lab admin appender log4j.appender.kplabadmin=org.apache.log4j.RollingFileAppender log4j.appender.kplabadmin.File= /var/kplab/logs/kplabadmin.log log4j.appender.kplabadmin.MaxFileSize=5000KB log4j.appender.kplabadmin.MaxBackupIndex=10 log4j.appender.kplabadmin.layout=org.apache.log4j.PatternLayout log4j.appender.kplabadmin.layout.ConversionPattern=%d %p [%c] - %m%n

This top part of this file are the "default" logger for all classes under org.kplab package and another logger for classes under org.kplab.portlets package. Below them are appenders for the loggers, which will do the actual writing into files (or console window or database). In other words, all the log messages will be stored into kplab.log file, except the ones coming from package org.kplab.portlets which will be saved into kplabadmin.log file. See creating a new logger for information how to create and configure a new logger.

Log files

All the log files will be stored under /var/kplab/logs.

Jetspeed logging

To log a jar package which will lie under Jetspeed application, you should use a existing configuration and extend and modify it to fit your needs. The file is located in the sources at ${kplab.project.home}/portal/src/webapp/WEB-INF/conf/Log4j.properties and in the running Tomcat at ${CATALINA_HOME}/webapps/jetspeed/WEB-INF/conf/Log4j.properties.

The whole file is not listed here, but this is the bottom part of the file where the KP-Lab specific configurations are.


# (Continuation from around line 155) # # KP-Lab Category # # Default category log4j.category.org.kplab = ERROR, kplab log4j.additivity.org.kplab = false # KBService log4j.category.org.kplab.evtek.knowledgebrowser = DEBUG, kbservice log4j.additivity.org.kplab.evtek.knowledgebrowser = false # Ajaxcontroller log4j.category.org.kplab.evtek.ajax = DEBUG, ajax log4j.additivity.org.kplab.evtek.ajax = false # # KP-Lab Appenders # # Everything from org.kplab will go to kplab.log by default log4j.appender.kplab=org.apache.log4j.RollingFileAppender log4j.appender.kplab.File= /var/kplab/logs/kplab.log log4j.appender.kplab.MaxFileSize=5000KB log4j.appender.kplab.MaxBackupIndex=10 log4j.appender.kplab.layout=org.apache.log4j.PatternLayout log4j.appender.kplab.layout.ConversionPattern=%d %p [%c] - %m%n # KnowledgeBroswer appender log4j.appender.kbservice=org.apache.log4j.RollingFileAppender log4j.appender.kbservice.File= /var/kplab/logs/kbservice.log log4j.appender.kbservice.MaxFileSize=5000KB log4j.appender.kbservice.MaxBackupIndex=10 log4j.appender.kbservice.layout=org.apache.log4j.PatternLayout log4j.appender.kbservice.layout.ConversionPattern=%d %p [%c] - %m%n # AjaxController appender log4j.appender.ajax=org.apache.log4j.RollingFileAppender log4j.appender.ajax.File= /var/kplab/logs/ajax.log log4j.appender.ajax.MaxFileSize=5000KB log4j.appender.ajax.MaxBackupIndex=10 log4j.appender.ajax.layout=org.apache.log4j.PatternLayout log4j.appender.ajax.layout.ConversionPattern=%d %p [%c] - %m%n

As you can see there is also the default logger setup, so that we will catch all the messages in any case, even if no specific logger is defined. In addition there are currently two more loggers configured, one to log events from KnowledgeKBrowser and one from AjaxController.

Creating a new logger

This should apply to both situations, whether you have a new component or a new application.

To add a new logger configuration, easiest way is to copy one of the existing category section and on appender section. Like these lines


# AjaxController appender log4j.appender.ajax=org.apache.log4j.RollingFileAppender log4j.appender.ajax.File= /var/kplab/logs/ajax.log log4j.appender.ajax.MaxFileSize=5000KB log4j.appender.ajax.MaxBackupIndex=10 log4j.appender.ajax.layout=org.apache.log4j.PatternLayout log4j.appender.ajax.layout.ConversionPattern=%d %p [%c] - %m%n

Then change the logged packages (the parts of the lines saying org.kplab.evtek.ajax) to match your packages.

Next change the appender, named here ajax, which you can find at the end of the category configuration and on every parameter name in the appender section. The name could come from the name of you package or jar file. Change also the log file to match the name of your appender.

If you like, you can change the logging level for your logger. It is the first value for the category parameter, in this case DEBUG. You can use any of the possible FATAL, ERROR, WARN, INFO, DEBUG or TRACE, where FATAL will give you least of the logging and TRACE will give you everything. Level ERROR is recommended for normally running applications. There are also special levels called ALL and OFF, which will turn the logging either to all or off. Note that it depends also of to which log level your application is logging, how much information is produced. If used properly, the amount should be as mentioned above.

Other parameters you leave as they are. By default it will use maximum file size of 5000KB and total of 10 backups. This means that the logs might eventually use space up to 50MB, so note that there is enough space for the files.

So, let's say that you have your classes under package org.kplab.evtek.mynewcomponent and you wish to have only ERROR level and above logging. In this case the lines might look something like this:


# My new component appender log4j.appender.mynewcomponent=org.apache.log4j.RollingFileAppender log4j.appender.mynewcomponent.File= /var/kplab/logs/mynewcomponent.log log4j.appender.mynewcomponent.MaxFileSize=5000KB log4j.appender.mynewcomponent.MaxBackupIndex=10 log4j.appender.mynewcomponent.layout=org.apache.log4j.PatternLayout log4j.appender.mynewcomponent.layout.ConversionPattern=%d %p [%c] - %m%n


Development Development Tools

  Page Info My Prefs Log in
This page (revision-11) last changed on 18:24 25-Mar-2017 by Mikko Wuokko.
 

Referenced by
...nobody

JSPWiki v2.4.102
[RSS]