|
STTNet 0.7.0
|
日志文件操作类 More...
#include <sttnet.h>
Public Member Functions | |
| LogFile (const size_t &logQueue_cap=8192) | |
| 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) |
| 写一行日志 | |
| uint64_t | getDroppedLogCount () const noexcept |
| 返回日志队列满时累计丢弃的日志条数。 | |
| bool | clearLog () |
| 清空所有日志 | |
| bool | deleteLogByTime (const std::string &date1="1", const std::string &date2="2") |
| 删除指定时间区间内的日志 | |
| ~LogFile () | |
| 析构函数 写完日志 关闭消费者线程 | |
Additional Inherited Members | |
Protected Member Functions inherited from 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) |
| 写数据块 | |
| bool | 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 Attributes inherited from stt::file::File | |
| std::mutex | che |
Static Protected Attributes inherited from stt::file::File | |
| static std::mutex | l1 |
| static std::unordered_map< std::string, FileThreadLock > | fl2 |
日志文件操作类
|
inline |
@brief 构造函数,初始化消费者线程
@param logQueue_cap 异步日志队列容量(必须为 2 的幂)。
所有线程产生的日志会先进入该无锁队列,再由独立 logger 线程批量写入文件。 日志系统不在主业务热路径上,允许在过载时丢弃,以保护核心服务性能。
选型原则: logQueue_cap >= 峰值日志速率 × logger 最坏暂停时间
建议值(经验):
当队列已满时:日志将丢弃,框架不会阻塞调用线程。
| stt::file::LogFile::~LogFile | ( | ) |
析构函数 写完日志 关闭消费者线程
| bool stt::file::LogFile::clearLog | ( | ) |
清空所有日志
| bool stt::file::LogFile::closeFile | ( | const bool & | del = false | ) |
关闭对象打开的日志文件
| del | true:关闭并且删除日志文件 false:只关闭不删除日志文件 (默认为false 即只关闭不删除日志文件) |
| bool stt::file::LogFile::deleteLogByTime | ( | const std::string & | date1 = "1", |
| const std::string & | date2 = "2" ) |
删除指定时间区间内的日志
| date1 | 时间区间的第一个参数 (默认缺省为无限小) |
| date2 | 时间区间的第二个参数 (默认缺省为无限大) |
|
inlinenoexcept |
返回日志队列满时累计丢弃的日志条数。
|
inline |
获取对象打开的文件名
|
inline |
获取对象是否打开日志文件的状态
| bool stt::file::LogFile::openFile | ( | const std::string & | fileName, |
| const std::string & | timeFormat = ISO8086A, | ||
| const std::string & | contentFormat = " " ) |
打开一个日志文件
| fileName | 日志文件名(可以用绝对路径也可以用相对路径) |
| timeFormat | 日志文件中的时间格式 yyyy年 mm月 dd日 hh时 mi分 ss秒 sss毫秒 (默认格式为'yyyy-mm-ddThh:mi:ss',即 STTNet 历史本地时间文本格式(不携带时区)) |
| contentFormat | 日志文件中时间和记录之间的填充格式(默认为" " 即四个空格) |
| void stt::file::LogFile::writeLog | ( | const std::string & | data | ) |
写一行日志
| data | 需要写入的日志内容 |