KanoopCommonQt 2.1.1
Kanoop foundational Qt utility library
Loading...
Searching...
No Matches
logcategory.h
1/******************************************************************************************
2**
3** logcategory.h
4**
5** Provide categorized logging for use with the default Log object.
6**
7** Moved from my Tesseract Engineering repo to open-source
8**
9** Author: Stephen Punak
10** Created: Wed Oct 4 13:25:38 2023
11**
12******************************************************************************************/
13#ifndef LOGCATEGORY_H
14#define LOGCATEGORY_H
15
16#include <QString>
17#include "loggingtypes.h"
18#include <Kanoop/kanoopcommon.h>
19
20/**
21 * @brief Logging subsystem namespace.
22 */
23namespace Log
24{
25
26/**
27 * @brief A named logging category with an associated minimum log level.
28 *
29 * Categories allow fine-grained control over which log messages are emitted.
30 * Each category has a name and a level; messages logged below the category level
31 * are suppressed even if they would otherwise pass the global logger level.
32 */
33class KANOOP_EXPORT LogCategory
34{
35public:
36 /** @brief Default constructor — creates an invalid (unnamed) category at the default level. */
37 LogCategory() : _level(DefaultLogLevel) {}
38
39 /**
40 * @brief Construct a named category at the default log level.
41 * @param name Category name string
42 */
43 LogCategory(const QString& name) :
44 _name(name),
45 _level(DefaultLogLevel) {}
46
47 /**
48 * @brief Return the category name.
49 * @return Category name string
50 */
51 QString name() const { return _name; }
52
53 /**
54 * @brief Return the minimum log level for this category.
55 * @return Active LogLevel threshold for this category
56 */
57 LogLevel level() const { return _level; }
58
59 /**
60 * @brief Create a new category by appending a sub-name to this category's name.
61 * @param name Sub-name to append (separated by '.')
62 * @return New LogCategory with the combined name
63 */
64 LogCategory append(const QString& name);
65
66 /**
67 * @brief Create a new category by prepending a prefix to this category's name.
68 * @param name Prefix to prepend (separated by '.')
69 * @return New LogCategory with the combined name
70 */
71 LogCategory prepend(const QString& name);
72
73 /**
74 * @brief Extract the parent portion of a dotted category name.
75 * @param name Full dotted category name
76 * @return Parent name (everything before the last '.')
77 */
78 static QString parentName(const QString& name);
79
80 /**
81 * @brief Return the process-wide default log level used for new categories.
82 * @return Current default LogLevel
83 */
84 static LogLevel defaultLogLevel() { return DefaultLogLevel; }
85
86 /**
87 * @brief Set the process-wide default log level used for new categories.
88 * @param value New default LogLevel
89 */
90 static void setDefaultLogLevel(LogLevel value) { DefaultLogLevel = value; }
91
92 /**
93 * @brief Test whether this category has a non-empty name.
94 * @return true if the name is non-empty
95 */
96 bool isValid() const { return _name.length() != 0; }
97
98 /** @brief Process-wide default log level applied to newly created categories. */
100
101protected:
102 /** @brief Category name string. */
103 QString _name;
104 /** @brief Minimum log level threshold for this category. */
106};
107
108} // namespace Log
109
110#endif // LOGCATEGORY_H
A named logging category with an associated minimum log level.
Definition logcategory.h:34
LogCategory()
Default constructor — creates an invalid (unnamed) category at the default level.
Definition logcategory.h:37
QString _name
Category name string.
QString name() const
Return the category name.
Definition logcategory.h:51
LogCategory(const QString &name)
Construct a named category at the default log level.
Definition logcategory.h:43
static void setDefaultLogLevel(LogLevel value)
Set the process-wide default log level used for new categories.
Definition logcategory.h:90
LogLevel level() const
Return the minimum log level for this category.
Definition logcategory.h:57
LogCategory append(const QString &name)
Create a new category by appending a sub-name to this category's name.
static LogLevel defaultLogLevel()
Return the process-wide default log level used for new categories.
Definition logcategory.h:84
LogLevel _level
Minimum log level threshold for this category.
static QString parentName(const QString &name)
Extract the parent portion of a dotted category name.
bool isValid() const
Test whether this category has a non-empty name.
Definition logcategory.h:96
LogCategory prepend(const QString &name)
Create a new category by prepending a prefix to this category's name.
static LogLevel DefaultLogLevel
Process-wide default log level applied to newly created categories.
Definition logcategory.h:99
Logging subsystem providing categorized, level-filtered output.
Definition log.h:40
LogLevel
Severity levels for log messages, ordered from most to least critical.