STTNet
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 宏定义 
Public 成员函数 | 所有成员列表
stt::file::LogFile类 参考

日志文件操作类 更多...

#include <sttnet.h>

类 stt::file::LogFile 继承关系图:
stt::time::DateTime stt::file::File stt::file::FileTool

Public 成员函数

 LogFile ()
 构造函数,初始化消费者线程 更多...
 
bool openFile (const std::string &fileName, const std::string &timeFormat=ISO8086A, const std::string &contentFormat=" ")
 打开一个日志文件 更多...
 
bool isOpen ()
 获取对象是否打开日志文件的状态 更多...
 
std::string getFileName ()
 获取对象打开的文件名 更多...
 
bool closeFile (const bool &del=false)
 关闭对象打开的日志文件 更多...
 
void writeLog (const std::string &data)
 写一行日志 更多...
 
bool clearLog ()
 清空所有日志 更多...
 
bool deleteLogByTime (const std::string &date1="1", const std::string &date2="2")
 删除指定时间区间内的日志 更多...
 
 ~LogFile ()
 析构函数 写完日志 关闭消费者线程 更多...
 

额外继承的成员函数

- Protected 成员函数 继承自 stt::file::File
bool openFile (const std::string &fileName, const bool &create=true, const int &multiple=0, const size_t &size=0, const mode_t &mode=0666)
 打开文件 更多...
 
bool closeFile (const bool &del=false)
 关闭已打开了的文件 更多...
 
 ~File ()
 析构函数 更多...
 
bool isOpen ()
 判断对象是否打开了文件 更多...
 
bool isBinary ()
 判断对象是否以二进制模式打开文件 更多...
 
std::string getFileName ()
 获取打开的文件名字 更多...
 
uint64_t getFileLine ()
 获取打开的文件的行数 更多...
 
size_t getFileSize ()
 获取二进制打开的文件的大小 更多...
 
size_t getSize1 ()
 获取二进制打开的文件在内存中的大小 更多...
 
bool lockMemory ()
 把数据从磁盘读入内存 更多...
 
bool unlockMemory (const bool &rec=false)
 把数据从内存写入磁盘 更多...
 
int findC (const std::string &targetString, const int linePos=1)
 查找行 更多...
 
bool appendLineC (const std::string &data, const int &linePos=0)
 插入行 更多...
 
bool deleteLineC (const int &linePos=0)
 删除行 更多...
 
bool deleteAllC ()
 删除全部 更多...
 
bool chgLineC (const std::string &data, const int &linePos=0)
 修改行 更多...
 
bool readLineC (std::string &data, const int linePos)
 读取单行 更多...
 
std::string & readC (std::string &data, const int &linePos, const int &num)
 读取行 更多...
 
std::string & readAllC (std::string &data)
 读取全部 更多...
 
bool readC (char *data, const size_t &pos, const size_t &size)
 读取数据块 更多...
 
bool writeC (const char *data, const size_t &pos, const size_t &size)
 写数据块 更多...
 
void formatC ()
 格式化数据 更多...
 
int find (const std::string &targetString, const int linePos=1)
 查找行 更多...
 
bool appendLine (const std::string &data, const int &linePos=0)
 插入行 更多...
 
bool deleteLine (const int &linePos=0)
 删除行 更多...
 
bool deleteAll ()
 删除全部 更多...
 
bool chgLine (const std::string &data, const int &linePos=0)
 修改行 更多...
 
bool readLine (std::string &data, const int linePos)
 读取单行 更多...
 
std::string & read (std::string &data, const int &linePos, const int &num)
 读取行 更多...
 
std::string & readAll (std::string &data)
 读取全部 更多...
 
bool read (char *data, const size_t &pos, const size_t &size)
 读取数据块 更多...
 
bool write (const char *data, const size_t &pos, const size_t &size)
 写数据块 更多...
 
void format ()
 格式化数据 更多...
 
- Protected 属性 继承自 stt::file::File
std::mutex che
 
- 静态 Protected 属性 继承自 stt::file::File
static std::mutex l1
 
static std::unordered_map
< std::string, FileThreadLock
fl2
 

详细描述

日志文件操作类

注解
此类的读写日志是线程安全的,因为继承了File类

构造及析构函数说明

stt::file::LogFile::LogFile ( )

构造函数,初始化消费者线程

stt::file::LogFile::~LogFile ( )

析构函数 写完日志 关闭消费者线程

成员函数说明

bool stt::file::LogFile::clearLog ( )

清空所有日志

返回
true:写入成功 false:写入失败
bool stt::file::LogFile::closeFile ( const bool &  del = false)

关闭对象打开的日志文件

参数
deltrue:关闭并且删除日志文件 false:只关闭不删除日志文件 (默认为false 即只关闭不删除日志文件)
返回
true:关闭成功 false:关闭失败
bool stt::file::LogFile::deleteLogByTime ( const std::string &  date1 = "1",
const std::string &  date2 = "2" 
)

删除指定时间区间内的日志

参数
date1时间区间的第一个参数 (默认缺省为无限小)
date2时间区间的第二个参数 (默认缺省为无限大)
注解
区间为[date1,date2)
返回
true:删除成功 false:删除失败
std::string stt::file::LogFile::getFileName ( )
inline

获取对象打开的文件名

返回
返回对象打开的文件名
bool stt::file::LogFile::isOpen ( )
inline

获取对象是否打开日志文件的状态

返回
true:打开了 false:没打开
bool stt::file::LogFile::openFile ( const std::string &  fileName,
const std::string &  timeFormat = ISO8086A,
const std::string &  contentFormat = "   " 
)

打开一个日志文件

注解
不存在则创建(连带目录),默认新建的目录的权限为rwx rwx r-x,默认新建的日志文件权限为rw-,rw-,r–
参数
fileName日志文件名(可以用绝对路径也可以用相对路径)
timeFormat日志文件中的时间格式 yyyy年 mm月 dd日 hh时 mi分 ss秒 sss毫秒 (默认格式为'yyyy-mm-ddThh:mi:ss',即ISO08086A标准)
contentFormat日志文件中时间和记录之间的填充格式(默认为" " 即四个空格)
返回
true:打开成功 false:打开失败
void stt::file::LogFile::writeLog ( const std::string &  data)

写一行日志

参数
data需要写入的日志内容

该类的文档由以下文件生成: