STTNet
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Public Member Functions | List of all members
stt::file::LogFile Class Reference

Log file operation class. More...

#include <sttnet_English.h>

Inheritance diagram for stt::file::LogFile:
stt::time::DateTime stt::file::File stt::file::FileTool

Public Member Functions

 LogFile ()
 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...
 
void 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
 

Detailed Description

Log file operation class.

Note
The log reading/writing of this class is thread-safe due to inheritance from the File class

Constructor & Destructor Documentation

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

Constructor, initializes the consumer thread.

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

The destructor writes the log and then closes the consumer thread.

Member Function Documentation

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

Clear all logs.

Returns
true for successful clear, false for failure
bool stt::file::LogFile::closeFile ( const bool &  del = false)

Close the log file opened by the object.

Parameters
deltrue to close and delete the log file, false to only close (default)
Returns
true for successful close, false for failure
bool stt::file::LogFile::deleteLogByTime ( const std::string &  date1 = "1",
const std::string &  date2 = "2" 
)

Delete logs within a specified time interval.

Parameters
date1The first parameter of the time interval (default is infinitely small)
date2The second parameter of the time interval (default is infinitely large)
Note
The interval is [date1, date2)
Returns
true for successful deletion, false for failure
std::string stt::file::LogFile::getFileName ( )
inline

Get the file name opened by the object.

Returns
The file name opened by the object
bool stt::file::LogFile::isOpen ( )
inline

Get the status of whether the log file is open.

Returns
true if open, false otherwise
bool stt::file::LogFile::openFile ( const std::string &  fileName,
const std::string &  timeFormat = ISO8086A,
const std::string &  contentFormat = "   " 
)

Open a log file.

Note
Create if not exists (including directories). Default directory permission: rwx rwx r-x, default log file permission: rw- rw- r–
Parameters
fileNameLog file name (absolute or relative path)
timeFormatTime format in the log file (default is ISO08086A standard)
contentFormatFiller format between time and record (default is " ")
Returns
true for success, false for failure
void stt::file::LogFile::writeLog ( const std::string &  data)

Write a line of log.

Parameters
dataContent to be written to the log

The documentation for this class was generated from the following file: