log4cpp: Logging Events and Priorities
The most important aspect of a log message is its priority. Take a simple scenario, when you are debugging your program, you want to display all the logs in your program. At that moment, you are not concerned about the resource crunch and performance impact. But when your program is running, you do not want to print the debug statements and only print statements which are critical errors. So every message must have a priority and depending on the value and the scenario, it is decided whether a message must be logged or not.
log4cpp supports the following priorities in the descending order of their priority
- EMERG, FATAL
- ALERT
- CRIT
- ERROR
- WARN
- NOTICE
- INFO
- DEBUG
- NOTSET (no priority set)
All these priorities are defined in the class log4cpp::Priority. You can print the string equivalent of these priorities (useful when you want to make your own log4cpp layout) using the function
const std::string & log4cpp::Priority::getPriorityName(int priority)
where priority can be any of the above values: log4cpp::Priority::EMERG, log4cpp::Priority::FATAL.
Apart from the priority, a message will be meaningful if we are aware of information like nested diagnostic context, which refers to the function or the thread executing the instance.
When we log a message, it is called a logging event. So considering all the above information, we can summarize that every logging event must have the following information associated with it.
- Category
- Priority
- The message itself
- NDC (nested diagnostic context)
log4cpp::LoggingEvent is used for the internal purposes, but we will find it useful to create our own layout.
Comments: