log4cpp日志不能是溶液子体积
我们的项目用途log4cpp由于日志输出模块,但在使用中发现,假设Services,或者是在Windows Server版本号。不会有一个正常的日志切削现象。该日志已被写入到文件中,持续,即使超过规定的文件大小。也不会分卷。
log4cpp中切割日志的核心算法为:(如果同意的最大文件个数为4)
1.关闭xxx.log.
2.删除 xxx.log.4
3.是一个loop, 将xxx.log.3--->xxx.log.4,xxx.log.2--->xxx.log.3,xxx.log.1----->xxx.log.2
4.将xxx.log--->xxx.log.1
5.打开xxx.log.
相关代码为:
void RollingFileAppender::rollOver() {
::close(_fd); // 1
if (_maxBackupIndex > 0) {
std::ostringstream oldName;
oldName << _fileName << "." << _maxBackupIndex << std::ends;
::remove(oldName.str().c_str()); //2
size_t n = _fileName.length() + 1;
for(unsigned int i = _maxBackupIndex; i > 1; i--) { //3
std::string newName = oldName.str();
oldName.seekp(n);
oldName << i-1 << std::ends;
::rename(oldName.str().c_str(), newName.c_str());
}
::rename(_fileName.c_str(), oldName.str().c_str()); //4
}
_fd = ::open(_fileName.c_str(), _flags, _mode);//5
}
日志文件无法切割(眼下发现仅仅在win server版本号无法work),原因出在步骤1,4,5上。
关闭文件后,随后将文件重命名,会导致重命名失败。通过打印错误码得知,错误码为32,意思为:文件句柄被占用。
解决方式为。往两个不同的文件中中写日志。不再仅仅往一个文件名称里写日志,交替写日志,交替关闭文件。write(A),close(B)---->Write(B),Close(A),----->Write(A),Close(B).
改动后的代码为:
void RollingFileAppender::rollOver() {
::close(_fd);
if (_maxBackupIndex > 0) {
std::ostringstream oldName;
oldName << _fileName << "." << _maxBackupIndex << std::ends;
::remove(oldName.str().c_str());
size_t n = _fileName.length() + 1;
for(unsigned int i = _maxBackupIndex; i > 1; i--) {
std::string newName = oldName.str();
oldName.seekp(n);
oldName << i-1 << std::ends;
::rename(oldName.str().c_str(), newName.c_str());
}
if(_bUsingTempFile)
::rename(_fileNameTmp.c_str(), oldName.str().c_str());
else
::rename(_fileName.c_str(), oldName.str().c_str());
}
if(_bUsingTempFile)
_fd = ::open(_fileName.c_str(), _flags, _mode);
else
_fd = ::open(_fileNameTmp.c_str(), _flags, _mode);
_bUsingTempFile = !_bUsingTempFile;
}
版权声明:本文博主原创文章。博客,未经同意不得转载。
log4cpp日志不能是溶液子体积的更多相关文章
- 以打印日志为荣之logging模块详细使用
啄木鸟社区里的Pythonic八荣八耻有一条: 以打印日志为荣 , 以单步跟踪为耻; 很多程序都有记录日志的需求,并且日志中包含的信息既有正常的程序访问日志,还可能有错误.警告等信息输出,python ...
- Logback日志配置的简单使用
Logback介绍 Logback是由log4j创始人设计的又一个开源日志组件.logback当前分成三个模块:logback-core,logback- classic和logback-access ...
- logback的使用和logback.xml详解,在Spring项目中使用log打印日志
logback的使用和logback.xml详解 一.logback的介绍 Logback是由log4j创始人设计的另一个开源日志组件,官方网站: http://logback.qos.ch.它当前分 ...
- 阿里云 oss实时日志查询
实时日志查询 更新时间:2019-01-29 10:31:49 编辑 · 本页目录 开启实时日志查询 查询实时日志 参考文档 用户在访问 OSS 的过程中,会产生大量的访问日志.实时日志查询功能将 O ...
- 一步步入门log4cpp
前言 项目实现过程中,需要检查.查找或者调试程序bug等,此时程序日志则较为清晰地展现代码的运行过程.目前接触到的方法有打印消息到控制台,将重要信息输出到某个文件比如txt文件,或者直接使用日志库. ...
- java日志 -logback的使用和logback.xml详解(转)
一.logback的介绍 Logback是由log4j创始人设计的另一个开源日志组件,官方网站: http://logback.qos.ch.它当前分为下面下个模块: logback-core:其它两 ...
- :Linux 系统日志管理 日志转储
Linux日志服务器设置 使用“@IP:端口”或“@@IP:端口”的格式可以把日志发送到远程主机上. 假设需要管理几十台服务器,每天的重要工作就是查看这些服务器的日志,可是每台服务器单独登录,并且查看 ...
- JavaWeb笔记(十二)日志
日志 日志信息根据用途与记录内容的不同,分为调试日志.运行日志.异常日志等. Java常用记录日志 logger log4j log4j2 logback 其中除了logger使用的概率较小,因此主要 ...
- Python学习笔记:logging(日志处理)
在一个软件中,日志是可以说必不可少的一个组成部分,通常会在定位客户问题或者记录软件使用情况等场景中会用到.logging模板块是Python的一个内置标准库,用于实现对日志的控制输出,对于平常的日志输 ...
随机推荐
- 参数化测试--sheet表的应用
自动化测试对录制和编辑好的测试步骤进行回放,这种是线性的自动化测试方式,其缺点是明显的,就是其测试覆盖面比较低.测试回放的只是录制时做出的界面操作,以及输入的测试数据,或者是脚本编辑时指定的界面操作和 ...
- android选择和裁剪图像拍摄的图像
转载请注明出处:http://blog.csdn.net/allen315410/article/details/39994913 近期从曾经的项目中扒下来一个经常使用的模块.在这里有必要记录一下的. ...
- Shine we together: A innovative dating site using 2012 Nobel Laureate Roth's algorithm
Abstract Our dating site introduced scoring and its related functionalities innovatively, conforming ...
- How to import the www.googleapis.com SSL CA certification to the jks store file?
Assumed that you have installed JDK and configured JAVA_HOME for your current operation system. (1) ...
- STL algorithm算法minmax,minmax_element(36)
minmax原型: std::minmax C++11 C++14 default (1) template <class T> pair <const T&,const T ...
- Android 通过系统使用NotificationListenerService 监听各种Notification的用法
NotificationListenerService是通过系统调起的服务,当有应用发起通知的时候,系统会将通知的动作和信息回调给NotificationListenerService. 在继承Not ...
- 于iOS跳转到应用程序AppStore
1.找到应用程序的叙述原文链接,实例: https://57324.api-01.com/serve? action=click&publisher_id=57324&site_id= ...
- 【原创】leetCodeOj --- Majority Element 解题报告(脍炙人口的找n个元素数组中最少重复n/2次的元素)
题目地址: https://oj.leetcode.com/problems/majority-element/ 题目内容: Given an array of size n, find the ma ...
- 【原创】leetCodeOj --- Merge k Sorted Lists 解题报告
题目地址: https://oj.leetcode.com/problems/merge-k-sorted-lists/ 题目内容: /** * Definition for singly-linke ...
- J2SE基础:7.系统经常使用类一
1.Object对象 Object对象是全部对象的根类. 每一个对象都默认继承自Object类. equals():对象与对象之间是否相等. 逻辑上面的相等.equals 物理上面的相等(地址相等) ...