标签:
前面几节中描述了Boost.Log 的基础知识,对Boost.Log 库的操作我们都是在C++代码中进行中,这样就会有一些不便的地方。比如说我们想要更改一下输出格式或者过滤条件,都必须对C++代码进行更改,并且还得编译一次(感觉编译时间还有点长)。其实Boost.Log 里面已经为这个问题提供了一种解决方案,就是通过配置文件来初始化Boost.Log 库,C++这边的代码也比较简单,就是这样的:
std::ifstream settings("settings.txt");
if (!settings.is_open())
throw std::runtime_error("Could not open settings.txt file");
logging::init_from_stream(settings);
#
# Copyright Andrey Semashev 2007 - 2014.
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)
#
[Sinks.TextFileSettings]
Destination=TextFile
FileName=test.log
AutoFlush=true
Format="[%TimeStamp%] [%Severity%]\n%MyScopes%\n\t:: %Message%"
Asynchronous=false
// Core 配置
Core
// 过滤条件, 例如 "%Severity% >= debug")
Filter
// 禁用日志, true 或者 flase)
DisableLogging
// 接收器配置
Sinks
// 输出位置,有五个选项,每个选项对应一系列相应选项
Destination(Console/TextFile/Syslog/Debugger/SimpleEventLog)
// 控制台对应的选项
##Console
// 是否宽字节 true 或者 flase
Wide
// 自动刷新 true 或者 flase
AutoFlush
// 过滤条件, 例如 "%Severity% >= debug")
Filter
// 异步方式 true 或者 flase
Asynchronous
// 格式化 例如 "[%TimeStamp%] [%Severity%]\n%MyScopes%\n\t:: %Message%"
Format
// 文件对应的选项
##TextFile
// 文件名 可以直接输入文件名也可以输出文件名的格式,例如test.log和"%Y-%m-%d_%N.log"
FileName
// 单个文件大小,超过此大小自动建立新文件 单位是字节
RotationSize
// 多久后自动建立新文件 单位是秒
RotationInterval
// 什么时候自动建立新文件 例如每个0点创建新文件就是:"00:00:00"
RotationTimePoint
AutoFlush
// 是否将记录追加到原有文件 true 或者 flase
Append
// 输出文件夹(有此选项后才能有下列选项)
Target
// 文件夹最大大小 单位是字节
MaxSize
// 文件夹最小预留空间 单位是字节
MinFreeSpace
// 扫描文件 true 或者 flase
ScanForFiles(ALL/Matching)
Filter
Asychronous
Format
##Syslog
LocalAddress
TargetAddress
Filter
Asynchronous
Format
##Debugger
Wide
Filter
Asynchronous
Format
##SimpleEventLog
Wide
LogName
LogSource
Registration
Filter
Asynchronous
Format
标签:
原文地址:http://www.cnblogs.com/zhangpanyi/p/4487277.html