g3log/API.markdown

63 lines
3.4 KiB
Markdown
Raw Normal View History

# 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](API.markdown). Examples of what you will find here are:
2015-10-10 14:50:24 -06:00
* Logging API: LOG calls
* Contract API: CHECK calls
* Logging levels
* disable/enabled levels at runtime
* custom logging levels
* Sink [creation](#sink_creation) and utilization
* Fatal handling
* custom fatal handling
* pre fatal hook
* override of signal handling
* disable fatal handling
* LOG calls
* CHECK calls
* Build Options
2015-10-10 14:50:24 -06:00
## 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 name="fatal_logging">A call using FATAL</a> logging level, such as the ```LOG_IF(FATAL,...)``` example above, will after logging the message at ```FATAL```level 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](#fatal_logging)).
For some windows framework there is a clash with the ```DEBUG``` logging level. One of the CMake [Build options](#build_options) can be used to then change offending default level from ```DEBUG``` TO ```DBUG```.
**CMake option: (default OFF) ** ```cmake -DCHANGE_G3LOG_DEBUG_TO_DBUG=ON ..```
2015-10-10 14:50:24 -06:00
### disable/enabled levels at runtime
Logging levels can be disabled at runtime. There is a cmake option to enable the dynamic enable/disable of levels.
When the option is enabled there will be a slight runtime overhead for each ```LOG``` call when the enable/disable status is checked. For most intent and purposes that runtime overhead is negligable.
There is **no** runtime overhead for checking if a level is enabled//disabled if the cmake option is turned off. If the dynamic logging cmake option is turned off then all logging levels are enabled.
**CMake option: (default OFF)** ```cmake -DUSE_DYNAMIC_LOGGING_LEVELS=ON ..```
2015-10-10 14:50:24 -06:00
### custom logging levels```FATAL``` (see FATAL usage above)
## Sink <a name="sink_creation">creation</a> and utilization
## Fatal handling
### custom fatal handling
### pre fatal hook
### override of signal handlingboolean-expression>
### disable fatal handling
## <a name="build_options">Build Options</a>
The build options are defined in the file [Options.cmake](Options.cmake)
2015-10-10 14:50:24 -06:00