The logging system provides a very basic mechanism to write messages to different types of streams. It is used by all the error and debug reporting facilities in Error Handling and Debugging, and therefore aims to be as robust as possible. If any error occurs during one of the logger functions, an error will be printed to stderr. If a logger is unsuccessful at writing the log message to the log stream then it will log the message to stdout. Also see Initialization, Finalization and Logging.
s_logger_file_new | Create a new file stream logger. |
s_logger_console_new | Create a new console stream logger. |
s_logger_null_new | Create a new null logger. |
s_logger_write | Format and write the given logging event information to the logger. |
s_logger_vwrite | Format and write the given logging event information to the logger (called with va_list). |
s_logger_destroy | Destroy the given logger’s associated resources. |
s_log_event_str | Get a string representation of the given log event level. |
The s_logger structure definition.
The logger consists of private data which can be anything required by the specific implementation, as it is only defined as an opaque type. The different logger implementations must implement the function pointers as described. If any error occurs during one of the logger functions, the logger must try and continue and print the error to stderr.
Three loggers are provided, one logging to file, one to a console and a null logger. The loggers must be freed by first calling s_logger_destroy() to free any private data of the logger, and then a call to S_FREE to free the logger itself.
Create a new file stream logger.
The logging message will be in the standard layout format.
Parameters: |
|
---|---|
Return: | Pointer to newly created file stream logger, or NULL on error. |
Note: | Only thread safe if compiled with threading library, and whether the standard ISO C vfprintf() function is thread-safe, see Threads Abstraction. |
See also: | File Stream, Standard |
Create a new console stream logger.
The logging message will be in the standard layout format.
Parameters: |
|
---|---|
Return: | Pointer to newly created console stream logger, or NULL on error. |
Note: | Only thread safe if compiled with threading library, and whether the standard ISO C vfprintf() function is thread-safe, see Threads Abstraction. |
See also: | Console Stream, Standard |
Create a new null logger.
A null logger does not log any messages.
Return: | Pointer to newly created null logger, or NULL on error. |
---|---|
Note: | The null logger must be destroyed (s_logger_destroy) and freed in the same manner as the other loggers. |
The standard layout for the file and console loggers define the format of the printed messages. There are two different formats, one for error messages and one for debugging/warning messages.
The error messages layout is as follows:
Date & Time [Logging event level1 (Error message2) Thread id3] User message (in function ‘Function name4‘, File name4, File line number4)
For example, the following will be printed with all the above information available:
Wed 18 May 2011 11:58:41 SAST [ERROR (Memory error) 10] Failed to allocate object memory (in function 'func', /home/nobody/test.c, 121)
The debugging/warning messages layout is as follows:
Date & Time [Debugging/warning message type1 Thread id2] User message
For example, the following will be printed with all the above information available:
Wed 18 May 2011 11:58:41 SAST [TRACE 10] value = 20.321
Format and write the given logging event information to the logger.
Parameters: |
|
---|---|
Return: | Error code. |
Format and write the given logging event information to the logger (called with va_list).
Equivalent to the s_logger_write except that it is called with a va_list instead of a variable number of arguments, same as the standard function vprintf().
Parameters: |
|
---|---|
Return: | Error code. |
Destroy the given logger’s associated resources.
The logger must still be free’d with S_FREE after this call.
Parameters: |
|
---|---|
Return: | error Error code. |
Note: | Thread-safety is dependent on the underlying implementation. |
Logging event definitions. The log events defines the type of information that will be output to the log.
Logging event level defintions.
Follows log4j Log levels (http://en.wikipedia.org/wiki/Log4j).
Values:
Reserved. Not to be used.
Severe errors that cause premature termination. [FATAL] in layout.
Other run time errors or unexpected conditions. [ERROR] in layout.
Undesirable/unexpected run time situations, but not necessarily “wrong”. [WARN] in layout.
Interesting run time events (start up/shutdown). [INFO] in layout.
Detailed information on the flow through the system. [DEBUG] in layout.
More detailed information. [TRACE] in layout.
Get a string representation of the given log event level.
Parameters: |
|
---|---|
Return: | Pointer to string representation of given log event level. If the error code is unknown then “UNKNOWN EVENT” is returned. |
Note: | Caller is responsible for returned character buffer’s memory. Thread-safe. |