Dragonfly 4.20
A text-based game engine
LogManager.h
1///
2/// The log manager
3///
4
5#ifndef __LOG_MANAGER_H__
6#define __LOG_MANAGER_H__
7
8// System includes.
9#include <stdio.h>
10#include <map>
11
12// Engine includes.
13#include "Manager.h"
14#include "utility.h"
15
16// Two-letter acronym for easier access to manager.
17#define LM df::LogManager::getInstance()
18
19namespace df {
20
21/// Default Dragonfly logfile.
22/// Override with DRAGONFLY_LOG environment variable.
23const std::string LOGFILE_DEFAULT = "dragonfly.log";
24
25class LogManager : public Manager {
26
27 private:
28 LogManager(); ///< Private since a singleton.
29 LogManager(LogManager const&); ///< Don't allow copy.
30 void operator=(LogManager const&);///< Don't allow assignment.
31 bool m_do_flush; ///< True if flush to disk after write.
32 int m_log_level; ///< Logging level.
33 bool m_log_time_string; ///< True if prepend time.
34 bool m_log_step_count; ///< True if prepend step count.
35 FILE *m_p_f; ///< Pointer to main logfile.
36 std::map <std::string, FILE *> m_file_list; ///< List of custom logfiles.
37
38 public:
39 /// If logfile is open, close it.
41
42 /// Get the one and only instance of the LogManager.
44
45 /// Start up LogManager (open main logfile, usually "dragonfly.log").
46 /// Return 0 if ok, else -1.
47 int startUp() override;
48
49 /// Shut down LogManager (close all logfiles).
50 void shutDown() override;
51
52 /// Write to logfile.
53 /// Supports printf() formatting of strings.
54 /// Return number of bytes written (excluding prepends), -1 if error.
55 int writeLog(const char *fmt, ...) const;
56
57 /// Write to logfile.
58 /// Only write if indicated log level >= LogManager log level.
59 /// Supports printf() formatting of strings.
60 /// Return number of bytes written (excluding prepends), -1 if error.
61 int writeLog(int log_level, const char *fmt, ...) const;
62
63 /// Write to custom logfile, identified by filename.
64 /// Supports printf() formatting of strings.
65 /// Return number of bytes written (excluding prepends), -1 if error.
66 int writeMyLog(std::string filename, const char *fmt, ...);
67
68 /// Write to custom logfile, identified by filename.
69 /// Only write if indicated log level >= LogManager log level.
70 /// Supports printf() formatting of strings.
71 /// Return number of bytes written (excluding prepends), -1 if error.
72 int writeMyLog(std::string filename, int log_level, const char *fmt, ...);
73
74 /// Set logging level.
75 void setLogLevel(int new_log_level);
76
77 /// Get logging level.
78 int getLogLevel() const;
79
80 /// Set flush of logfile after each write.
81 void setFlush(bool do_flush=true);
82
83 /// Flush the logfile.
84 void flush();
85
86 /// Set prepend time string to log messages.
87 void setLogTimeString(bool log_time_string=true);
88
89 /// Set prepend step count to log messages.
90 void setLogStepCount(bool log_step_count=true);
91};
92
93} // end of namespace df
94#endif // __LOG_MANAGER_H__
Definition: LogManager.h:25
int m_log_level
Logging level.
Definition: LogManager.h:32
void flush()
Flush the logfile.
int getLogLevel() const
Get logging level.
bool m_log_time_string
True if prepend time.
Definition: LogManager.h:33
void setLogTimeString(bool log_time_string=true)
Set prepend time string to log messages.
static LogManager & getInstance()
Get the one and only instance of the LogManager.
int writeLog(int log_level, const char *fmt,...) const
Write to logfile.
LogManager()
Private since a singleton.
void setLogStepCount(bool log_step_count=true)
Set prepend step count to log messages.
~LogManager()
If logfile is open, close it.
std::map< std::string, FILE * > m_file_list
List of custom logfiles.
Definition: LogManager.h:36
bool m_do_flush
True if flush to disk after write.
Definition: LogManager.h:31
LogManager(LogManager const &)
Don't allow copy.
int writeMyLog(std::string filename, const char *fmt,...)
Write to custom logfile, identified by filename.
bool m_log_step_count
True if prepend step count.
Definition: LogManager.h:34
void shutDown() override
Shut down LogManager (close all logfiles).
void setFlush(bool do_flush=true)
Set flush of logfile after each write.
int writeMyLog(std::string filename, int log_level, const char *fmt,...)
Write to custom logfile, identified by filename.
int startUp() override
Start up LogManager (open main logfile, usually "dragonfly.log").
FILE * m_p_f
Pointer to main logfile.
Definition: LogManager.h:35
int writeLog(const char *fmt,...) const
Write to logfile.
void operator=(LogManager const &)
Don't allow assignment.
void setLogLevel(int new_log_level)
Set logging level.
Definition: Manager.h:24
An animation for a sprite.
Definition: Animation.h:15
const std::string LOGFILE_DEFAULT
Default Dragonfly logfile.
Definition: LogManager.h:23