EZLog
Loading...
Searching...
No Matches
EZLog::Logger Class Referencefinal

logger class More...

#include <Logger.h>

Public Types

enum  Level {
  Log_Debug , Log_Info , Log_Warn , Log_Error ,
  Log_Critical , Log_Off
}
 Log levels, divided into 6 levels, in ascending order. Only logs with a level higher than the setting will be output. The default log level is the lowest level Log_Debug_Info, which prints all levels of logs. More...
 
using Callback = std::function< void(const QString &)>
 Callback function type.
 

Public Member Functions

Loggernotimestamp ()
 Return version without timestamp.
 
Loggertimestamp ()
 Return version with timestamp.
 
Loggernoleveltag ()
 Return version without level tag.
 
Loggerleveltag ()
 Return version with level tag.
 
Loggernooutput ()
 Return version without output.
 
Loggeroutput ()
 Return version with output.
 
 ~Logger ()
 Destruct and handle log information.
 
Loggeroperator<< (QChar t)
 Stream input of QChar type data.
 
Loggeroperator<< (bool t)
 Stream input of bool type data.
 
Loggeroperator<< (char t)
 Stream input of char type data.
 
Loggeroperator<< (signed short t)
 Stream input of signed short type data.
 
Loggeroperator<< (unsigned short t)
 Stream input of unsigned short type data.
 
Loggeroperator<< (signed int t)
 Stream input of signed int type data.
 
Loggeroperator<< (unsigned int t)
 Stream input of unsigned int type data.
 
Loggeroperator<< (signed long t)
 Stream input of signed long type data.
 
Loggeroperator<< (unsigned long t)
 Stream input of unsigned long type data.
 
Loggeroperator<< (qint64 t)
 Stream input of qint64 type data.
 
Loggeroperator<< (quint64 t)
 Stream input of quint64 type data.
 
Loggeroperator<< (float t)
 Stream input of float type data.
 
Loggeroperator<< (double t)
 Stream input of double type data.
 
Loggeroperator<< (const char *t)
 Stream input of char* type data.
 
Loggeroperator<< (const QString &t)
 Stream input of QString type data.
 
Loggeroperator<< (const QStringRef &t)
 Stream input of QStringRef type data.
 
Loggeroperator<< (QStringView s)
 Stream input of QStringView type data.
 
Loggeroperator<< (QLatin1String t)
 Stream input of QLatin1String type data.
 
Loggeroperator<< (const QByteArray &t)
 Stream input of QByteArray type data.
 
Loggeroperator<< (const void *t)
 Stream input of void* type data.
 
Loggeroperator<< (QTextStreamFunction f)
 Stream input of QTextStreamFunction type data.
 
Loggeroperator<< (QTextStreamManipulator m)
 Stream input of QTextStreamManipulator type data.
 
template<typename SequentialContainer >
LoggerprintSequentialContainer (Logger &logger, const char *which, const SequentialContainer &c)
 Print sequential container message.
 
template<typename T >
Loggeroperator<< (const QList< T > &list)
 Stream input of QList type data.
 
template<typename T >
Loggeroperator<< (const QVector< T > &vec)
 Stream input of QVector type data.
 
template<typename T , typename Alloc >
Loggeroperator<< (const std::vector< T, Alloc > &vec)
 Stream input of std::vector type data.
 
template<typename T , typename Alloc >
Loggeroperator<< (const std::list< T, Alloc > &list)
 Stream input of std::list type data.
 
template<typename Key , typename T , typename Compare , typename Alloc >
Loggeroperator<< (const std::map< Key, T, Compare, Alloc > &map)
 Stream input of std::map type data.
 
template<typename Key , typename T , typename Compare , typename Alloc >
Loggeroperator<< (const std::multimap< Key, T, Compare, Alloc > &map)
 Stream input of std::multimap type data.
 
template<class Key , class T >
Loggeroperator<< (const QMap< Key, T > &map)
 Stream input of QMap type data.
 
template<class Key , class T >
Loggeroperator<< (const QHash< Key, T > &hash)
 Stream input of QHash type data.
 
template<class T1 , class T2 >
Loggeroperator<< (const QPair< T1, T2 > &pair)
 Stream input of QPair type data.
 
template<class T1 , class T2 >
Loggeroperator<< (const std::pair< T1, T2 > &pair)
 Stream input of std::pair type data.
 
template<typename T >
Loggeroperator<< (const QSet< T > &set)
 Stream input of QSet type data.
 
template<typename T >
Loggeroperator<< (const QContiguousCache< T > &cache)
 Stream input of QContiguousCache type data.
 
 Logger (Level level)
 Logger constructor.
 
 Logger (const Logger &other)
 Logger copy constructor.
 
Loggeroperator= (const Logger &other)
 Logger assignment operator.
 
Loggerspace ()
 Write a space character to the message stream and return logger. Subsequent write operations will automatically insert a space.
 
Loggernospace ()
 Disable automatic space insertion and return logger.
 
LoggermaybeSpace ()
 Write a space character to the stream, depending on the current setting for automatic insertion of spaces, and return logger.
 
bool autoInsertSpaces () const
 Return current setting for automatic space insertion.
 
void setAutoInsertSpaces (bool set)
 Set whether to automatically insert spaces.
 

Static Public Member Functions

static bool Initialize (const QString &projectName="Project", const QString &logPrefix="log", const QString &logDir="Logs/")
 Initialize the logging system.
 
static QString errMsg ()
 Error message. Used to retrieve error information when the logging system fails to initialize.
 
static void InstallMessageHandler ()
 Take over qDebug output.
 
static void UninstallMessageHandler ()
 Cancel taking over qDebug output.
 
static void SetLogLevel (int level)
 Set the log level, only logs with a level higher than the set level will be processed. When the log level is set to Log_Off, the log is turned off.
 
static Level logLevel ()
 Return current log level.
 
static void ReadConfig (const QString &filePath)
 Read log level config file. The file should be in INI format, and this method will read the configuration with the key 'logLevel' and apply it.
 
static void SetShowTimeStamp (bool set)
 Set whether to show timestamps by default.
 
static void SetTimeStampFormat (const QString &format)
 Set timestamp format.
 
static void SetShowLevelTag (bool set)
 Set whether to show level tag by default.
 
static void SetDebugTag (const QString &tag)
 Set debug-level tag.
 
static void SetInfoTag (const QString &tag)
 Set info-level tag.
 
static void SetWarnTag (const QString &tag)
 Set warn-level tag.
 
static void SetErrorTag (const QString &tag)
 Set error-level tag.
 
static void SetCriticalTag (const QString &tag)
 Set critical-level tag.
 
static void SetNeedOutput (bool set)
 Set whether to output log by default.
 
static void SetUnifiedCallback (const Callback &callback)
 Set unified callback, triggered when logging any-level logs.
 
static void SetDebugCallback (const Callback &callback)
 Set debug-level callback, triggered when logging debug-level logs.
 
static void SetInfoCallback (const Callback &callback)
 Set info-level callback, triggered when logging info-level logs.
 
static void SetWarnCallback (const Callback &callback)
 Set warn-level callback, triggered when logging warn-level logs.
 
static void SetErrorCallback (const Callback &callback)
 Set error-level callback, triggered when logging error-level logs.
 
static void SetCriticalCallback (const Callback &callback)
 Set critical-level callback, triggered when logging critical-level logs.
 
static Logger Debug ()
 Create debug-level logger.
 
static Logger Info ()
 Create info-level logger.
 
static Logger Warn ()
 Create warn-level logger.
 
static Logger Error ()
 Create error-level logger.
 
static Logger Critical ()
 Create critical-level logger.
 
static Logger Debug (const QString &msg)
 Record debug-level information in the log.
 
static Logger Info (const QString &msg)
 Record info-level information in the log.
 
static Logger Warn (const QString &msg)
 Record warn-level information in the log.
 
static Logger Error (const QString &msg)
 Record error-level information in the log.
 
static Logger Critical (const QString &msg)
 Record critical-level information in the log.
 

Detailed Description

logger class

Member Typedef Documentation

◆ Callback

using EZLog::Logger::Callback = std::function<void(const QString&)>

Callback function type.

Member Enumeration Documentation

◆ Level

Log levels, divided into 6 levels, in ascending order. Only logs with a level higher than the setting will be output. The default log level is the lowest level Log_Debug_Info, which prints all levels of logs.

Enumerator
Log_Debug 

Output debug information, typically used for debugging during the development process

Log_Info 

Output informational messages, typically used to indicate the normal running state of the program

Log_Warn 

Output warning messages, typically used to indicate potential issues that may arise in the program

Log_Error 

Output error messages, typically used to indicate errors that would prevent the program from running properly

Log_Critical 

Output critical error messages, typically used to indicate severe failures or errors

Log_Off 

Turn off logging

Constructor & Destructor Documentation

◆ ~Logger()

EZLog::Logger::~Logger ( )
inline

Destruct and handle log information.

◆ Logger() [1/2]

EZLog::Logger::Logger ( Level  level)
inlineexplicit

Logger constructor.

Parameters
levellogger level

◆ Logger() [2/2]

EZLog::Logger::Logger ( const Logger other)
inline

Logger copy constructor.

Parameters
otherobject to be copied

Member Function Documentation

◆ autoInsertSpaces()

bool EZLog::Logger::autoInsertSpaces ( ) const
inline

Return current setting for automatic space insertion.

Returns
current setting for automatic space insertion

◆ Critical() [1/2]

Logger EZLog::Logger::Critical ( )
inlinestatic

Create critical-level logger.

Returns
critical-level logger

◆ Critical() [2/2]

Logger EZLog::Logger::Critical ( const QString &  msg)
inlinestatic

Record critical-level information in the log.

Parameters
msginformation to be logged
Returns
critical-level logger

◆ Debug() [1/2]

Logger EZLog::Logger::Debug ( )
inlinestatic

Create debug-level logger.

Returns
debug-level logger

◆ Debug() [2/2]

Logger EZLog::Logger::Debug ( const QString &  msg)
inlinestatic

Record debug-level information in the log.

Parameters
msginformation to be logged
Returns
debug-level logger

◆ errMsg()

QString EZLog::Logger::errMsg ( )
inlinestatic

Error message. Used to retrieve error information when the logging system fails to initialize.

Returns
the error message

◆ Error() [1/2]

Logger EZLog::Logger::Error ( )
inlinestatic

Create error-level logger.

Returns
error-level logger

◆ Error() [2/2]

Logger EZLog::Logger::Error ( const QString &  msg)
inlinestatic

Record error-level information in the log.

Parameters
msginformation to be logged
Returns
error-level logger

◆ Info() [1/2]

Logger EZLog::Logger::Info ( )
inlinestatic

Create info-level logger.

Returns
info-level logger

◆ Info() [2/2]

Logger EZLog::Logger::Info ( const QString &  msg)
inlinestatic

Record info-level information in the log.

Parameters
msginformation to be logged
Returns
info-level logger

◆ Initialize()

bool EZLog::Logger::Initialize ( const QString &  projectName = "Project",
const QString &  logPrefix = "log",
const QString &  logDir = "Logs/" 
)
inlinestatic

Initialize the logging system.

Parameters
projectNameproject name
logPrefixlog file prefix
logDirlog storage location
Returns
whether the initialization was successful

◆ InstallMessageHandler()

void EZLog::Logger::InstallMessageHandler ( )
inlinestatic

Take over qDebug output.

◆ leveltag()

Logger & EZLog::Logger::leveltag ( )
inline

Return version with level tag.

Returns
logger with level tag

◆ logLevel()

Logger::Level EZLog::Logger::logLevel ( )
inlinestatic

Return current log level.

Returns
current log level

◆ maybeSpace()

Logger & EZLog::Logger::maybeSpace ( )
inline

Write a space character to the stream, depending on the current setting for automatic insertion of spaces, and return logger.

Returns
logger

◆ noleveltag()

Logger & EZLog::Logger::noleveltag ( )
inline

Return version without level tag.

Returns
logger without level tag

◆ nooutput()

Logger & EZLog::Logger::nooutput ( )
inline

Return version without output.

Returns
logger without output

◆ nospace()

Logger & EZLog::Logger::nospace ( )
inline

Disable automatic space insertion and return logger.

Returns
logger with automatic space insertion mode disabled

◆ notimestamp()

Logger & EZLog::Logger::notimestamp ( )
inline

Return version without timestamp.

Returns
logger without timestamp

◆ operator<<() [1/34]

Logger & EZLog::Logger::operator<< ( bool  t)
inline

Stream input of bool type data.

Parameters
tdata
Returns
logger

◆ operator<<() [2/34]

Logger & EZLog::Logger::operator<< ( char  t)
inline

Stream input of char type data.

Parameters
tdata
Returns
logger

◆ operator<<() [3/34]

Logger & EZLog::Logger::operator<< ( const char *  t)
inline

Stream input of char* type data.

Parameters
tdata
Returns
logger

◆ operator<<() [4/34]

Logger & EZLog::Logger::operator<< ( const QByteArray &  t)
inline

Stream input of QByteArray type data.

Parameters
tdata
Returns
logger

◆ operator<<() [5/34]

template<typename T >
Logger & EZLog::Logger::operator<< ( const QContiguousCache< T > &  cache)
inline

Stream input of QContiguousCache type data.

Parameters
cachedata
Returns
logger

◆ operator<<() [6/34]

template<class Key , class T >
Logger & EZLog::Logger::operator<< ( const QHash< Key, T > &  hash)
inline

Stream input of QHash type data.

Parameters
hashdata
Returns
logger

◆ operator<<() [7/34]

template<typename T >
Logger & EZLog::Logger::operator<< ( const QList< T > &  list)
inline

Stream input of QList type data.

Parameters
listdata
Returns
logger

◆ operator<<() [8/34]

template<class Key , class T >
Logger & EZLog::Logger::operator<< ( const QMap< Key, T > &  map)
inline

Stream input of QMap type data.

Parameters
mapdata
Returns
logger

◆ operator<<() [9/34]

template<class T1 , class T2 >
Logger & EZLog::Logger::operator<< ( const QPair< T1, T2 > &  pair)
inline

Stream input of QPair type data.

Parameters
pairdata
Returns
logger

◆ operator<<() [10/34]

template<typename T >
Logger & EZLog::Logger::operator<< ( const QSet< T > &  set)
inline

Stream input of QSet type data.

Parameters
setdata
Returns
logger

◆ operator<<() [11/34]

Logger & EZLog::Logger::operator<< ( const QString &  t)
inline

Stream input of QString type data.

Parameters
tdata
Returns
logger

◆ operator<<() [12/34]

Logger & EZLog::Logger::operator<< ( const QStringRef &  t)
inline

Stream input of QStringRef type data.

Parameters
tdata
Returns
logger

◆ operator<<() [13/34]

template<typename T >
Logger & EZLog::Logger::operator<< ( const QVector< T > &  vec)
inline

Stream input of QVector type data.

Parameters
vecdata
Returns
logger

◆ operator<<() [14/34]

template<typename T , typename Alloc >
Logger & EZLog::Logger::operator<< ( const std::list< T, Alloc > &  list)
inline

Stream input of std::list type data.

Parameters
listdata
Returns
logger

◆ operator<<() [15/34]

template<typename Key , typename T , typename Compare , typename Alloc >
Logger & EZLog::Logger::operator<< ( const std::map< Key, T, Compare, Alloc > &  map)
inline

Stream input of std::map type data.

Parameters
mapdata
Returns
logger

◆ operator<<() [16/34]

template<typename Key , typename T , typename Compare , typename Alloc >
Logger & EZLog::Logger::operator<< ( const std::multimap< Key, T, Compare, Alloc > &  map)
inline

Stream input of std::multimap type data.

Parameters
mapdata
Returns
logger

◆ operator<<() [17/34]

template<class T1 , class T2 >
Logger & EZLog::Logger::operator<< ( const std::pair< T1, T2 > &  pair)
inline

Stream input of std::pair type data.

Parameters
pairdata
Returns
logger

◆ operator<<() [18/34]

template<typename T , typename Alloc >
Logger & EZLog::Logger::operator<< ( const std::vector< T, Alloc > &  vec)
inline

Stream input of std::vector type data.

Parameters
vecdata
Returns
logger

◆ operator<<() [19/34]

Logger & EZLog::Logger::operator<< ( const void *  t)
inline

Stream input of void* type data.

Parameters
tdata
Returns
logger

◆ operator<<() [20/34]

Logger & EZLog::Logger::operator<< ( double  t)
inline

Stream input of double type data.

Parameters
tdata
Returns
logger

◆ operator<<() [21/34]

Logger & EZLog::Logger::operator<< ( float  t)
inline

Stream input of float type data.

Parameters
tdata
Returns
logger

◆ operator<<() [22/34]

Logger & EZLog::Logger::operator<< ( QChar  t)
inline

Stream input of QChar type data.

Parameters
tdata
Returns
logger

◆ operator<<() [23/34]

Logger & EZLog::Logger::operator<< ( qint64  t)
inline

Stream input of qint64 type data.

Parameters
tdata
Returns
logger

◆ operator<<() [24/34]

Logger & EZLog::Logger::operator<< ( QLatin1String  t)
inline

Stream input of QLatin1String type data.

Parameters
tdata
Returns
logger

◆ operator<<() [25/34]

Logger & EZLog::Logger::operator<< ( QStringView  s)
inline

Stream input of QStringView type data.

Parameters
sdata
Returns
logger

◆ operator<<() [26/34]

Logger & EZLog::Logger::operator<< ( QTextStreamFunction  f)
inline

Stream input of QTextStreamFunction type data.

Parameters
fdata
Returns
logger

◆ operator<<() [27/34]

Logger & EZLog::Logger::operator<< ( QTextStreamManipulator  m)
inline

Stream input of QTextStreamManipulator type data.

Parameters
mdata
Returns
logger

◆ operator<<() [28/34]

Logger & EZLog::Logger::operator<< ( quint64  t)
inline

Stream input of quint64 type data.

Parameters
tdata
Returns
logger

◆ operator<<() [29/34]

Logger & EZLog::Logger::operator<< ( signed int  t)
inline

Stream input of signed int type data.

Parameters
tdata
Returns
logger

◆ operator<<() [30/34]

Logger & EZLog::Logger::operator<< ( signed long  t)
inline

Stream input of signed long type data.

Parameters
tdata
Returns
logger

◆ operator<<() [31/34]

Logger & EZLog::Logger::operator<< ( signed short  t)
inline

Stream input of signed short type data.

Parameters
tdata
Returns
logger

◆ operator<<() [32/34]

Logger & EZLog::Logger::operator<< ( unsigned int  t)
inline

Stream input of unsigned int type data.

Parameters
tdata
Returns
logger

◆ operator<<() [33/34]

Logger & EZLog::Logger::operator<< ( unsigned long  t)
inline

Stream input of unsigned long type data.

Parameters
tdata
Returns
logger

◆ operator<<() [34/34]

Logger & EZLog::Logger::operator<< ( unsigned short  t)
inline

Stream input of unsigned short type data.

Parameters
tdata
Returns
logger

◆ operator=()

Logger & EZLog::Logger::operator= ( const Logger other)
inline

Logger assignment operator.

Parameters
otherobject to be copied
Returns
logger

◆ output()

Logger & EZLog::Logger::output ( )
inline

Return version with output.

Returns
logger with output

◆ printSequentialContainer()

template<typename SequentialContainer >
Logger & EZLog::Logger::printSequentialContainer ( Logger logger,
const char *  which,
const SequentialContainer &  c 
)
inline

Print sequential container message.

Parameters
loggerlogger
whichcontainer name
ccontainer
Returns
logger

◆ ReadConfig()

void EZLog::Logger::ReadConfig ( const QString &  filePath)
inlinestatic

Read log level config file. The file should be in INI format, and this method will read the configuration with the key 'logLevel' and apply it.

Parameters
filePathconfig file path

◆ setAutoInsertSpaces()

void EZLog::Logger::setAutoInsertSpaces ( bool  set)
inline

Set whether to automatically insert spaces.

Parameters
setwhether to set

◆ SetCriticalCallback()

void EZLog::Logger::SetCriticalCallback ( const Callback callback)
inlinestatic

Set critical-level callback, triggered when logging critical-level logs.

Parameters
callbackcallback method

◆ SetCriticalTag()

void EZLog::Logger::SetCriticalTag ( const QString &  tag)
inlinestatic

Set critical-level tag.

Parameters
tagtag content, default is [critical]

◆ SetDebugCallback()

void EZLog::Logger::SetDebugCallback ( const Callback callback)
inlinestatic

Set debug-level callback, triggered when logging debug-level logs.

Parameters
callbackcallback method

◆ SetDebugTag()

void EZLog::Logger::SetDebugTag ( const QString &  tag)
inlinestatic

Set debug-level tag.

Parameters
tagtag content, default is [debug]

◆ SetErrorCallback()

void EZLog::Logger::SetErrorCallback ( const Callback callback)
inlinestatic

Set error-level callback, triggered when logging error-level logs.

Parameters
callbackcallback method

◆ SetErrorTag()

void EZLog::Logger::SetErrorTag ( const QString &  tag)
inlinestatic

Set error-level tag.

Parameters
tagtag content, default is [error]

◆ SetInfoCallback()

void EZLog::Logger::SetInfoCallback ( const Callback callback)
inlinestatic

Set info-level callback, triggered when logging info-level logs.

Parameters
callbackcallback method

◆ SetInfoTag()

void EZLog::Logger::SetInfoTag ( const QString &  tag)
inlinestatic

Set info-level tag.

Parameters
tagtag content, default is [info]

◆ SetLogLevel()

void EZLog::Logger::SetLogLevel ( int  level)
inlinestatic

Set the log level, only logs with a level higher than the set level will be processed. When the log level is set to Log_Off, the log is turned off.

Parameters
levellog level, default is Log_Debug

◆ SetNeedOutput()

void EZLog::Logger::SetNeedOutput ( bool  set)
inlinestatic

Set whether to output log by default.

Parameters
setwhether to output, default is false

◆ SetShowLevelTag()

void EZLog::Logger::SetShowLevelTag ( bool  set)
inlinestatic

Set whether to show level tag by default.

Parameters
setwhether to show, default is true

◆ SetShowTimeStamp()

void EZLog::Logger::SetShowTimeStamp ( bool  set)
inlinestatic

Set whether to show timestamps by default.

Parameters
setwhether to show, default is false

◆ SetTimeStampFormat()

void EZLog::Logger::SetTimeStampFormat ( const QString &  format)
inlinestatic

Set timestamp format.

Parameters
formattimestamp format, default is [HH:mm:ss]

◆ SetUnifiedCallback()

void EZLog::Logger::SetUnifiedCallback ( const Callback callback)
inlinestatic

Set unified callback, triggered when logging any-level logs.

Parameters
callbackcallback method

◆ SetWarnCallback()

void EZLog::Logger::SetWarnCallback ( const Callback callback)
inlinestatic

Set warn-level callback, triggered when logging warn-level logs.

Parameters
callbackcallback method

◆ SetWarnTag()

void EZLog::Logger::SetWarnTag ( const QString &  tag)
inlinestatic

Set warn-level tag.

Parameters
tagtag content, default is [warning]

◆ space()

Logger & EZLog::Logger::space ( )
inline

Write a space character to the message stream and return logger. Subsequent write operations will automatically insert a space.

Returns
logger with automatic space insertion mode enabled

◆ timestamp()

Logger & EZLog::Logger::timestamp ( )
inline

Return version with timestamp.

Returns
logger with timestamp

◆ UninstallMessageHandler()

void EZLog::Logger::UninstallMessageHandler ( )
inlinestatic

Cancel taking over qDebug output.

◆ Warn() [1/2]

Logger EZLog::Logger::Warn ( )
inlinestatic

Create warn-level logger.

Returns
warn-level logger

◆ Warn() [2/2]

Logger EZLog::Logger::Warn ( const QString &  msg)
inlinestatic

Record warn-level information in the log.

Parameters
msginformation to be logged
Returns
warn-level logger

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