Logging
A note to upgrading customers
Midway through 2013.2, logging in ScormEngine changed, and is still in the
process of changing. Your old logging configuration settings in your
ScormEngineSettings file will no longer have any effect; they have been
replaced by platform specific configuration files (see below). In addition,
use of the LogDetail
, LogAudit
, and LogError
configuration methods are officially deprecated. The overrides will still
function in 2014.1, but they will be removed by the next major release of SCORM
Engine.
You are in no way compelled to use our logging framework for your own logging messages (e.g., in your integration layer), but you can use it if you want to. Example code will be given for each platform.
.NET
In .NET Scorm Engine, logging is handled exclusively through log4net, an open-source logging library bundled with SCORM Engine. A sensible default configuration for log4net is provided in our web.config templates, but this configuration can be edited or replaced at will. If the configuration is missing, SCORM Engine will still run, but nothing will be logged.
If you are not using our web.config templates and you wish to use log4net, you
will need to add a few modifiecations to your web.config file. First, if you do
not have a configSections
tag already, you will need to add it as a
child of the root configuration
element. Then, under the
configSections
tag, you will need to add:
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,Log4net"/>
In addition, you will need to add a log4net
element as a child of
the root element. You can copy the example from our templates, or you can
consult the
log4net documentation.
The default log4net configuration included in our web.config templates will log only those messages with a log level of WARNING or higher. These messages will be written to a rolling log file under C:\\logs\scormengine-log.txt. They will also be written to the ASP.NET trace, with categories corresponding to their log level.
If you desire to use log4net for logging messages in your integration layer, you will need to add the following code:
- Add
using log4net;
to your integration layer's "using" declarations. - Declare a static logger variable in your integration layer, e.g.,
private static readonly ILog Logger = LogManager.GetLogger(typeof(MyIntegrationLayer))
. - At any point in your integration layer where you would like to add logging,
call the appropriate logging method (
Debug
,Info
,Warn
,Error
, orFatal
) to add a logging message at that level. The following example logs calls to RollupRegistration:Logger.Info("RollupRegistration called")
.
For more information on using log4net, consult the log4net documentation.
Java
In Java ScormEngine, most logging is handled primarily through SLF4J, an open-source interface to several other logging libraries.
SLF4J can be used in combination with many other logging frameworks. In order to enable a particular framework, you must download the appropriate SLF4J adapter from [the SLF4J project website](http://www.slf4j.org/download.html and place it in the classpath for your web application. That said, SCORM Engine already ships with logback, an open-source logging library, and its SLF4J adapter so that logging will work "right out of the box."
We also ship with a default logback configuration file, which is deployed when
the WAR is deployed. The file, logback.xml
, is located in the
WEB-INF/classes directory of your deployed application. That said, we do not
recommend you edit this configuration, lest your changes get overwritten when
you upgrade Engine. Instead, we recommend you take advantage of the fact that
logback.xml is logback's last choice for a configuration file. If you place a
logback.groovy or logback-test.xml file in your web application classpath,
logback will load that configuration instead. For more information on logback's
configuration file format, see the tutorial on the logback
project website.
There is unfortunately some legacy code that still uses the built-in
java.util.logging
library; these messages can be configured in
whichever way they are usually configured for your application (e.g., the
logging.properties
file for Tomcat). These logging usages are
scheduled for removal in the next major release of SCORM Engine.
If you desire to use SLF4J/logback for your own integration layer, you will need to add the following code:
- Add the following two import statements at the top of your integration
layer:
import org.slf4j.Logger;
, andimport org.slf4j.LoggerFactory;
. - Declare a static logger variable in your integration layer, e.g.,
private static final Logger _logger = LoggerFactory.getLogger("com.example.ExampleIntegration");
- At any point in your integration layer where you would like to add logging,
call the appropriate logging method (
trace
,debug
,info
,warn
, orerror
) to add a logging message at that level. The following example logs calls to RollupRegistration:_logger.info("RollupRegistration called")
.
For more information on using logback effectively, consult the logback manual.