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.


For examples, see:


PJ_LOG(level, arg)

Write log message. This is the main macro used to write text to the logging backend.


PJ_LOG(2, (__FILE__, "current value is %d", value));

  • 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.


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.

Param level:

Log level.

Param data:

Log message, which will be NULL terminated.

Param len:

Message length.


enum pj_log_decoration

Log decoration flag, to be specified with pj_log_set_decor().


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]


Include microseconds [yes]

enumerator PJ_LOG_HAS_SENDER

Include sender in the log [yes]


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]


Include level text string [no]


Include thread identification [no]


Add mark when thread has switched [yes]

enumerator PJ_LOG_HAS_INDENT

Indentation. Say yes! [yes]


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.

  • 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.

  • 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.


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.


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.


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.


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.


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.


Log decoration flag.

void pj_log_add_indent(int indent)

Add indentation to log message. Indentation will add PJ_LOG_INDENT_CHAR before the message, and is useful to show the depth of function calls.


indent – The indentation to add or substract. Positive value adds current indent, negative value subtracts current indent.

void pj_log_set_indent(int indent)

Set indentation to specific value.


indent – The indentation value.

int pj_log_get_indent(void)

Get current indentation value.


Current indentation value.

void pj_log_push_indent(void)

Push indentation to the right by default value (PJ_LOG_INDENT_SIZE).

void pj_log_pop_indent(void)

Pop indentation (to the left) by default value (PJ_LOG_INDENT_SIZE).

void pj_log_set_color(int level, pj_color_t color)

Set color of log messages.

  • 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.


level – Log level which color will be returned.


Log color.

pj_status_t pj_log_init(void)

Internal function to be called by pj_init()