Abstract class receiving log requests from log areas.
class LogChannel
more...
Summary
format() | Gets or set the log message formatting setting. |
level() | Gets or set the log level. |
Detailed description
class LogChannel
Abstract class receiving log requests from log areas.
This class cannot directly instantiated. Calling it directlty will generate a code error.
Methods
Gets or set the log message formatting setting.
LogChannel.format( [format] )
format | the new format to set (a string). |
Returns: | The current log message format (a string). |
The message format is a template string filled with informations from the logging system. Some loggin subsystems (as the MS-Windows Event Logger, or as the Posix SYSLOG system) fill autonomously informations on behalf of the application, while others (file and stream based loggers) require a format to print meaningful informations as the timestamp.
The format string can contain the following escape codes:
- %a: Application area requesting the log (name of the LogArea).
- %c: Numeric code as passed in the "code" optional parameter.
- %C: Numeric code as passed in the "code" optional parameter, zero padded to 5 digits.
- %d: date in YYYY-MM-DD format.
- %f: Function calling the log request.
- %l: Log level as a numeric integer.
- %L: Letter representing the log level (one character).
- %M: Name of the module requesting the log.
- %m: Log message.
- %R: date in RFC2822 format (as "Sun, 06 Sep 2009 18:16:20 +0200")
- %s: Milliseconds since the start of the program in seconds and fractions.
- %S: Milliseconds since the start of the program (absolute).
- %t: timestamp in HH:MM:SS.mmm format.
- %T: timestamp in YYYY-MM-DD HH:MM:SS.mmm format.
- %%: The "%" character.
For example, the pattern "%t\t%L (%M)\t%m" will print something like
13:22:18.344 D (testbind) Debug message from testbind.
The module also provides some standard log format code that can be useful in the most common situations as constants defined at toplevel. They are the following:
- LOGFMT_TRACE: "[%s %M.%f]\t%m" -- this is useful for logs meant to trace application progress and perform debug sessions. It indicates how many seconds and fractions have passed and the function calling sending the log message.
- LOGFMT_ERROR: "%T\t%L%C\t[%a]\t%m" -- this format indicates the complete date and time at which an error took place, the error level and code (padded to 5 digits), the area that generated this error and the message.
- LOGFMT_ERRORP: "%T\t%L%C\t[%a:%M.%f]\t%m" -- This format is the same as LOGFMT_ERROR, but it adds the name of the module and function that generated the log to the area description.
- LOGFMT_ERRORT: "%T\t%L%C\t[%M.%f]\t%m" -- This format is the same as LOGFMT_ERRORP, but it doesn't report the log area generating the log. Useful if you know that you will be using the general area only.
- LOGFMT_ENTRY: "%T\t(%L) %m" -- Simpler format, reporting the day and time in which a log entry is generated, the log level and the message.
- LOGFMT_ENTRYP: "%T\t(%L) [%a]%m" -- Like LOGFMT_ENTRY, but reporting also the log area.
Gets or set the log level.
LogChannel.level( [level] )
level | a new log level to be set. |
Returns: | The current log level. |