C++-根据级别记录语句
C++ - Logging statements according to the level
我有以下语句:
static Logging::Logger* common_logger = new Logging::Logger(Logging::Logger::LEVEL);
在Logger.h中,我有
class Logger {
public:
enum LEVEL {
Debug,
Warning,
Notification,
Error
};
}
我已经将Logger.h文件包含在我的另一个类中,作为:
Logging::log(CustomDialog::logger, Logging::Entry, CustomDialog::CLASSNAME, "CustomDialog");
我需要知道这是否是正确的方法。我这样做的原因是根据级别获取日志。
问候,
看看Log4cxx——它很容易使用,几乎包含了C++日志框架中需要的所有功能。它是可扩展的,可以通过配置文件进行配置,甚至支持开箱即用的远程登录。
你可以使用ACE_DEBUG,它看起来很老派(ala printf),但线程安全、可靠且完全可配置(使用日志文件、stdout等)。当然,你必须链接到libACE(自适应通信框架),但它的开发包现在在许多linux发行版中默认都很容易获得。我一直在查看Als
提到的C++日志库帖子中的列表,但似乎大多数人都遇到了许多框架的内存泄漏,boost::Log还没有发布。
另一点是,大多数日志库都使用流,例如:
// from thread 1
mlog(mlog::DEBUG) << "Debug message goes here" << mlog::endl;
// from thread 2
mlog(mlog::INFO) << "Info message goes here" << mlog::endl;
将无法在多线程环境中按预期工作,而ACE将在那里正确执行。
上面的输出看起来像这样:
[thread1 | 12:04.23] Debug me[thread2 | 12:04.24] Info message goesssage goes herehere
相关文章:
- 我的简单if-else语句是如何无法访问的代码
- 有一个打印语句的函数是一种糟糕的编程实践吗
- 线程,如果else语句,都是错误的上下文切换后,会发生什么
- 为什么是0;C++中的有效语句
- 将两个数组中的差异记录在第三个数组中
- Insert函数不适用于2 if语句C++
- If语句未被求值C++
- C++嵌套if语句,基本货币交换
- 多个If语句与使用逻辑运算符计算条件的单个语句的比较
- 是否可以使用if constexpr删除控制流语句
- 无法理解此 return 语句的功能,没有它就会发生运行时错误
- 我似乎对if/else的基本语句有问题:/
- 当调用switch语句中的函数时(即使函数不包含循环),似乎是永不结束的循环的问题
- C++-根据级别记录语句
- QRCodeSignature类不允许记录语句
- Boost.Log在每个日志记录语句之后刷新
- 如何在 android L 上加载 OpenCV 时删除日志记录语句
- 为什么我的 read 语句不记录二进制数据
- 一个方便的C++日志记录语句,使用boost::格式
- Log4cxx日志记录语句挂起