KanoopCommonQt 2.1.1
Kanoop foundational Qt utility library
Loading...
Searching...
No Matches
Log::Logger Class Reference

Core logger class supporting console, file, syslog, and consumer outputs. More...

#include <log.h>

Public Member Functions

 Logger ()
 Default constructor — initializes an unopened logger at Debug level.
 
void openLog ()
 Open the log file or syslog connection as configured.
 
void rotateLog (const QString &newFileName)
 Rotate the log to a new file path.
 
void logText (const char *file, int lineNumber, LogLevel level, const QString &text)
 Write a text message to the log.
 
void logText (const char *file, int lineNumber, LogLevel level, const LogCategory &category, const QString &text)
 Write a categorized text message to the log.
 
void logHex (const char *file, int lineNumber, LogLevel level, const QByteArray &data, const QString &tag=QString())
 Write a hex dump of a byte array to the log.
 
void logHex (const char *file, int lineNumber, LogLevel level, const LogCategory &category, const QByteArray &data, const QString &tag=QString())
 Write a categorized hex dump to the log.
 
LogLevel level () const
 Return the current minimum log level.
 
void setLevel (LogLevel value)
 Set the minimum log level; messages below this level are discarded.
 
OutputFlags flags () const
 Return the active output flags.
 
void setFlags (OutputFlags flags)
 Set the output flags, replacing any existing flags.
 
void enableOutputFlags (OutputFlags flags)
 Enable additional output flags without clearing existing ones.
 
void disableOutputFlags (OutputFlags flags)
 Disable specific output flags without affecting others.
 
QString filename () const
 Return the log file path.
 
void setFilename (const QString &filename)
 Set the log file path and reopen the file.
 
QString identity () const
 Return the syslog identity string.
 
void setIdentity (const QString &value)
 Set the syslog identity string.
 
LogCategory registerCategory (const QString &name)
 Register a new log category by name.
 
LogCategory registerCategory (const LogCategory &category)
 Register an existing LogCategory object.
 
QList< LogCategorycategories () const
 Return all registered log categories.
 
void setCategoryLevel (const QString &name, LogLevel level)
 Override the log level for a specific category.
 
void addConsumer (LogConsumer *consumer)
 Add an external log consumer to receive log entries.
 
void removeConsumer (LogConsumer *consumer)
 Remove a previously added log consumer.
 
bool isLogOpen () const
 Test whether the log is open and ready to write.
 

Detailed Description

Core logger class supporting console, file, syslog, and consumer outputs.

Logger is typically accessed through the module-level free functions (Log::logText, etc.) which delegate to a process-wide singleton returned by Log::systemLog().

Definition at line 52 of file log.h.

Member Function Documentation

◆ addConsumer()

void Log::Logger::addConsumer ( LogConsumer consumer)

Add an external log consumer to receive log entries.

Parameters
consumerConsumer to add

◆ categories()

QList< LogCategory > Log::Logger::categories ( ) const

Return all registered log categories.

Returns
List of LogCategory objects

◆ disableOutputFlags()

void Log::Logger::disableOutputFlags ( OutputFlags  flags)

Disable specific output flags without affecting others.

Parameters
flagsFlags to disable

◆ enableOutputFlags()

void Log::Logger::enableOutputFlags ( OutputFlags  flags)

Enable additional output flags without clearing existing ones.

Parameters
flagsFlags to enable

◆ filename()

QString Log::Logger::filename ( ) const
inline

Return the log file path.

Returns
Path to the output log file

Definition at line 147 of file log.h.

◆ flags()

OutputFlags Log::Logger::flags ( ) const
inline

Return the active output flags.

Returns
Bitmask of OutputFlags

Definition at line 123 of file log.h.

◆ identity()

QString Log::Logger::identity ( ) const
inline

Return the syslog identity string.

Returns
Identity string used in syslog output

Definition at line 159 of file log.h.

◆ isLogOpen()

bool Log::Logger::isLogOpen ( ) const
inline

Test whether the log is open and ready to write.

Returns
true if the log is open

Definition at line 210 of file log.h.

◆ level()

LogLevel Log::Logger::level ( ) const
inline

Return the current minimum log level.

Returns
Active LogLevel threshold

Definition at line 111 of file log.h.

◆ logHex() [1/2]

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

Write a categorized hex dump to the log.

Parameters
fileSource filename (use FILE)
lineNumberSource line number (use LINE)
levelSeverity level of this message
categoryLog category for filtering
dataBytes to dump
tagOptional label prepended to the dump

◆ logHex() [2/2]

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

Write a hex dump of a byte array to the log.

Parameters
fileSource filename (use FILE)
lineNumberSource line number (use LINE)
levelSeverity level of this message
dataBytes to dump
tagOptional label prepended to the dump

◆ logText() [1/2]

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

Write a categorized text message to the log.

Parameters
fileSource filename (use FILE)
lineNumberSource line number (use LINE)
levelSeverity level of this message
categoryLog category for filtering
textMessage text to log

◆ logText() [2/2]

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

Write a text message to the log.

Parameters
fileSource filename (use FILE)
lineNumberSource line number (use LINE)
levelSeverity level of this message
textMessage text to log

◆ registerCategory() [1/2]

LogCategory Log::Logger::registerCategory ( const LogCategory category)

Register an existing LogCategory object.

Parameters
categoryCategory to register
Returns
Registered LogCategory object

◆ registerCategory() [2/2]

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

Register a new log category by name.

Parameters
nameCategory name string
Returns
Registered LogCategory object

◆ removeConsumer()

void Log::Logger::removeConsumer ( LogConsumer consumer)

Remove a previously added log consumer.

Parameters
consumerConsumer to remove

◆ rotateLog()

void Log::Logger::rotateLog ( const QString &  newFileName)

Rotate the log to a new file path.

Parameters
newFileNamePath to the new log file

◆ setCategoryLevel()

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

Override the log level for a specific category.

Parameters
nameCategory name
levelLevel to apply to this category

◆ setFilename()

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

Set the log file path and reopen the file.

Parameters
filenamePath to the output log file

◆ setFlags()

void Log::Logger::setFlags ( OutputFlags  flags)
inline

Set the output flags, replacing any existing flags.

Parameters
flagsNew OutputFlags bitmask

Definition at line 129 of file log.h.

References Log::flags().

◆ setIdentity()

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

Set the syslog identity string.

Parameters
valueIdentity string used in syslog output

◆ setLevel()

void Log::Logger::setLevel ( LogLevel  value)
inline

Set the minimum log level; messages below this level are discarded.

Parameters
valueNew LogLevel threshold

Definition at line 117 of file log.h.


The documentation for this class was generated from the following file: