This page last changed on Sep 24, 2012 by dberenguer.

Hy guys!

I now want to log some activity by means of the logging capabilities provided by OpenRemote Controller, so I'm adding this into our LagartoCommandBuilder class:

public final static String LAGARTO_PROTOCOL_LOG_CATEGORY = Constants.CONTROLLER_PROTOCOL_LOG_CATEGORY + "LAGARTO";
private final static Logger logger = Logger.getLogger(LAGARTO_PROTOCOL_LOG_CATEGORY);

I've also added this line to build.xml:
<mkdir dir = "$build.dir/testcontainer/logs/lagarto/">
(had to remove the brackets to make the text appear)

where the rest of protocols do the same. Then, whenever I want to log something I do:

logger.debug("My log");

or

logger.error("my error");

However the "lagarto" folder is not created under output/OpenRemote/logs/ and hence no log is created.

Thanks in advance for your suggestions.

Daniel.

> svn mkdir runtime/apache-tomcat-6.0.18/logs/lagarto
> svn commit -m "I like to commit often because that helps others review my code" \
  runtime/apache-tomcat-6.0.18/logs/lagarto
Posted by juha at Sep 24, 2012 23:59

Thanks Juha,

I've created the new folder under runtime/apache-tomcat-6.0.18/logs/ but no logs are being created. I think I still have to tell Controller where to store the logs for lagarto.

BTW, the sources have been committed to SVN.

Posted by dberenguer at Sep 25, 2012 12:07

Yes, log output is configured in /web/WEB-INF/classes/log4j.properties

You can look at the file for examples. Two relevant entries are:

1-wire logging (single file logs)

# ---------------------------------------------------------------------------------------------
#
#  1-WIRE LOGGING
#
#  Direct 1-wire related logging to its own category. Currently 1-wire logging is all directed
#  into a single file. Set threshold (INFO, DEBUG, or other) accordingly.
#
# ---------------------------------------------------------------------------------------------


# Enable all of 1-wire logging -- file log appenders may threshold which records they
# want to include
log4j.logger.OpenRemote.Controller.protocol.onewire = ALL, onewire-file



# ---- 1-WIRE FILE LOG -------------------------------------------------------------------------------

# Log file will roll over (delete) old entries once maximum number of backup files
# is reached (each file size is defined with MaxFileSize property)
log4j.appender.onewire-file = org.apache.log4j.RollingFileAppender

# Location of the log file
log4j.appender.onewire-file.File = ../logs/onewire/onewire.log

# Only log INFO or above. If you want more detailed log, set threshold to DEBUG. If you want
# less detailed log, set threshold to WARN
log4j.appender.onewire-file.Threshold = INFO

# Maximum size of the log file
log4j.appender.onewire-file.MaxFileSize = 500KB

# Keep at most one backup file until older entries are deleted and written over.
log4j.appender.onewire-file.MaxBackupIndex = 1

# Formatting of log records -- print priority (level) %p, date/time %d and message %m
log4j.appender.onewire-file.layout = org.apache.log4j.PatternLayout
log4j.appender.onewire-file.layout.ConversionPattern = %p %d (1-WIRE): %m%n

You are free to create more detailed setups, for example, KNX logging separates debug and trace level logging to a separate file from general info/warning/error logs:

# ---------------------------------------------------------------------------------------------
#
#  KNX LOGGING
#
#  Direct KNX related logging to their own category. KNX logging is separated to the usual
#  operational log that records some specific KNX related events and a detailed KNX debug
#  log that records a lot of detailed information about the KNX stack.
#
#  The debug log is by default set to low file size values with the assumption that the debug
#  log is not required under normal circumstances (and it can be very chatty). If you do need
#  to analyze the debug log, you are likely to need to increase the log sizes first to retrieve
#  sufficient information over a longer period of time.
#
#  Note on performance : debug log does have an impact on performance, however under usual
#  circumstances this is not an issue. However, if you are sending hundreds of KNX frames per
#  second and need to optimize performance, turning off the knx debug logging or all of the
#  KNX logging altogether may help with performance optimization.
#
# ---------------------------------------------------------------------------------------------


# Enable all of KNX logging -- file log appenders may threshold which records they
# want to include
log4j.logger.OpenRemote.Controller.protocol.knx = ALL, knx-file, knx-debug-file


# ---- KNX FILE LOG -------------------------------------------------------------------------------

# Log file will roll over (delete) old entries once maximum number of backup files
# is reached (each file size is defined with MaxFileSize property)
log4j.appender.knx-file = org.apache.log4j.RollingFileAppender

# Location of the log file
log4j.appender.knx-file.File = ../logs/knx/knx.log

# Only log INFO or above. Detailed debug messages are in a separate debug log file
log4j.appender.knx-file.Threshold = INFO

# Maximum size of the log file
log4j.appender.knx-file.MaxFileSize = 500KB

# Keep at most one backup file until older entries are deleted and written over.
log4j.appender.knx-file.MaxBackupIndex = 1

# Formatting of log records -- print priority (level) %p, date/time %d and message %m
log4j.appender.knx-file.layout = org.apache.log4j.PatternLayout
log4j.appender.knx-file.layout.ConversionPattern = %p %d (KNX): %m%n


# ---- KNX DEBUG LOG ------------------------------------------------------------------------------

# Log file will roll over (delete) old entries once  maximum number of backup files
# is reached (each file size is defined with MaxFileSize property). Both the size and
# number of backups is set rather low for debug logging by default (see values below).
# If you're tracking down an issue with the KNX implementation, you will want to increase
# these values.
log4j.appender.knx-debug-file = org.apache.log4j.RollingFileAppender

# Location of the log file
log4j.appender.knx-debug-file.File = ../logs/knx/knx-debug.log

# Logs *everything* related to KNX. Can be *very* chatty.
log4j.appender.knx-debug-file.Threshold = ALL

# Maximum size of the log file -- by default this is relatively low compared to the amount
# of logging that may occur at debug level. If you're debugging an issue, you will want to
# increase this file size limit and add a number of backup log files (see below) to ensure
# older log files are not deleted and written over.
log4j.appender.knx-debug-file.MaxFileSize = 100KB

# By default, do not keep backup logs. This means that as soon as the max file size is reached
# on the debug log, it is deleted and new empty log is created to replace it.
#
# If you're debugging an issue, you will want to increase both the file size and the number of
# backup files as the debug logging can be *very* noisy.
log4j.appender.knx-debug-file.MaxBackupIndex = 0

# Formatting of log records -- print priority (level) %p, date/time %d and message %m
log4j.appender.knx-debug-file.layout = org.apache.log4j.PatternLayout
log4j.appender.knx-debug-file.layout.ConversionPattern = %p %d (KNX): %m%n

Posted by admin at Sep 25, 2012 19:59

Thanks for the information!

Can logs be disabled in some way? I'd be interested in logging only under debug circumstances. Then, I'd prefer to disable logs in order to reduce flash writes.

EDIT:
Sorry, I'm now thinking that maybe there is no way to do this from Controller. We should then manage logs from the protocol itself.

Posted by dberenguer at Sep 26, 2012 12:41

In the above example for 1-wire:

# DISABLE all of 1-wire logging 
log4j.logger.OpenRemote.Controller.protocol.onewire = OFF, onewire-file

You're correct the logging is not exposed to the user in any way currently. There should be either an user interface in the controller or designer (or both depending on the use case: remotely managed controller instance or user managed controller instance) or there could be a protocol that manages its own logging levels programmatically.

Posted by juha at Sep 27, 2012 01:28

Thanks Juha, I've added the following section to log4j.properties:

# ---------------------------------------------------------------------------------------------
#
#  PANSTAMP LAGARTO LOGGING
#
#  Direct lagarto related logging to its own category. Currently lagarto logging is all directed
#  into a single file. Set threshold (INFO, DEBUG, or other) accordingly.
#
# ---------------------------------------------------------------------------------------------


# Enable all of lagarto logging -- file log appenders may threshold which records they
# want to include
log4j.logger.OpenRemote.Controller.protocol.lagarto = ALL, lagarto-file


# ---- LAGARTO FILE LOG -------------------------------------------------------------------------------

# Log file will roll over (delete) old entries once maximum number of backup files
# is reached (each file size is defined with MaxFileSize property)
log4j.appender.lagarto-file = org.apache.log4j.RollingFileAppender

# Location of the log file
log4j.appender.lagarto-file.File = ../logs/lagarto/lagarto.log

# Only log INFO or above. If you want more detailed log, set threshold to DEBUG. If you want
# less detailed log, set threshold to WARN
log4j.appender.lagarto-file.Threshold = INFO

# Maximum size of the log file
log4j.appender.lagarto-file.MaxFileSize = 500KB

# Keep at most one backup file until older entries are deleted and written over.
log4j.appender.lagarto-file.MaxBackupIndex = 1

# Formatting of log records -- print priority (level) %p, date/time %d and message %m
log4j.appender.lagarto-file.layout = org.apache.log4j.PatternLayout
log4j.appender.lagarto-file.layout.ConversionPattern = %p %d (LAGARTO): %m%n

But still no log file is created under logs/lagarto/

I'm now thinking that the problem may be in how LagartoCommandBuilder is loading the log stuff:

public final static String LAGARTO_PROTOCOL_LOG_CATEGORY = Constants.CONTROLLER_PROTOCOL_LOG_CATEGORY + "LAGARTO";
private final static Logger logger = Logger.getLogger(LAGARTO_PROTOCOL_LOG_CATEGORY);

I know I'm closer to the solution Thanks for your patience.

Posted by dberenguer at Sep 27, 2012 11:20

Maybe it's case sensitive?

See what happens if you change:

public final static String LAGARTO_PROTOCOL_LOG_CATEGORY = 
    Constants.CONTROLLER_PROTOCOL_LOG_CATEGORY + "LAGARTO";

To:

public final static String LAGARTO_PROTOCOL_LOG_CATEGORY = 
    Constants.CONTROLLER_PROTOCOL_LOG_CATEGORY + "lagarto";
Posted by juha at Sep 27, 2012 16:07

Same result, no log file created. I think I'm skipping something...

Posted by dberenguer at Sep 27, 2012 17:15

OK, found the problem.

The issue is that I was trying to log DEBUG information whilst
log4j.appender.lagarto-file.Threshold = INFO

Posted by dberenguer at Oct 05, 2012 16:48

Thanks for updating the forums too

Posted by juha at Oct 05, 2012 16:53
Document generated by Confluence on Jun 05, 2016 09:31