Logging

From OpenSimulator

(Difference between revisions)
Jump to: navigation, search
(Added another example)
Line 1: Line 1:
 +
__NOTOC__
 +
{{Template:Quicklinks}}
 +
<br />
 +
 
== Changing logging levels before startup ==
 
== Changing logging levels before startup ==
  

Revision as of 14:34, 21 May 2009


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.

More specialized requirements

As an example, similar to Mantis#2603, if you want logging the XEngine's DEBUG output into a separate file xengine.log, and let only the message with level INFO and higher appear on the console, you can do that by adding the following lines to your OpenSim.exe.config:

   <appender name="XengineLogFileAppender" type="log4net.Appender.FileAppender">
     <file value="xengine.log" />
     <appendToFile value="true" />
     <layout type="log4net.Layout.PatternLayout">
       <conversionPattern value="%date %-5level - %logger %message%newline" />
     </layout>
   </appender>
   <appender name="XengineConsole" type="OpenSim.Framework.Console.OpenSimAppender, OpenSim.Framework.Console">
     <layout type="log4net.Layout.PatternLayout">
       <conversionPattern value="%date{HH:mm:ss} - %message%newline" />
     </layout>
     <filter type="log4net.Filter.LevelRangeFilter">
       <levelMin value="INFO" />
       <levelMax value="FATAL" />
     </filter>
   </appender>
   <logger name="OpenSim.Region.ScriptEngine.XEngine.XEngine" additivity="false">
     <appender-ref ref="XengineLogFileAppender" />
     <appender-ref ref="XengineConsole" />
   </logger>

(if there is a shorter way to do it, please replace those lines above) ;-)

Or, as an easier example, if you want to have the normal logging, except for the HttpServers which you want only INFO messages for, you can add the following lines after the </root>-tag:

   <logger name="OpenSim.Framework.Servers.HttpServerLogWriter">
     <level value="INFO" />
   </logger>

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 as described above.

Personal tools
General
About This Wiki