A simple (colored) log library for Qt
Null Log Library是一个为Qt制作的简易日志工具,它可以帮助您输出美观的彩色日志。
Null Log Library is a simple library made for Qt, it can help you out beautiful (colored) log for you.
兼容性问题(非常重要) · Compatibility Issue (Very Important)
该库仅在能支持ANSI escape code的终端上能输出彩色文本,部分终端以及IDE(比如CLion)的终端需要进行配置才可以正确输出彩色文本
This library can only output colored log properly on terminal (emulators) that supports ANSI escape code, and some terminals and IDEs (like CLion) need you to configure them in order to output colored logs properly.
该库仅在能支持ANSI escape code的终端上能输出彩色文本,部分终端以及IDE(比如CLion)的终端需要进行配置才可以正确输出彩色文本
This library can only output colored log properly on terminal (emulators) that supports ANSI escape code, and some terminals and IDEs (like CLion) need you to configure them in order to output colored logs properly.
我们假设您使用Qt5或者Qt6以及CMake。
We assume that you are using either Qt 5 or Qt 6 together with CMake.
- 克隆这个仓库到本地。
Clone this repository to your machine. - 打开项目的CMake工程(与本README同级,不在
src
或者demo_src
里),设置如下CMake前缀:
Open the CMake project (which is at the same level with this README, it is not that ope insrc
norsrc_demo
) and set the following Cmake Prefix:比如:-DCMAKE_PREFIX_PATH:PATH="<Qt安装路径 · Qt Installation path>"
For example:-DCMAKE_PREFIX_PATH:PATH="D:/SDK/Qt/6.8.0/msvc2022_64"
- 编译这个库,请注意库不会自动安装到系统。
Start compiling, please note that THE LIBRARY WILL NOT BE INSTALLED TO YOUR SYSTEM.
- 对于导入库,可以参考
./demo_src/CMakeLists.txt
。
For importing, you may refer to the demo example at./demo_src/CMakeLists.txt
. - 您应该需要修改一下其中路径到自己的导入位置,如果您不作为子项目引入的话,请尤其注意
target_include_directories
,该值决定了库中的头文件是否能被找到,本项目的/includes
文件夹里面有所需的所有头文件,需要的话可以复制一份。
You might want to adjust the import path in thatCMakeList
to fit your project, please ESPECIALLY NOTE THE VARIABLEtarget_include_directories
, which decided whether IDE would tell you that you got missing header(s) (from this library). The/includes
folder of this project contains all the headers you will need, and you can copy that if needed.
- 如果您的程序闪退,并且是由于缺少库文件引起,请注意我们的例子没有自动拷贝库到二进制文件路径的功能,如果您是完全参考它写的引入,您应该考虑自己实现一个或者手动拷贝。
If your program crashed due to missing library file, please note that our demo does not automatically copy the library to the binary location, so you may want to implement that or copy the library file manually.
以下是本库目前支持的函数的签名:
Here are the function signatures that you can use:
static void setIsColorEnabled(bool result);
static bool getIsColorEnabled(void);
static QString info(const QString& tag, const QString& content);
static QString info(const QString& tag, const QString& title, const QString& content);
static QString ok(const QString& tag, const QString& content);
static QString ok(const QString& tag, const QString& title, const QString& content);
static QString warn(const QString& tag, const QString& content);
static QString warn(const QString& tag, const QString& title, const QString& content);
static QString error(const QString& tag, const QString& content);
static QString error(const QString& tag, const QString& title, const QString& content);
setIsColorEnabled
: 设置彩色日志输出是否开启,true
为开启,false
为关闭;彩色日志输出默认开启。这是全局设置,并且设置后会产生一条日志。setIsColorEnabled
: Set if colored log output should be enabled,true
for enabling andfalse
for disabling; Colored log output is enabled by default. This is global config, and a log will be generated after you toggle the setting.getIsColorEnabled
: 获取彩色日志输出状态,返回true
为开启,false
为关闭。getIsColorEnabled
: Get if colored log output is enabled, returningtrue
for enabling andfalse
for disabling.- 剩下这些函数都是负责输出日志的,函数名即为日志等级,参数介绍请参考下方的表格:
- And all other functions are responsible for generating logs, see table below for explanation of these parameters:
名称 · Parameter Name | 解释 · Explaination | 是否必须 · Is that Required |
---|---|---|
tag | 您定义的标签名,用于告诉其他开发者这是哪个模块正在输出日志 | 是 |
tag | Tag name that is defined by you that tells others which module is generating log | Yes |
title | 可选的标题名,用于进一步定位产生日志的代码 | 否 |
title | Optional title that helps locating the code that throws the log | No |
content | 日志的具体内容 | 是 |
content | Content of your log | Yes |
注意 · Notice
1.
2. 本库目前不会储存任何产生的日志,但是这些日志生成函数的返回类型都是
1. Log level
2. Currently this library will not store any log generated so you may need to implement your own way. You may notice that the return type of each log generating function is
1.
OK
使用的是qInfo
。2. 本库目前不会储存任何产生的日志,但是这些日志生成函数的返回类型都是
QString
,内容是(没有颜色的)您的日志内容,您可以利用这个自己实现日志储存。1. Log level
OK
uses qInfo
.2. Currently this library will not store any log generated so you may need to implement your own way. You may notice that the return type of each log generating function is
QString
and they are actually returning the log generated (without color) so you may use them.
- [✔ 已完成 · Completed] Log generating · 基础日志生成
- [🔧 正在开发 · Developing] Log storing · 日志储存
- [🔧 正在开发 · Developing] Log displaying widget · 日志显示微件
本项目以GPL-2.0许可分发,请参阅LICENSE文件以获取更多信息。
This project is distributed under GPL-2.0. See LICENSE for more information.