|
STTNet
|
Log file operation class. More...
#include <sttnet_English.h>
Public Member Functions | |
| LogFile (const size_t &logQueue_cap=8192) | |
| Constructor, initializes the consumer thread. More... | |
| bool | openFile (const std::string &fileName, const std::string &timeFormat=ISO8086A, const std::string &contentFormat=" ") |
| Open a log file. More... | |
| bool | isOpen () |
| Get the status of whether the log file is open. More... | |
| std::string | getFileName () |
| Get the file name opened by the object. More... | |
| bool | closeFile (const bool &del=false) |
| Close the log file opened by the object. More... | |
| void | writeLog (const std::string &data) |
| Write a line of log. More... | |
| bool | clearLog () |
| Clear all logs. More... | |
| bool | deleteLogByTime (const std::string &date1="1", const std::string &date2="2") |
| Delete logs within a specified time interval. More... | |
| ~LogFile () | |
| The destructor writes the log and then closes the consumer thread. More... | |
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) |
| Open a file. More... | |
| bool | closeFile (const bool &del=false) |
| Close the opened file. More... | |
| ~File () | |
| Destructor. More... | |
| bool | isOpen () |
| Check if the object has opened a file. More... | |
| bool | isBinary () |
| Check if the object has opened the file in binary mode. More... | |
| std::string | getFileName () |
| Get the name of the opened file. More... | |
| uint64_t | getFileLine () |
| Get the number of lines in the opened file. More... | |
| size_t | getFileSize () |
| Get the size of the file opened in binary mode. More... | |
| size_t | getSize1 () |
| Get the size of the file opened in binary mode in memory. More... | |
| bool | lockMemory () |
| Read data from disk into memory. More... | |
| bool | unlockMemory (const bool &rec=false) |
| Write data from memory to disk. More... | |
| int | findC (const std::string &targetString, const int linePos=1) |
| Find a line. More... | |
| bool | appendLineC (const std::string &data, const int &linePos=0) |
| Insert a line. More... | |
| bool | deleteLineC (const int &linePos=0) |
| Delete a line. More... | |
| bool | deleteAllC () |
| Delete all lines. More... | |
| bool | chgLineC (const std::string &data, const int &linePos=0) |
| Modify a line. More... | |
| bool | readLineC (std::string &data, const int linePos) |
| Read a single line. More... | |
| std::string & | readC (std::string &data, const int &linePos, const int &num) |
| Read multiple lines. More... | |
| std::string & | readAllC (std::string &data) |
| Read all lines. More... | |
| bool | readC (char *data, const size_t &pos, const size_t &size) |
| Read a data block. More... | |
| bool | writeC (const char *data, const size_t &pos, const size_t &size) |
| Write a data block. More... | |
| bool | formatC () |
| Format the data. More... | |
| int | find (const std::string &targetString, const int linePos=1) |
| Find a line. More... | |
| bool | appendLine (const std::string &data, const int &linePos=0) |
| Insert a line. More... | |
| bool | deleteLine (const int &linePos=0) |
| Delete a line. More... | |
| bool | deleteAll () |
| Delete all lines. More... | |
| bool | chgLine (const std::string &data, const int &linePos=0) |
| Modify a line. More... | |
| bool | readLine (std::string &data, const int linePos) |
| Read a single line. More... | |
| std::string & | read (std::string &data, const int &linePos, const int &num) |
| Read multiple lines. More... | |
| std::string & | readAll (std::string &data) |
| Read all lines. More... | |
| bool | read (char *data, const size_t &pos, const size_t &size) |
| Read a data block. More... | |
| bool | write (const char *data, const size_t &pos, const size_t &size) |
| Write a data block. More... | |
| void | format () |
| Format the data. More... | |
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 |
Log file operation class.
|
inline |
Constructor, initializes the consumer thread.
| logQueue_cap | Asynchronous log queue capacity (must be a power of 2). |
// Logs generated by all threads will first enter this lock-free queue, and then be written to the file in batches by an independent logger thread.
The logging system is not on the main business hot path, allowing logs to be discarded during overload to protect the performance of core services.
// Selection principle:
logQueue_cap >= Peak log rate × worst-case logger pause time
Recommended values (empirical):
When the queue is full: logs will be discarded, and the framework will not block the calling thread.
| stt::file::LogFile::~LogFile | ( | ) |
The destructor writes the log and then closes the consumer thread.
| bool stt::file::LogFile::clearLog | ( | ) |
Clear all logs.
| bool stt::file::LogFile::closeFile | ( | const bool & | del = false | ) |
Close the log file opened by the object.
| del | true to close and delete the log file, false to only close (default) |
| bool stt::file::LogFile::deleteLogByTime | ( | const std::string & | date1 = "1", |
| const std::string & | date2 = "2" |
||
| ) |
Delete logs within a specified time interval.
| date1 | The first parameter of the time interval (default is infinitely small) |
| date2 | The second parameter of the time interval (default is infinitely large) |
|
inline |
Get the file name opened by the object.
|
inline |
Get the status of whether the log file is open.
| bool stt::file::LogFile::openFile | ( | const std::string & | fileName, |
| const std::string & | timeFormat = ISO8086A, |
||
| const std::string & | contentFormat = " " |
||
| ) |
Open a log file.
| fileName | Log file name (absolute or relative path) |
| timeFormat | Time format in the log file (default is ISO08086A standard) |
| contentFormat | Filler format between time and record (default is " ") |
| void stt::file::LogFile::writeLog | ( | const std::string & | data | ) |
Write a line of log.
| data | Content to be written to the log |
1.8.5