KanoopCommonQt 2.1.1
Kanoop foundational Qt utility library
Loading...
Searching...
No Matches
Log Namespace Reference

Logging subsystem providing categorized, level-filtered output. More...

Classes

class  LogCategory
 A named logging category with an associated minimum log level. More...
 
class  LogEntry
 Immutable record of a single log event. More...
 
class  Logger
 Core logger class supporting console, file, syslog, and consumer outputs. More...
 
class  LogLevelToStringMap
 Bidirectional map between LogLevel values and their string names. More...
 

Enumerations

enum  LogLevel {
  Emergency = 0 , Alert = 1 , Critical = 2 , Error = 3 ,
  Warning = 4 , Notice = 5 , Info = 6 , Debug = 7
}
 Severity levels for log messages, ordered from most to least critical. More...
 
enum  OutputFlags {
  None = 0x00000000 , LineNumbers = 0x00000001 , Timestamp = 0x00000002 , Level = 0x00000004 ,
  Console = 0x00001000 , File = 0x00002000 , QDebug = 0x00004000 , Syslog = 0x00008000 ,
  Standard = LineNumbers | Timestamp | Level | Console
}
 Bitmask flags controlling where log output is sent. More...
 

Functions

KANOOP_EXPORT void logText (const char *file, int lineNumber, LogLevel level, const QString &text)
 Write a text message via the system logger.
 
KANOOP_EXPORT void logText (const char *file, int lineNumber, LogLevel level, const LogCategory &category, const QString &text)
 Write a categorized text message via the system logger.
 
KANOOP_EXPORT void logHex (const char *file, int lineNumber, LogLevel level, const LogCategory &category, const QByteArray &data, const QString &tag=QString())
 Write a categorized hex dump via the system logger.
 
KANOOP_EXPORT void logHex (const char *file, int lineNumber, LogLevel level, const QByteArray &data, const QString &tag=QString())
 Write a hex dump via the system logger.
 
KANOOP_EXPORT LoggersystemLog ()
 Return the process-wide Logger singleton.
 
KANOOP_EXPORT LogLevel level ()
 Return the current minimum log level of the system logger.
 
KANOOP_EXPORT void setLevel (LogLevel value)
 Set the minimum log level of the system logger.
 
KANOOP_EXPORT OutputFlags flags ()
 Return the output flags of the system logger.
 
KANOOP_EXPORT void setFlags (OutputFlags flags)
 Set the output flags of the system logger.
 
KANOOP_EXPORT QString filename ()
 Return the log file path of the system logger.
 
KANOOP_EXPORT void setFilename (const QString &filename)
 Set the log file path of the system logger.
 
KANOOP_EXPORT QString identity ()
 Return the syslog identity of the system logger.
 
KANOOP_EXPORT void setIdentity (const QString &value)
 Set the syslog identity of the system logger.
 
KANOOP_EXPORT void enableOutputFlags (OutputFlags flags)
 Enable additional output flags on the system logger.
 
KANOOP_EXPORT void disableOutputFlags (OutputFlags flags)
 Disable specific output flags on the system logger.
 
KANOOP_EXPORT LogCategory registerCategory (const QString &name)
 Register a log category by name with the system logger.
 
KANOOP_EXPORT LogCategory registerCategory (const QString &name, LogLevel level)
 Register a log category by name and level with the system logger.
 
KANOOP_EXPORT QList< LogCategorycategories ()
 Return all categories registered with the system logger.
 
KANOOP_EXPORT void setCategoryLevel (const QString &name, LogLevel level)
 Override the log level for a named category on the system logger.
 
KANOOP_EXPORT void addConsumer (LogConsumer *consumer)
 Add an external log consumer to the system logger.
 
KANOOP_EXPORT void removeConsumer (LogConsumer *consumer)
 Remove an external log consumer from the system logger.
 
KANOOP_EXPORT LogLevel parseLevel (const QString &value, bool *parsed=nullptr)
 Parse a log level name string into a LogLevel enum value.
 
KANOOP_EXPORT QDateTime getLogStartTime (const QString &filename)
 Read the start timestamp from an existing log file.
 
KANOOP_EXPORT QDateTime getLogEndTime (const QString &filename)
 Read the end timestamp from an existing log file.
 
KANOOP_EXPORT LogLevel getLogLevel (const QString &levelName)
 Look up a LogLevel by its name string.
 
KANOOP_EXPORT QList< LogLevelgetLogLevels ()
 Return a list of all defined LogLevel values.
 
KANOOP_EXPORT QString getLogLevelString (LogLevel level)
 Return the name string for a LogLevel value.
 

Detailed Description

Logging subsystem providing categorized, level-filtered output.

A single log entry carrying level, category, timestamp, and message text.

Logging subsystem namespace.

Enumeration Type Documentation

◆ LogLevel

Severity levels for log messages, ordered from most to least critical.

Mirrors the syslog severity levels. The active logger level acts as a threshold: messages with a value greater than the threshold are discarded.

Enumerator
Emergency 

System is unusable.

Alert 

Action must be taken immediately.

Critical 

Critical conditions.

Error 

Error conditions.

Warning 

Warning conditions.

Notice 

Normal but significant condition.

Info 

Informational messages.

Debug 

Debug-level messages.

Definition at line 26 of file loggingtypes.h.

◆ OutputFlags

Bitmask flags controlling where log output is sent.

Enumerator
None 

No output flags set.

LineNumbers 

Include source line numbers in output.

Timestamp 

Include timestamps in output.

Level 

Include severity level in output.

Console 

Write to stdout/stderr.

File 

Write to a log file.

QDebug 

Write via Qt's qDebug() mechanism.

Syslog 

Write to the system syslog.

Standard 

Default output configuration.

Definition at line 41 of file loggingtypes.h.

Function Documentation

◆ addConsumer()

KANOOP_EXPORT void Log::addConsumer ( LogConsumer consumer)

Add an external log consumer to the system logger.

Parameters
consumerConsumer to add

◆ categories()

KANOOP_EXPORT QList< LogCategory > Log::categories ( )

Return all categories registered with the system logger.

Returns
List of LogCategory objects

◆ disableOutputFlags()

KANOOP_EXPORT void Log::disableOutputFlags ( OutputFlags  flags)

Disable specific output flags on the system logger.

Parameters
flagsFlags to disable

◆ enableOutputFlags()

KANOOP_EXPORT void Log::enableOutputFlags ( OutputFlags  flags)

Enable additional output flags on the system logger.

Parameters
flagsFlags to enable

◆ filename()

KANOOP_EXPORT QString Log::filename ( )

Return the log file path of the system logger.

Returns
Log file path string

◆ flags()

KANOOP_EXPORT OutputFlags Log::flags ( )

Return the output flags of the system logger.

Returns
Active OutputFlags bitmask

Referenced by Log::Logger::setFlags().

◆ getLogEndTime()

KANOOP_EXPORT QDateTime Log::getLogEndTime ( const QString &  filename)

Read the end timestamp from an existing log file.

Parameters
filenamePath to the log file
Returns
QDateTime of the last log entry, or invalid QDateTime on error

◆ getLogLevel()

KANOOP_EXPORT LogLevel Log::getLogLevel ( const QString &  levelName)

Look up a LogLevel by its name string.

Parameters
levelNameName string (case-insensitive)
Returns
Matching LogLevel, or Debug as default

◆ getLogLevels()

KANOOP_EXPORT QList< LogLevel > Log::getLogLevels ( )

Return a list of all defined LogLevel values.

Returns
List of LogLevel enum values

◆ getLogLevelString()

KANOOP_EXPORT QString Log::getLogLevelString ( LogLevel  level)

Return the name string for a LogLevel value.

Parameters
levelLogLevel to convert
Returns
Name string, e.g. "Debug"

◆ getLogStartTime()

KANOOP_EXPORT QDateTime Log::getLogStartTime ( const QString &  filename)

Read the start timestamp from an existing log file.

Parameters
filenamePath to the log file
Returns
QDateTime of the first log entry, or invalid QDateTime on error

◆ identity()

KANOOP_EXPORT QString Log::identity ( )

Return the syslog identity of the system logger.

Returns
Syslog identity string

◆ level()

KANOOP_EXPORT LogLevel Log::level ( )

Return the current minimum log level of the system logger.

Returns
Active LogLevel threshold

Referenced by Log::LogEntry::LogEntry().

◆ logHex() [1/2]

KANOOP_EXPORT void Log::logHex ( const char *  file,
int  lineNumber,
LogLevel  level,
const LogCategory category,
const QByteArray &  data,
const QString &  tag = QString() 
)

Write a categorized hex dump via the system logger.

Parameters
fileSource filename
lineNumberSource line number
levelSeverity level
categoryLog category
dataBytes to dump
tagOptional label

◆ logHex() [2/2]

KANOOP_EXPORT void Log::logHex ( const char *  file,
int  lineNumber,
LogLevel  level,
const QByteArray &  data,
const QString &  tag = QString() 
)

Write a hex dump via the system logger.

Parameters
fileSource filename
lineNumberSource line number
levelSeverity level
dataBytes to dump
tagOptional label

◆ logText() [1/2]

KANOOP_EXPORT void Log::logText ( const char *  file,
int  lineNumber,
LogLevel  level,
const LogCategory category,
const QString &  text 
)

Write a categorized text message via the system logger.

Parameters
fileSource filename
lineNumberSource line number
levelSeverity level
categoryLog category
textMessage text

◆ logText() [2/2]

KANOOP_EXPORT void Log::logText ( const char *  file,
int  lineNumber,
LogLevel  level,
const QString &  text 
)

Write a text message via the system logger.

Parameters
fileSource filename
lineNumberSource line number
levelSeverity level
textMessage text

◆ parseLevel()

KANOOP_EXPORT LogLevel Log::parseLevel ( const QString &  value,
bool *  parsed = nullptr 
)

Parse a log level name string into a LogLevel enum value.

Parameters
valueString name (e.g. "debug", "error")
parsedOptional output set to true if parsing succeeded
Returns
Parsed LogLevel, or Debug as default on failure

◆ registerCategory() [1/2]

KANOOP_EXPORT LogCategory Log::registerCategory ( const QString &  name)

Register a log category by name with the system logger.

Parameters
nameCategory name
Returns
Registered LogCategory

◆ registerCategory() [2/2]

KANOOP_EXPORT LogCategory Log::registerCategory ( const QString &  name,
LogLevel  level 
)

Register a log category by name and level with the system logger.

Parameters
nameCategory name
levelLevel override for this category
Returns
Registered LogCategory

◆ removeConsumer()

KANOOP_EXPORT void Log::removeConsumer ( LogConsumer consumer)

Remove an external log consumer from the system logger.

Parameters
consumerConsumer to remove

◆ setCategoryLevel()

KANOOP_EXPORT void Log::setCategoryLevel ( const QString &  name,
LogLevel  level 
)

Override the log level for a named category on the system logger.

Parameters
nameCategory name
levelLevel to apply

◆ setFilename()

KANOOP_EXPORT void Log::setFilename ( const QString &  filename)

Set the log file path of the system logger.

Parameters
filenamePath to the log file

◆ setFlags()

KANOOP_EXPORT void Log::setFlags ( OutputFlags  flags)

Set the output flags of the system logger.

Parameters
flagsNew OutputFlags bitmask

◆ setIdentity()

KANOOP_EXPORT void Log::setIdentity ( const QString &  value)

Set the syslog identity of the system logger.

Parameters
valueIdentity string

◆ setLevel()

KANOOP_EXPORT void Log::setLevel ( LogLevel  value)

Set the minimum log level of the system logger.

Parameters
valueNew LogLevel threshold

◆ systemLog()

KANOOP_EXPORT Logger * Log::systemLog ( )

Return the process-wide Logger singleton.

Returns
Pointer to the global Logger instance