13 Star 69 Fork 22

johnsonyl/cpps

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
cpps_logging_filehandler.cpp 1.17 KB
一键复制 编辑 原始数据 按行查看 历史
johnsonyl 提交于 2021-01-09 10:35 +08:00 . 2020-01-09 更新
#include "cpps_logging_filehandler.h"
#include "cpps_logger_config.h"
namespace cpps {
cpps_integer cpps_io_mkdirs(std::string szdir);
std::string cpps_io_getfilepath(std::string str);
cpps_logging_filehandler::cpps_logging_filehandler()
:cpps_logging_handler( cpps_logging_handler_type_filehandler)
{
file = NULL;
delay = false;
mode = "ab+";
}
cpps_logging_filehandler::~cpps_logging_filehandler()
{
if (file) fclose(file);
file = NULL;
}
void cpps_logging_filehandler::pop(usint8 level, std::string& msg)
{
while (!file) {
std::this_thread::sleep_for(std::chrono::milliseconds(10));
openfile();/*尝试重新打开*/
}
fprintf(file,"%s\r\n", msg.c_str());
fflush(file);
}
void cpps_logging_filehandler::setfile(std::string name, std::string filemode)
{
/*创建文件夹*/
std::string path = cpps_io_getfilepath(name);
cpps_io_mkdirs(path);
filename = name;
mode = filemode;
}
void cpps_logging_filehandler::setdelay(bool d)
{
delay = d;
}
void cpps_logging_filehandler::openfile()
{
if (filename.empty() || mode.empty()) return;
file = fopen(filename.c_str(), mode.c_str());
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/cppscript/cpps.git
git@gitee.com:cppscript/cpps.git
cppscript
cpps
cpps
master

搜索帮助