SLProject  4.2.000
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
Utils::FileLog Class Reference

File logging class. More...

#include <FileLog.h>

Public Member Functions

 FileLog (std::string logDir, bool forceFlush)
 
virtual ~FileLog ()
 
void flush ()
 
void post (const std::string &message)
 

Private Attributes

std::ofstream _logFile
 
bool _forceFlush
 

Detailed Description

File logging class.

Definition at line 20 of file FileLog.h.

Constructor & Destructor Documentation

◆ FileLog()

Utils::FileLog::FileLog ( std::string  logDir,
bool  forceFlush 
)

Definition at line 20 of file FileLog.cpp.

21  : _forceFlush(forceFlush)
22 {
23  if (!Utils::dirExists(logDir))
24  Utils::makeDir(logDir);
25 
26  time_t now = time(nullptr);
27  std::string fileName = logDir + "/" + std::to_string(now) + "_log.txt";
28  _logFile.open(fileName, std::ofstream::out);
29 
30  if (!_logFile.is_open())
31  {
32  std::string msg = "Could not create log file in dir: " + logDir;
33  Utils::errorMsg("Utils", msg.c_str(), __LINE__, __FILE__);
34  }
35 }
bool _forceFlush
Definition: FileLog.h:30
std::ofstream _logFile
Definition: FileLog.h:29
bool dirExists(const string &path)
Returns true if a directory exists.
Definition: Utils.cpp:790
bool makeDir(const string &path)
Creates a directory with given path.
Definition: Utils.cpp:810
void errorMsg(const char *tag, const char *msg, const int line, const char *file)
Platform independent error message output.
Definition: Utils.cpp:1168

◆ ~FileLog()

Utils::FileLog::~FileLog ( )
virtual

Definition at line 37 of file FileLog.cpp.

38 {
39  _logFile.flush();
40  _logFile.close();
41 }

Member Function Documentation

◆ flush()

void Utils::FileLog::flush ( )

Definition at line 43 of file FileLog.cpp.

44 {
45  _logFile.flush();
46 }

◆ post()

void Utils::FileLog::post ( const std::string &  message)

Definition at line 48 of file FileLog.cpp.

49 {
50  _logFile << message;
51  if (_forceFlush)
52  _logFile.flush();
53 }

Member Data Documentation

◆ _forceFlush

bool Utils::FileLog::_forceFlush
private

Definition at line 30 of file FileLog.h.

◆ _logFile

std::ofstream Utils::FileLog::_logFile
private

Definition at line 29 of file FileLog.h.


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