Dragonfly 4.19
A text-based game engine
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
df::LogManager Class Reference
Inheritance diagram for df::LogManager:
Inheritance graph

Public Member Functions

 ~LogManager ()
 
int startUp () override
 
void shutDown () override
 
int writeLog (const char *fmt,...) const
 
int writeLog (int log_level, const char *fmt,...) const
 
int writeMyLog (std::string filename, const char *fmt,...)
 
int writeMyLog (std::string filename, int log_level, const char *fmt,...)
 
void setLogLevel (int new_log_level)
 
int getLogLevel () const
 
void setFlush (bool do_flush=true)
 
void flush ()
 
void setLogTimeString (bool log_time_string=true)
 
void setLogStepCount (bool log_step_count=true)
 
- Public Member Functions inherited from df::Manager
std::string getType () const
 
virtual int startUp ()
 
virtual void shutDown ()
 
bool isStarted () const
 
int onEvent (const Event *p_event) const
 
int registerInterest (Object *p_o, std::string event_type)
 
int unregisterInterest (Object *p_o, std::string event_type)
 

Static Public Member Functions

static LogManagergetInstance ()
 

Private Member Functions

 LogManager ()
 
 LogManager (LogManager const &)
 
void operator= (LogManager const &)
 

Private Attributes

bool m_do_flush
 
int m_log_level
 
bool m_log_time_string
 
bool m_log_step_count
 
FILE * m_p_f
 
std::map< std::string, FILE * > m_file_list
 

Additional Inherited Members

- Protected Member Functions inherited from df::Manager
void setType (std::string new_type)
 

Constructor & Destructor Documentation

◆ LogManager() [1/2]

df::LogManager::LogManager ( )
private

Private since a singleton.

◆ LogManager() [2/2]

df::LogManager::LogManager ( LogManager const &  )
private

Don't allow copy.

◆ ~LogManager()

df::LogManager::~LogManager ( )

If logfile is open, close it.

Member Function Documentation

◆ flush()

void df::LogManager::flush ( )

Flush the logfile.

◆ getInstance()

static LogManager & df::LogManager::getInstance ( )
static

Get the one and only instance of the LogManager.

◆ getLogLevel()

int df::LogManager::getLogLevel ( ) const

Get logging level.

◆ operator=()

void df::LogManager::operator= ( LogManager const &  )
private

Don't allow assignment.

◆ setFlush()

void df::LogManager::setFlush ( bool  do_flush = true)

Set flush of logfile after each write.

◆ setLogLevel()

void df::LogManager::setLogLevel ( int  new_log_level)

Set logging level.

◆ setLogStepCount()

void df::LogManager::setLogStepCount ( bool  log_step_count = true)

Set prepend step count to log messages.

◆ setLogTimeString()

void df::LogManager::setLogTimeString ( bool  log_time_string = true)

Set prepend time string to log messages.

◆ shutDown()

void df::LogManager::shutDown ( )
overridevirtual

Shut down LogManager (close all logfiles).

Reimplemented from df::Manager.

◆ startUp()

int df::LogManager::startUp ( )
overridevirtual

Start up LogManager (open main logfile, usually "dragonfly.log").

Return 0 if ok, else -1.

Reimplemented from df::Manager.

◆ writeLog() [1/2]

int df::LogManager::writeLog ( const char *  fmt,
  ... 
) const

Write to logfile.

Supports printf() formatting of strings. Return number of bytes written (excluding prepends), -1 if error.

◆ writeLog() [2/2]

int df::LogManager::writeLog ( int  log_level,
const char *  fmt,
  ... 
) const

Write to logfile.

Only write if indicated log level >= LogManager log level. Supports printf() formatting of strings. Return number of bytes written (excluding prepends), -1 if error.

◆ writeMyLog() [1/2]

int df::LogManager::writeMyLog ( std::string  filename,
const char *  fmt,
  ... 
)

Write to custom logfile, identified by filename.

Supports printf() formatting of strings. Return number of bytes written (excluding prepends), -1 if error.

◆ writeMyLog() [2/2]

int df::LogManager::writeMyLog ( std::string  filename,
int  log_level,
const char *  fmt,
  ... 
)

Write to custom logfile, identified by filename.

Only write if indicated log level >= LogManager log level. Supports printf() formatting of strings. Return number of bytes written (excluding prepends), -1 if error.

Member Data Documentation

◆ m_do_flush

bool df::LogManager::m_do_flush
private

True if flush to disk after write.

◆ m_file_list

std::map<std::string, FILE *> df::LogManager::m_file_list
private

List of custom logfiles.

◆ m_log_level

int df::LogManager::m_log_level
private

Logging level.

◆ m_log_step_count

bool df::LogManager::m_log_step_count
private

True if prepend step count.

◆ m_log_time_string

bool df::LogManager::m_log_time_string
private

True if prepend time.

◆ m_p_f

FILE* df::LogManager::m_p_f
private

Pointer to main logfile.