Group PJ_LOG¶
-
group
PJ_LOG
The PJLIB logging facility is a configurable, flexible, and convenient way to write logging or trace information.
To write to the log, one uses construct like below:
In the above example, the number 3 controls the verbosity level of the information (which means “information”, by convention). The string “main.c” specifies the source or sender of the message.
Defines
-
PJ_LOG
(level, arg)¶ Write log message. This is the main macro used to write text to the logging backend.
Sample:
PJ_LOG(2, (__FILE__, "current value is %d", value));
- Parameters
level – The logging verbosity level. Lower number indicates higher importance, with level zero indicates fatal error. Only numeral argument is permitted (e.g. not variable).
arg – Enclosed ‘printf’ like arguments, with the first argument is the sender, the second argument is format string and the following arguments are variable number of arguments suitable for the format string.
Typedefs
-
typedef void
pj_log_func
(int level, const char *data, int len)¶ Signature for function to be registered to the logging subsystem to write the actual log message to some output device.
- Parameters
level – Log level.
data – Log message, which will be NULL terminated.
len – Message length.
Enums
-
enum
pj_log_decoration
¶ Log decoration flag, to be specified with pj_log_set_decor().
Values:
-
enumerator
PJ_LOG_HAS_DAY_NAME
¶ Include day name [default: no]
-
enumerator
PJ_LOG_HAS_YEAR
¶ Include year digit [no]
-
enumerator
PJ_LOG_HAS_MONTH
¶ Include month [no]
-
enumerator
PJ_LOG_HAS_DAY_OF_MON
¶ Include day of month [no]
-
enumerator
PJ_LOG_HAS_TIME
¶ Include time [yes]
-
enumerator
PJ_LOG_HAS_MICRO_SEC
¶ Include microseconds [yes]
-
enumerator
PJ_LOG_HAS_SENDER
¶ Include sender in the log [yes]
-
enumerator
PJ_LOG_HAS_NEWLINE
¶ Terminate each call with newline [yes]
-
enumerator
PJ_LOG_HAS_CR
¶ Include carriage return [no]
-
enumerator
PJ_LOG_HAS_SPACE
¶ Include two spaces before log [yes]
-
enumerator
PJ_LOG_HAS_COLOR
¶ Colorize logs [yes on win32]
-
enumerator
PJ_LOG_HAS_LEVEL_TEXT
¶ Include level text string [no]
-
enumerator
PJ_LOG_HAS_THREAD_ID
¶ Include thread identification [no]
-
enumerator
Functions
-
void
pj_log_write
(int level, const char *buffer, int len)¶ Default logging writer function used by front end logger function. This function will print the log message to stdout only. Application normally should NOT need to call this function, but rather use the PJ_LOG macro.
- Parameters
level – Log level.
buffer – Log message.
len – Message length.
-
void
pj_log
(const char *sender, int level, const char *format, va_list marker)¶ Write to log.
- Parameters
sender – Source of the message.
level – Verbosity level.
format – Format.
marker – Marker.
-
void
pj_log_set_log_func
(pj_log_func *func)¶ Change log output function. The front-end logging functions will call this function to write the actual message to the desired device. By default, the front-end functions use pj_log_write() to write the messages, unless it’s changed by calling this function.
- Parameters
func – The function that will be called to write the log messages to the desired device.
-
pj_log_func *
pj_log_get_log_func
(void)¶ Get the current log output function that is used to write log messages.
- Returns
Current log output function.
-
void
pj_log_set_level
(int level)¶ Set maximum log level. Application can call this function to set the desired level of verbosity of the logging messages. The bigger the value, the more verbose the logging messages will be printed. However, the maximum level of verbosity can not exceed compile time value of PJ_LOG_MAX_LEVEL.
- Parameters
level – The maximum level of verbosity of the logging messages (6=very detailed..1=error only, 0=disabled)
-
int
pj_log_get_level
(void)¶ Get current maximum log verbositylevel.
- Returns
Current log maximum level.
-
void
pj_log_set_decor
(unsigned decor)¶ Set log decoration. The log decoration flag controls what are printed to output device alongside the actual message. For example, application can specify that date/time information should be displayed with each log message.
- Parameters
decor – Bitmask combination of pj_log_decoration to control the layout of the log message.
-
unsigned
pj_log_get_decor
(void)¶ Get current log decoration flag.
- Returns
Log decoration flag.
-
void
pj_log_set_color
(int level, pj_color_t color)¶ Set color of log messages.
- Parameters
level – Log level which color will be changed.
color – Desired color.
-
pj_color_t
pj_log_get_color
(int level)¶ Get color of log messages.
- Parameters
level – Log level which color will be returned.
- Returns
Log color.
-
pj_status_t
pj_log_init
(void)¶ Internal function to be called by pj_init()
-