Logging

From OpenSimulator

(Difference between revisions)
Jump to: navigation, search
(Changing logging levels before startup)
(Adding information about rolling log-files)
Line 52: Line 52:
  
 
You can also see from the OpenSim.exe.config file that log files are written to OpenSim.log (as well as the console).
 
You can also see from the OpenSim.exe.config file that log files are written to OpenSim.log (as well as the console).
 +
 +
=== Rolling file appender and maximum log-file size ===
 +
 +
Log4net provides several log-file appenders. One of them is the ''RollingFileAppender'', which limits log-file size and rotates log-files automatically. To use this appender, add the following section to the log4net-configuration:
 +
 +
<appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
 +
  <file value="OpenSim.log" />
 +
  <appendToFile value="true" />
 +
  <maximumFileSize value="1000KB" />
 +
  <maxSizeRollBackups value="2" />
 +
  <layout type="log4net.Layout.PatternLayout">
 +
    <conversionPattern value="%date %-5level - %logger %message%newline" />
 +
  </layout>
 +
</appender>
 +
 +
The maximum size can be set in the ''maximumFileSize'' element, the ''maxSizeRollBackups'' element determines the maximum number of rolling log-files. So, the setting above will create a log-file named ''OpenSim.log'' with a maximum size of 1000KB. When the limit is reached, ''OpenSim.log'' will be renamed to ''OpenSim.log.1'', and a fresh ''OpenSim.log'' is started (possibly after renaming ''OpenSim.log.1'' to ''OpenSim.log.2'', should that file exist already).
 +
 +
To use the appender defined above, replace the line
 +
  <appender-ref ref="LogFileAppender" />
 +
by
 +
  <appender-ref ref="RollingFileAppender" />
 +
 +
Further information about configuration of log4net can be found on the [http://logging.apache.org/log4net/release/manual/configuration.html Log4Net configuration page].
  
 
== Setting log levels during runtime ==
 
== Setting log levels during runtime ==

Revision as of 21:56, 20 August 2008

Changing logging levels before startup

OpenSim uses the log4net package for logging. This means that every executable you run for OpenSim has an accompanying .config file which contains the logging configuration

For instance, the OpenSim.exe.config file looks like this.

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
 <configSections>
   <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" />
 </configSections>
 <appSettings>
 </appSettings>
 <log4net>
   <appender name="Console" type="OpenSim.Framework.Console.OpenSimAppender, OpenSim.Framework.Console">
     <layout type="log4net.Layout.PatternLayout">
       <conversionPattern value="%date{HH:mm:ss} - %message%newline" />
     </layout>
   </appender>
   <appender name="LogFileAppender" type="log4net.Appender.FileAppender">
     <file value="OpenSim.log" />
     <appendToFile value="true" />
     <layout type="log4net.Layout.PatternLayout">
       <conversionPattern value="%date %-5level - %logger %message%newline" />
     </layout>
   </appender>
   <logger name="NHibernate" additivity="false">
     <level value="INFO"/>
     <appender-ref ref="NHibernateFileLog"/>
   </logger>
   <root>
     <level value="DEBUG" />
     <appender-ref ref="Console" />
     <appender-ref ref="LogFileAppender" />
   </root>
 </log4net>
</configuration>

This looks rather complicated, but if you want to change the level of messages logged, then you could change the value in the <root> section (right at the end) which is

<level value="DEBUG" />

in the example above to something different, e.g.

<level value="WARN" />

which will only display warning and error level log messages. Permissible values are ALL, DEBUG, INFO, WARN, ERROR, FATAL, OFF

You can also see from the OpenSim.exe.config file that log files are written to OpenSim.log (as well as the console).

Rolling file appender and maximum log-file size

Log4net provides several log-file appenders. One of them is the RollingFileAppender, which limits log-file size and rotates log-files automatically. To use this appender, add the following section to the log4net-configuration:

<appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
  <file value="OpenSim.log" />
  <appendToFile value="true" />
  <maximumFileSize value="1000KB" />
  <maxSizeRollBackups value="2" />
  <layout type="log4net.Layout.PatternLayout">
    <conversionPattern value="%date %-5level - %logger %message%newline" />
  </layout>
</appender>

The maximum size can be set in the maximumFileSize element, the maxSizeRollBackups element determines the maximum number of rolling log-files. So, the setting above will create a log-file named OpenSim.log with a maximum size of 1000KB. When the limit is reached, OpenSim.log will be renamed to OpenSim.log.1, and a fresh OpenSim.log is started (possibly after renaming OpenSim.log.1 to OpenSim.log.2, should that file exist already).

To use the appender defined above, replace the line

 <appender-ref ref="LogFileAppender" />

by

 <appender-ref ref="RollingFileAppender" />

Further information about configuration of log4net can be found on the Log4Net configuration page.

Setting log levels during runtime

It isn't currently possible to change the level of logging to the log file during runtime. However, it is possible to change the level sent to the console. You can do this by executing the

set log level [<level>]

command. For example

set log level error

will mean only errors are sent to the console. The log still receives messages that meet the level set in the OpenSim.exe.config file at startup.

Not specifying any level will tell you what the current console logging level is.

Changes to the log level sent to the console will not persist over restarts. If you want the change to be permanent, you can set a threshold value in the ConsoleAppender in a config file such as OpenSim.exe.config (see the log4net docs for more details).

Personal tools
General
About This Wiki