Logging Facility

Level

Usage

 

 

LOG_NOTICE

Conditions that are not error conditions, but that

 

may require special handling.

 

 

LOG_INFO

Informational messages.

 

 

LOG_DEBUG

Message that contain information normally of use

 

only when debugging a program.

 

 

To log a message, a handle to an instance of the Logger class is acquired and the "notify()" mem- ber function is called.

import netsvc

logger = netsvc.Logger() logger.notify(netsvc.LOG_DEBUG,"message")

The format of a message when displayed will be:

DEBUG: message

The string before the ":" corresponds to the level assigned to the message. The remainder of the line

after the ":" is the actual message. If you wish to have the time and process ID appear in the prefix, call the "enableLongFormat()" member function. Whether the longer form of prefix is enabled can be queried using the "longFormatEnabled()" member function. It can be disabled using the "disableLongFormat()" member function.

By default, messages will appear on the standard error output. If you wish to disable the display of mes- sages onto the standard error output, call the "disableStderrOutput()" member function. Con- versely, the "enableStderrOutput()" member function can be called to enable display of messages onto the standard error output if previously disabled. Whether messages are currently being displayed onto the standard error output can be queried by calling the member function "stder- rOutputEnabled()".

Specifying a Log File

At any time, messages can be captured into a single file by specifying the name of a log file using the member function "setLogFile()". If a log file is currently in use, the name of the log file can be queried using the "logFile()" member function.

logger.setLogFile("/var/tmp/application.log")

14

Page 14
Image 14
Python Python Manual, 7.0pl5 manual Specifying a Log File