This class implements utility functions for writing logs to files asynchronously.
More...
#include <trantor/utils/AsyncFileLogger.h>
|
| void | output (const char *msg, const uint64_t len) |
| | Write the message to the log file.
|
|
void | flush () |
| | Flush data from memory buffer to the log file.
|
|
void | startLogging () |
| | Start writing log files.
|
| void | setFileSizeLimit (uint64_t limit) |
| | Set the size limit of log files. When the log file size reaches the limit, the log file is switched.
|
| void | setMaxFiles (size_t maxFiles) |
| | Set the max number of log files. When the number exceeds the limit, the oldest log file will be deleted.
|
| void | setSwitchOnLimitOnly (bool flag=true) |
| | Set whether to switch the log file when the AsyncFileLogger object is destroyed. If this flag is set to true, the log file is not switched when the AsyncFileLogger object is destroyed.
|
| void | setFileName (const std::string &baseName, const std::string &extName=".log", const std::string &path="./") |
| | Set the log file name.
|
|
|
void | writeLogToFile (const StringPtr buf) |
|
void | logThreadFunc () |
|
void | swapBuffer () |
|
|
std::mutex | mutex_ |
|
std::condition_variable | cond_ |
|
StringPtr | logBufferPtr_ |
|
StringPtr | nextBufferPtr_ |
|
StringPtrQueue | writeBuffers_ |
|
StringPtrQueue | tmpBuffers_ |
|
std::unique_ptr< std::thread > | threadPtr_ |
|
bool | stopFlag_ {false} |
|
std::string | filePath_ {"./"} |
|
std::string | fileBaseName_ {"trantor"} |
|
std::string | fileExtName_ {".log"} |
|
uint64_t | sizeLimit_ {20 * 1024 * 1024} |
|
bool | switchOnLimitOnly_ {false} |
|
size_t | maxFiles_ {0} |
|
std::unique_ptr< LoggerFile > | loggerFilePtr_ |
|
uint64_t | lostCounter_ {0} |
This class implements utility functions for writing logs to files asynchronously.
◆ output()
| void trantor::AsyncFileLogger::output |
( |
const char * | msg, |
|
|
const uint64_t | len ) |
Write the message to the log file.
- Parameters
-
◆ setFileName()
| void trantor::AsyncFileLogger::setFileName |
( |
const std::string & | baseName, |
|
|
const std::string & | extName = ".log", |
|
|
const std::string & | path = "./" ) |
|
inline |
Set the log file name.
- Parameters
-
| baseName | The base name of the log file. |
| extName | The extended name of the log file. |
| path | The location where the log file is stored. |
◆ setFileSizeLimit()
| void trantor::AsyncFileLogger::setFileSizeLimit |
( |
uint64_t | limit | ) |
|
|
inline |
Set the size limit of log files. When the log file size reaches the limit, the log file is switched.
- Parameters
-
◆ setMaxFiles()
| void trantor::AsyncFileLogger::setMaxFiles |
( |
size_t | maxFiles | ) |
|
|
inline |
Set the max number of log files. When the number exceeds the limit, the oldest log file will be deleted.
- Parameters
-
◆ setSwitchOnLimitOnly()
| void trantor::AsyncFileLogger::setSwitchOnLimitOnly |
( |
bool | flag = true | ) |
|
|
inline |
Set whether to switch the log file when the AsyncFileLogger object is destroyed. If this flag is set to true, the log file is not switched when the AsyncFileLogger object is destroyed.
- Parameters
-
The documentation for this class was generated from the following file: