EZLog
载入中...
搜索中...
未找到
EZLog::Logger类 参考final

日志类 更多...

#include <Logger.h>

Public 类型

enum  Level {
  Log_Debug , Log_Info , Log_Warn , Log_Error ,
  Log_Critical , Log_Off
}
 日志等级,分为6等,依次递增。只有等级高于设定的日志才会被输出。 默认为最低等级Log_Debug_Info,即打印全部等级的日志。 更多...
 
using Callback = std::function< void(const QString &)>
 回调函数类型
 

Public 成员函数

Loggernotimestamp ()
 返回不带时间戳的版本。
 
Loggertimestamp ()
 返回带时间戳的版本。
 
Loggernoleveltag ()
 返回不带等级标签的版本。
 
Loggerleveltag ()
 返回带等级标签的版本。
 
Loggernooutput ()
 返回不带输出的版本。
 
Loggeroutput ()
 返回带输出的版本。
 
 ~Logger ()
 析构并处理log信息。
 
Loggeroperator<< (QChar t)
 流式输入QChar类型数据。
 
Loggeroperator<< (bool t)
 流式输入bool类型数据。
 
Loggeroperator<< (char t)
 流式输入char类型数据。
 
Loggeroperator<< (signed short t)
 流式输入signed short类型数据。
 
Loggeroperator<< (unsigned short t)
 流式输入unsigned short类型数据。
 
Loggeroperator<< (signed int t)
 流式输入signed int类型数据。
 
Loggeroperator<< (unsigned int t)
 流式输入unsigned int类型数据。
 
Loggeroperator<< (signed long t)
 流式输入signed long类型数据。
 
Loggeroperator<< (unsigned long t)
 流式输入unsigned long类型数据。
 
Loggeroperator<< (qint64 t)
 流式输入qint64类型数据。
 
Loggeroperator<< (quint64 t)
 流式输入quint64类型数据。
 
Loggeroperator<< (float t)
 流式输入float类型数据。
 
Loggeroperator<< (double t)
 流式输入double类型数据。
 
Loggeroperator<< (const char *t)
 流式输入char*类型数据。
 
Loggeroperator<< (const QString &t)
 流式输入QString类型数据。
 
Loggeroperator<< (const QStringRef &t)
 流式输入QStringRef类型数据。
 
Loggeroperator<< (QStringView s)
 流式输入QStringView类型数据。
 
Loggeroperator<< (QLatin1String t)
 流式输入QLatin1String类型数据。
 
Loggeroperator<< (const QByteArray &t)
 流式输入QByteArray类型数据。
 
Loggeroperator<< (const void *t)
 流式输入void*类型数据。
 
Loggeroperator<< (QTextStreamFunction f)
 流式输入QTextStreamFunction类型数据。
 
Loggeroperator<< (QTextStreamManipulator m)
 流式输入QTextStreamManipulator类型数据。
 
template<typename SequentialContainer >
LoggerprintSequentialContainer (Logger &logger, const char *which, const SequentialContainer &c)
 打印顺序容器信息。
 
template<typename T >
Loggeroperator<< (const QList< T > &list)
 流式输入QList类型数据。
 
template<typename T >
Loggeroperator<< (const QVector< T > &vec)
 流式输入QVector类型数据。
 
template<typename T , typename Alloc >
Loggeroperator<< (const std::vector< T, Alloc > &vec)
 流式输入std::vector类型数据。
 
template<typename T , typename Alloc >
Loggeroperator<< (const std::list< T, Alloc > &list)
 流式输入std::list类型数据。
 
template<typename Key , typename T , typename Compare , typename Alloc >
Loggeroperator<< (const std::map< Key, T, Compare, Alloc > &map)
 流式输入std::map类型数据。
 
template<typename Key , typename T , typename Compare , typename Alloc >
Loggeroperator<< (const std::multimap< Key, T, Compare, Alloc > &map)
 流式输入std::multimap类型数据。
 
template<class Key , class T >
Loggeroperator<< (const QMap< Key, T > &map)
 流式输入QMap类型数据。
 
template<class Key , class T >
Loggeroperator<< (const QHash< Key, T > &hash)
 流式输入QHash类型数据。
 
template<class T1 , class T2 >
Loggeroperator<< (const QPair< T1, T2 > &pair)
 流式输入QPair类型数据。
 
template<class T1 , class T2 >
Loggeroperator<< (const std::pair< T1, T2 > &pair)
 流式输入std::pair类型数据。
 
template<typename T >
Loggeroperator<< (const QSet< T > &set)
 流式输入QSet类型数据。
 
template<typename T >
Loggeroperator<< (const QContiguousCache< T > &cache)
 流式输入QContiguousCache类型数据。
 
 Logger (Level level)
 Logger构造函数。
 
 Logger (const Logger &other)
 Logger拷贝构造函数。
 
Loggeroperator= (const Logger &other)
 Logger赋值运算符。
 
Loggerspace ()
 向消息流中写入一个空格并返回日志实例,后续的写入操作会自动插入空格。
 
Loggernospace ()
 关闭自动插入空格并返回日志实例。
 
LoggermaybeSpace ()
 根据当前的设置插入空格并返回日志实例。
 
bool autoInsertSpaces () const
 返回当前自动插入空格的设定。
 
void setAutoInsertSpaces (bool set)
 设置是否自动插入空格。
 

静态 Public 成员函数

static bool Initialize (const QString &projectName="Project", const QString &logPrefix="log", const QString &logDir="Logs/")
 初始化日志系统。
 
static QString errMsg ()
 错误信息。当日志系统初始化失败时用于获取错误信息。
 
static void InstallMessageHandler ()
 接管qDebug输出。
 
static void UninstallMessageHandler ()
 取消接管qDebug输出。
 
static void SetLogLevel (int level)
 设置日志等级,只有等级高于设定的日志才会被处理。 当日志等级设置为 Log_Off 时,log关闭。
 
static Level logLevel ()
 返回当前日志等级。
 
static void ReadConfig (const QString &filePath)
 读取日志等级配置文件。配置文件应为ini格式, 该方法会读取键为"logLevel"的配置并应用。
 
static void SetShowTimeStamp (bool set)
 设置默认是否显示时间戳。
 
static void SetTimeStampFormat (const QString &format)
 设置时间戳格式
 
static void SetShowLevelTag (bool set)
 设置默认是否显示等级标签。
 
static void SetDebugTag (const QString &tag)
 设置debug等级标签。
 
static void SetInfoTag (const QString &tag)
 设置info等级标签。
 
static void SetWarnTag (const QString &tag)
 设置warn等级标签。
 
static void SetErrorTag (const QString &tag)
 设置error等级标签。
 
static void SetCriticalTag (const QString &tag)
 设置critical等级标签。
 
static void SetNeedOutput (bool set)
 设置默认是否输出log信息。
 
static void SetUnifiedCallback (const Callback &callback)
 设置统一回调,在记录任意等级的log时触发
 
static void SetDebugCallback (const Callback &callback)
 设置debug等级回调,在记录debug等级的log时触发
 
static void SetInfoCallback (const Callback &callback)
 设置info等级回调,在记录info等级的log时触发
 
static void SetWarnCallback (const Callback &callback)
 设置warn等级回调,在记录warn等级的log时触发
 
static void SetErrorCallback (const Callback &callback)
 设置error等级回调,在记录info等级的log时触发
 
static void SetCriticalCallback (const Callback &callback)
 设置critical等级回调,在记录critical等级的log时触发
 
static Logger Debug ()
 创建debug等级日志实例。
 
static Logger Info ()
 创建info等级日志实例。
 
static Logger Warn ()
 创建warn等级日志实例。
 
static Logger Error ()
 创建error等级日志实例。
 
static Logger Critical ()
 创建critical等级日志实例。
 
static Logger Debug (const QString &msg)
 在日志中记录debug等级的信息。
 
static Logger Info (const QString &msg)
 在日志中记录info等级的信息。
 
static Logger Warn (const QString &msg)
 在日志中记录warn等级的信息。
 
static Logger Error (const QString &msg)
 在日志中记录error等级的信息。
 
static Logger Critical (const QString &msg)
 在日志中记录critical等级的信息。
 

详细描述

日志类

成员类型定义说明

◆ Callback

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

回调函数类型

成员枚举类型说明

◆ Level

日志等级,分为6等,依次递增。只有等级高于设定的日志才会被输出。 默认为最低等级Log_Debug_Info,即打印全部等级的日志。

枚举值
Log_Debug 

输出调试信息,一般用于开发过程中debug

Log_Info 

输出消息性信息,一般用于标记程序正常运行的状态

Log_Warn 

输出警告信息,一般用于标记程序可能出现的潜在问题

Log_Error 

输出错误信息,一般用于标记发生了会导致程序无法正常运行的错误

Log_Critical 

输出严重错误信息,一般用于标记发生了严重的故障或错误

Log_Off 

关闭Log

构造及析构函数说明

◆ ~Logger()

EZLog::Logger::~Logger ( )
inline

析构并处理log信息。

◆ Logger() [1/2]

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

Logger构造函数。

参数
levellogger等级

◆ Logger() [2/2]

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

Logger拷贝构造函数。

参数
other拷贝对象

成员函数说明

◆ autoInsertSpaces()

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

返回当前自动插入空格的设定。

返回
当前自动插入空格的设定

◆ Critical() [1/2]

Logger EZLog::Logger::Critical ( )
inlinestatic

创建critical等级日志实例。

返回
critical等级的日志实例

◆ Critical() [2/2]

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

在日志中记录critical等级的信息。

参数
msg要记录的信息
返回
critical等级的日志实例

◆ Debug() [1/2]

Logger EZLog::Logger::Debug ( )
inlinestatic

创建debug等级日志实例。

返回
debug等级的日志实例

◆ Debug() [2/2]

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

在日志中记录debug等级的信息。

参数
msg要记录的信息
返回
debug等级的日志实例

◆ errMsg()

QString EZLog::Logger::errMsg ( )
inlinestatic

错误信息。当日志系统初始化失败时用于获取错误信息。

返回
具体错误信息

◆ Error() [1/2]

Logger EZLog::Logger::Error ( )
inlinestatic

创建error等级日志实例。

返回
error等级的日志实例

◆ Error() [2/2]

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

在日志中记录error等级的信息。

参数
msg要记录的信息
返回
error等级的日志实例

◆ Info() [1/2]

Logger EZLog::Logger::Info ( )
inlinestatic

创建info等级日志实例。

返回
info等级的日志实例

◆ Info() [2/2]

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

在日志中记录info等级的信息。

参数
msg要记录的信息
返回
info等级的日志实例

◆ Initialize()

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

初始化日志系统。

参数
projectName项目名
logPrefix文件前缀
logDir日志存储位置
返回
初始化是否成功

◆ InstallMessageHandler()

void EZLog::Logger::InstallMessageHandler ( )
inlinestatic

接管qDebug输出。

◆ leveltag()

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

返回带等级标签的版本。

返回
带等级标签的日志实例

◆ logLevel()

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

返回当前日志等级。

返回
当前日志等级

◆ maybeSpace()

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

根据当前的设置插入空格并返回日志实例。

返回
日志实例

◆ noleveltag()

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

返回不带等级标签的版本。

返回
不带等级标签的日志实例

◆ nooutput()

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

返回不带输出的版本。

返回
带输出的日志实例

◆ nospace()

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

关闭自动插入空格并返回日志实例。

返回
关闭自动插入空格模式的日志实例

◆ notimestamp()

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

返回不带时间戳的版本。

返回
不带时间戳的日志实例

◆ operator<<() [1/34]

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

流式输入bool类型数据。

参数
t数据
返回
日志实例

◆ operator<<() [2/34]

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

流式输入char类型数据。

参数
t数据
返回
日志实例

◆ operator<<() [3/34]

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

流式输入char*类型数据。

参数
t数据
返回
日志实例

◆ operator<<() [4/34]

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

流式输入QByteArray类型数据。

参数
t数据
返回
日志实例

◆ operator<<() [5/34]

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

流式输入QContiguousCache类型数据。

参数
cache数据
返回
日志实例

◆ operator<<() [6/34]

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

流式输入QHash类型数据。

参数
hash数据
返回
日志实例

◆ operator<<() [7/34]

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

流式输入QList类型数据。

参数
list数据
返回
日志实例

◆ operator<<() [8/34]

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

流式输入QMap类型数据。

参数
map数据
返回
日志实例

◆ operator<<() [9/34]

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

流式输入QPair类型数据。

参数
pair数据
返回
日志实例

◆ operator<<() [10/34]

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

流式输入QSet类型数据。

参数
set数据
返回
日志实例

◆ operator<<() [11/34]

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

流式输入QString类型数据。

参数
t数据
返回
日志实例

◆ operator<<() [12/34]

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

流式输入QStringRef类型数据。

参数
t数据
返回
日志实例

◆ operator<<() [13/34]

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

流式输入QVector类型数据。

参数
vec数据
返回
日志实例

◆ operator<<() [14/34]

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

流式输入std::list类型数据。

参数
list数据
返回
日志实例

◆ 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

流式输入std::map类型数据。

参数
map数据
返回
日志实例

◆ 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

流式输入std::multimap类型数据。

参数
map数据
返回
日志实例

◆ operator<<() [17/34]

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

流式输入std::pair类型数据。

参数
pair数据
返回
日志实例

◆ operator<<() [18/34]

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

流式输入std::vector类型数据。

参数
vec数据
返回
日志实例

◆ operator<<() [19/34]

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

流式输入void*类型数据。

参数
t数据
返回
日志实例

◆ operator<<() [20/34]

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

流式输入double类型数据。

参数
t数据
返回
日志实例

◆ operator<<() [21/34]

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

流式输入float类型数据。

参数
t数据
返回
日志实例

◆ operator<<() [22/34]

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

流式输入QChar类型数据。

参数
t数据
返回
日志实例

◆ operator<<() [23/34]

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

流式输入qint64类型数据。

参数
t数据
返回
日志实例

◆ operator<<() [24/34]

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

流式输入QLatin1String类型数据。

参数
t数据
返回
日志实例

◆ operator<<() [25/34]

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

流式输入QStringView类型数据。

参数
s数据
返回
日志实例

◆ operator<<() [26/34]

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

流式输入QTextStreamFunction类型数据。

参数
f数据
返回
日志实例

◆ operator<<() [27/34]

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

流式输入QTextStreamManipulator类型数据。

参数
m数据
返回
日志实例

◆ operator<<() [28/34]

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

流式输入quint64类型数据。

参数
t数据
返回
日志实例

◆ operator<<() [29/34]

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

流式输入signed int类型数据。

参数
t数据
返回
日志实例

◆ operator<<() [30/34]

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

流式输入signed long类型数据。

参数
t数据
返回
日志实例

◆ operator<<() [31/34]

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

流式输入signed short类型数据。

参数
t数据
返回
日志实例

◆ operator<<() [32/34]

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

流式输入unsigned int类型数据。

参数
t数据
返回
日志实例

◆ operator<<() [33/34]

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

流式输入unsigned long类型数据。

参数
t数据
返回
日志实例

◆ operator<<() [34/34]

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

流式输入unsigned short类型数据。

参数
t数据
返回
日志实例

◆ operator=()

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

Logger赋值运算符。

参数
other拷贝对象
返回
日志实例

◆ output()

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

返回带输出的版本。

返回
带输出的日志实例

◆ printSequentialContainer()

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

打印顺序容器信息。

参数
logger日志实例
which容器名称
c容器
返回
日志实例

◆ ReadConfig()

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

读取日志等级配置文件。配置文件应为ini格式, 该方法会读取键为"logLevel"的配置并应用。

参数
filePath配置文件路径

◆ setAutoInsertSpaces()

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

设置是否自动插入空格。

参数
set是否设置

◆ SetCriticalCallback()

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

设置critical等级回调,在记录critical等级的log时触发

参数
callback回调函数

◆ SetCriticalTag()

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

设置critical等级标签。

参数
tag标签内容,默认为 [critical]

◆ SetDebugCallback()

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

设置debug等级回调,在记录debug等级的log时触发

参数
callback回调函数

◆ SetDebugTag()

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

设置debug等级标签。

参数
tag标签内容,默认为 [debug]

◆ SetErrorCallback()

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

设置error等级回调,在记录info等级的log时触发

参数
callback回调函数

◆ SetErrorTag()

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

设置error等级标签。

参数
tag标签内容,默认为 [error]

◆ SetInfoCallback()

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

设置info等级回调,在记录info等级的log时触发

参数
callback回调函数

◆ SetInfoTag()

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

设置info等级标签。

参数
tag标签内容,默认为 [info]

◆ SetLogLevel()

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

设置日志等级,只有等级高于设定的日志才会被处理。 当日志等级设置为 Log_Off 时,log关闭。

参数
level日志等级,默认为 Log_Debug

◆ SetNeedOutput()

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

设置默认是否输出log信息。

参数
set是否输出,默认为false

◆ SetShowLevelTag()

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

设置默认是否显示等级标签。

参数
set是否显示,默认为true

◆ SetShowTimeStamp()

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

设置默认是否显示时间戳。

参数
set是否显示,默认为false

◆ SetTimeStampFormat()

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

设置时间戳格式

参数
format时间戳格式,默认为 [HH:mm:ss]

◆ SetUnifiedCallback()

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

设置统一回调,在记录任意等级的log时触发

参数
callback回调函数

◆ SetWarnCallback()

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

设置warn等级回调,在记录warn等级的log时触发

参数
callback回调函数

◆ SetWarnTag()

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

设置warn等级标签。

参数
tag标签内容,默认为 [warning]

◆ space()

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

向消息流中写入一个空格并返回日志实例,后续的写入操作会自动插入空格。

返回
开启自动插入空格模式的日志实例

◆ timestamp()

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

返回带时间戳的版本。

返回
带时间戳的日志实例

◆ UninstallMessageHandler()

void EZLog::Logger::UninstallMessageHandler ( )
inlinestatic

取消接管qDebug输出。

◆ Warn() [1/2]

Logger EZLog::Logger::Warn ( )
inlinestatic

创建warn等级日志实例。

返回
warn等级的日志实例

◆ Warn() [2/2]

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

在日志中记录warn等级的信息。

参数
msg要记录的信息
返回
warn等级的日志实例

该类的文档由以下文件生成: