[翻译] Gecko日志记录
来源:互联网 发布:centos改为中文 编辑:程序博客网 时间:2024/05/16 00:54
原文链接:Gecko_Logging
Gecko核心代码提供了一个基础的C++日志记录框架。所有构建 (Debug、Release)默认开启,线程安全,是NSPR日志记录的首选。
日志记录框架
声明日志模块
LazyLogModule以线程安全的方式推迟创建后台LogModule,并且是声明日志模块的首选方法。
#include "mozilla/Logging.h"static mozilla::LazyLogModule sFooLog("foo");
提供了2个宏和1个枚举类做为基本接口
Mozilla日志记录宏
MOZ_LOG(module, level, message)
输出指定信息,如果模块日志级别允许。
- module - 要使用的日志模块
- level - 消息的日志输出级别
- message - 要输出的printf样式消息。必须括在括号中
MOZ_LOG_TEST(module, level)
检查模块是否开启相应的日志输出级别。
- module - 要使用的日志模块
- level - 日志输出级别
Mozilla日志级别
日志记录接口
使用示例
示例代码
#include "mozilla/Logging.h"using mozilla::LogLevel;static mozilla::LazyLogModule sLogger("example_logger");static void DoStuff(){ MOZ_LOG(sLogger, LogLevel::Info, ("Doing stuff.")); int i = 0; int start = Time::NowMS(); MOZ_LOG(sLogger, LogLevel::Debug, ("Starting loop.")); while (i++ < 10) { MOZ_LOG(sLogger, LogLevel::Verbose, ("i = %d", i)); } // Only calculate the elapsed time if the Warning level is enabled. if (MOZ_LOG_TEST(sLogger, LogLevel::Warning)) { int elapsed = Time::NowMS() - start; if (elapsed > 1000) { MOZ_LOG(sLogger, LogLevel::Warning, ("Loop took %dms!", elapsed)); } } if (i != 10) { MOZ_LOG(sLogger, LogLevel::Error, ("i should be 10!")); }}
开启日志输出
模块的日志级别通过在启动应用程序之前设置环境变量来控制。
export MOZ_LOG="example_logger:3"
有一些特殊的模块名可以改变日志行为。除日志级别以外,你可以指定一个或多个特殊模块名称。
例如,如果要指定“sync”,“timestamp”和“rotate”:
export MOZ_LOG="example_logger:3,timestamp,sync,rotate:10"
重定向日志到文件
日志输出可以通过环境变量传递其路径来重定向到文件。
默认情况下,日志输出到stderr。
export MOZ_LOG_FILE="log.txt"
上述转储和附加选项仅适用于记录到文件。
E10S注意
当content进程在沙盒中时,它不能写入stderr或任何文件。可能需要将首选项security.sandbox.content.level设置为0才能查看日志。
0 0
- [翻译] Gecko日志记录
- Gecko:Key Gecko Structures And Invariants翻译
- Gecko
- Gecko
- jbpm用户指南翻译:第15章 记录日志
- 日志记录
- 日志记录
- 记录日志
- 日志记录
- 日志记录
- 记录日志
- 记录日志
- 日志记录
- 记录日志
- 日志记录
- 日志记录
- 日志记录
- 日志记录
- 大话数据结构之:简单选择排序
- 汉诺塔问题
- 表格嵌套时,即表格中插入表格,边框重叠的两种实现方式
- 走迷宫
- (24)Air Band OpenCV2.4.13_自定义线性滤波器
- [翻译] Gecko日志记录
- 子线程一定不能更新UI吗?
- 随手笔记
- Vehicle tracking using a support vector machine vs. YOLO
- 【Python&NLP】一些没什么用处的经验,结巴分词的安装心路历程
- 利用salesforce(sfdc)自带的IDE来编写并调试Apex类(入门级-调试篇)
- C# 闭包解析
- 279. Perfect Squares
- Spring入门---环境配置