KanoopCommonQt 2.1.1
Kanoop foundational Qt utility library
Loading...
Searching...
No Matches
loggingtypes.h
1/******************************************************************************************
2**
3** loggingtypes.h
4**
5** Moved from my Tesseract Engineering repo to open-source
6**
7** Author: Stephen Punak
8** Created: Tue Oct 3 09:44:40 2023
9**
10******************************************************************************************/
11#ifndef LOGGINGTYPES_H
12#define LOGGINGTYPES_H
13#include <Kanoop/kanoopcommon.h>
14
15/**
16 * @brief Logging subsystem namespace.
17 */
18namespace Log {
19
20/**
21 * @brief Severity levels for log messages, ordered from most to least critical.
22 *
23 * Mirrors the syslog severity levels. The active logger level acts as a threshold:
24 * messages with a value greater than the threshold are discarded.
25 */
27{
28 Emergency = 0, ///< System is unusable
29 Alert = 1, ///< Action must be taken immediately
30 Critical = 2, ///< Critical conditions
31 Error = 3, ///< Error conditions
32 Warning = 4, ///< Warning conditions
33 Notice = 5, ///< Normal but significant condition
34 Info = 6, ///< Informational messages
35 Debug = 7, ///< Debug-level messages
36};
37
38/**
39 * @brief Bitmask flags controlling where log output is sent.
40 */
42{
43 None = 0x00000000, ///< No output flags set
44 LineNumbers = 0x00000001, ///< Include source line numbers in output
45 Timestamp = 0x00000002, ///< Include timestamps in output
46 Level = 0x00000004, ///< Include severity level in output
47 Console = 0x00001000, ///< Write to stdout/stderr
48 File = 0x00002000, ///< Write to a log file
49 QDebug = 0x00004000, ///< Write via Qt's qDebug() mechanism
50 Syslog = 0x00008000, ///< Write to the system syslog
51
52 Standard = LineNumbers | Timestamp | Level | Console ///< Default output configuration
53};
54
55/**
56 * @brief Bidirectional map between LogLevel values and their string names.
57 */
59{
60public:
61 /** @brief Populate the map with all standard LogLevel name pairs. */
63 {
64 insert(Emergency, "Emergency");
65 insert(Alert, "Alert");
66 insert(Critical, "Critical");
67 insert(Error, "Error");
68 insert(Warning, "Warning");
69 insert(Notice, "Notice");
70 insert(Info, "Info");
71 insert(Debug, "Debug");
72 }
73};
74
75/**
76 * @brief Look up a LogLevel by its name string.
77 * @param levelName Name string (case-insensitive)
78 * @return Matching LogLevel, or Debug as default
79 */
80KANOOP_EXPORT LogLevel getLogLevel(const QString& levelName);
81
82/**
83 * @brief Return a list of all defined LogLevel values.
84 * @return List of LogLevel enum values
85 */
86KANOOP_EXPORT QList<LogLevel> getLogLevels();
87
88/**
89 * @brief Return the name string for a LogLevel value.
90 * @param level LogLevel to convert
91 * @return Name string, e.g. "Debug"
92 */
93KANOOP_EXPORT QString getLogLevelString(LogLevel level);
94
95} // namespace Log
96
97#endif // LOGGINGTYPES_H
A QMap subclass providing bidirectional enum-to-string lookups.
Bidirectional map between LogLevel values and their string names.
LogLevelToStringMap()
Populate the map with all standard LogLevel name pairs.
Logging subsystem providing categorized, level-filtered output.
Definition log.h:40
LogLevel
Severity levels for log messages, ordered from most to least critical.
@ Error
Error conditions.
@ Critical
Critical conditions.
@ Info
Informational messages.
@ Alert
Action must be taken immediately.
@ Warning
Warning conditions.
@ Debug
Debug-level messages.
@ Emergency
System is unusable.
@ Notice
Normal but significant condition.
KANOOP_EXPORT LogLevel getLogLevel(const QString &levelName)
Look up a LogLevel by its name string.
KANOOP_EXPORT QString getLogLevelString(LogLevel level)
Return the name string for a LogLevel value.
KANOOP_EXPORT QList< LogLevel > getLogLevels()
Return a list of all defined LogLevel values.
KANOOP_EXPORT LogLevel level()
Return the current minimum log level of the system logger.
OutputFlags
Bitmask flags controlling where log output is sent.
@ Console
Write to stdout/stderr.
@ Timestamp
Include timestamps in output.
@ None
No output flags set.
@ Level
Include severity level in output.
@ LineNumbers
Include source line numbers in output.
@ File
Write to a log file.
@ Syslog
Write to the system syslog.
@ QDebug
Write via Qt's qDebug() mechanism.
@ Standard
Default output configuration.