没有合适的资源?快使用搜索试试~ 我知道了~
首页linux系统中c++写日志文件功能分享
资源详情
资源评论
资源推荐

linux系统中系统中c++写日志文件功能分享写日志文件功能分享
主要介绍了linux系统中c++写日志文件功能,简化了glog,只保留了写日志文件的功能,只是改写了linux版本,
需要的朋友可以参考下
简化了glog,只保留了写日志文件的功能,只是改写了linux版本,win版本未改写,可以用
LOG(INFO)<< 输出日志
也可用LOG_IF(INFO,condition)<<输出日志
也可直接调用日志类Logger::GetInstance().Error 等方式写日志
初始化时调用 InitLogging(argv[0],INFO,"./log/test");
第一个参数是路径,第二个参数是最低日志级别,第三个参数表示日志文件的前缀和文件夹
FileHelper.h
#ifndef FILEHELPER_H_
#define FILEHELPER_H_
#include <string>
#include <vector>
#include <fstream>
#include <stdio.h>
#ifdef _WIN32
#include <direct.h>
#include <io.h>
#else
#include <stdarg.h>
#include <sys/stat.h>
#endif
namespace FrameWork {
#ifdef _WIN32
#define ACCESS _access
#define MKDIR(a) _mkdir((a))
#else
#define ACCESS access
#define MKDIR(a) mkdir((a),0755)
#endif
class FileHelper {
public:
static bool save(const std::string filename, std::string& content)
{
FILE *file = fopen(filename.c_str(), "wb");
if (file == NULL)
return false;
fwrite(content.c_str(),sizeof(char),content.size(),file);
fclose(file);
return true;
}
// used to open binary file
static bool open(const std::string filename, std::string& content)
{
FILE *file = fopen(filename.c_str(), "rb");
if (file == NULL)
return false;
fseek(file, 0, SEEK_END);
int len = ftell(file);
rewind(file);
content.clear();
char *buffer = new char[len];
fread(buffer, sizeof(char), len, file);
content.assign(buffer, len);
delete []buffer;
//int nRead;
//content.clear();



















安全验证
文档复制为VIP权益,开通VIP直接复制

评论0