Skip to content

TracLogging

Ricardo Ferraz Leal edited this page Mar 31, 2019 · 13 revisions

<html><body><h1 id="TracLogging">Trac Logging</h1>

<div class="wiki-toc"><h4>Table of Contents</h4>

</div>

Trac supports logging of system messages using the standard <span class="icon">​</span>logging module that comes with Python.

Logging is configured in the <tt>[logging]</tt> section in trac.ini .

<h2 id="SupportedLoggingMethods">Supported Logging Methods</h2>

The log method is set using the <tt>log_type</tt> option in trac.ini , which takes any of the following values:

<dl class="wiki"><dt> **none ** </dt><dd>Suppress all log messages. </dd><dt> file </dt><dd>Log messages to a file, specified with the <tt>log_file</tt> option in trac.ini . Relative paths in <tt>log_file</tt> are resolved relative to the <tt>log</tt> directory of the environment. </dd><dt> stderr </dt><dd>Output all log entries to console ( tracd only). </dd><dt> syslog </dt><dd>(UNIX) Send all log messages to the local syslogd via named pipe <tt>/dev/log</tt>. By default, syslog will write them to the file /var/log/messages. </dd><dt> eventlog </dt><dd>(Windows) Use the system's NT Event Log for Trac logging. </dd></dl> <h2 id="LogLevels">Log Levels</h2>

The verbosity level of logged messages can be set using the <tt>log_level</tt> option in trac.ini . The log level defines the minimum level of urgency required for a message to be logged, and those levels are:

<dl class="wiki"><dt> CRITICAL </dt><dd>Log only the most critical (typically fatal) errors. </dd><dt> ERROR </dt><dd>Log failures, bugs and errors. </dd><dt> WARN </dt><dd>Log warnings, non-interrupting events. </dd><dt> INFO </dt><dd>Diagnostic information, log information about all processing. </dd><dt> DEBUG </dt><dd>Trace messages, profiling, etc. </dd></dl>

Note that starting with Trac 0.11.5 you can in addition enable logging of SQL statements, at debug level. This is turned off by default, as it's very verbose (set <tt>[trac] debug_sql = yes</tt> in TracIni to activate).

<h2 id="LogFormat">Log Format</h2>

Starting with Trac 0.10.4 (see <span class="icon">​</span>#2844 ), it is possible to set the output format for log entries. This can be done through the <tt>log_format</tt> option in trac.ini . The format is a string which can contain any of the <span class="icon">​</span>Python logging Formatter variables . Additonally, the following Trac-specific variables can be used: <dl class="wiki"><dt> $(basename)s </dt><dd>The last path component of the current environment. </dd><dt> $(path)s </dt><dd>The absolute path for the current environment. </dd><dt> $(project)s </dt><dd>The originating project's name.

</dd></dl>

Note that variables are identified using a dollar sign (<tt>$(...)s</tt>) instead of percent sign (<tt>%(...)s</tt>).

The default format is:

log_format = Trac[$(module)s] $(levelname)s: $(message)s

In a multi-project environment where all logs are sent to the same place (e.g. <tt>syslog</tt>), it makes sense to add the project name. In this example we use <tt>basename</tt> since that can generally be used to identify a project:

log_format = Trac[$(basename)s:$(module)s] $(levelname)s: $(message)s

<hr />

See also: TracIni , TracGuide , TracEnvironment

</body></html>

Clone this wiki locally