g3log/API.markdown
2015-10-10 14:50:24 -06:00

2.4 KiB

API description

Most of the API that you need for using g3log is described in this readme. For more API documentation and examples please continue to read the API readme. Examples of what you will find here are:

  • Logging API: LOG calls
  • Contract API: CHECK calls
  • Logging levels
    • disable/enabled levels at runtime
    • custom logging levels
  • Sink creation and utilization
  • Fatal handling
    • custom fatal handling
    • pre fatal hook
    • override of signal handling
    • disable fatal handling
  • LOG calls
  • CHECK calls

Logging API: LOG calls

It is optional to use either streaming LOG(INFO) << some text or printf-like syntax LOGF(WARNING, "some number %d", 123);

Conditional logging is made with LOG_IF(INFO, <boolean-expression>) << " some text" or LOGF_IF(WARNING, <boolean-expression>) << " some text". Only if the expressions evaluates to true will the logging take place.

Example: LOG_IF(INFO, 1 = 200) << " some text"; or LOG_IF(FATAL, SomeFunctionCall()) << " some text";

A call using FATAL logging level, such as the LOG_IF(FATAL,...) example above, will after logging the message at FATALlevel also kill the process. It is essentially the same as a CHECK(<boolea-expression>) << ... with the difference that the CHECK(<boolean-expression) triggers when the expression evaluates to false.

Contract API: CHECK calls

The contract API follows closely the logging API with CHECK(<boolean-expression>) << ... for streaming or CHECK_F(<boolean-expression>, ...); for printf-style.

If the <boolean-expression> evaluates to false then the the message for the failed contract will be logged in FIFO order with previously made messages. The process will then shut down after the message is sent to the sinks and the sinks have dealt with the fatal contract message.

Logging levels ```

The default logging levels are DEBUG, INFO, WARNING and FATAL (see FATAL usage above)

disable/enabled levels at runtime

custom logging levelsFATAL (see FATAL usage above)

Sink creation and utilization

Fatal handling

custom fatal handling

pre fatal hook

override of signal handlingboolean-expression>

disable fatal handling