Dragonfly  4.3
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 
19 namespace df {
20 
21 const std::string LOGFILE_DEFAULT = "dragonfly.log";
22 
23 class LogManager : public Manager {
24 
25  private:
26  LogManager(); ///< Private since a singleton.
27  LogManager(LogManager const&); ///< Don't allow copy.
28  void operator=(LogManager const&);///< Don't allow assignment.
29  bool m_do_flush; ///< True if flush to disk after write.
30  int m_log_level; ///< Logging level.
31  bool m_log_time_string; ///< True if prepend time.
32  bool m_log_step_count; ///< True if prepend step count.
33  FILE *m_p_f; ///< Pointer to main logfile.
34  std::map <std::string, FILE *> m_file_list; ///< List of custom logfiles.
35 
36  public:
37  /// If logfile is open, close it.
38  ~LogManager();
39 
40  /// Get the one and only instance of the LogManager.
41  static LogManager &getInstance();
42 
43  /// Start up LogManager (open main logfile, usually "dragonfly.log").
44  int startUp();
45 
46  /// Shut down LogManager (close all logfiles).
47  void shutDown();
48 
49  /// Write to logfile.
50  /// Supports printf() formatting of strings.
51  /// Return number of bytes written (excluding prepends), -1 if error.
52  int writeLog(const char *fmt, ...) const;
53 
54  /// Write to logfile.
55  /// Only write if indicated log level >= LogManager log level.
56  /// Supports printf() formatting of strings.
57  /// Return number of bytes written (excluding prepends), -1 if error.
58  int writeLog(int log_level, const char *fmt, ...) const;
59 
60  /// Write to custom logfile, identified by filename.
61  /// Supports printf() formatting of strings.
62  /// Return number of bytes written (excluding prepends), -1 if error.
63  int writeMyLog(std::string filename, const char *fmt, ...);
64 
65  /// Write to custom logfile, identified by filename.
66  /// Only write if indicated log level >= LogManager log level.
67  /// Supports printf() formatting of strings.
68  /// Return number of bytes written (excluding prepends), -1 if error.
69  int writeMyLog(std::string filename, int log_level, const char *fmt, ...);
70 
71  /// Set logging level.
72  void setLogLevel(int new_log_level);
73 
74  /// Get logging level.
75  int getLogLevel() const;
76 
77  /// Set flush of logfile after each write.
78  void setFlush(bool do_flush=true);
79 
80  /// Set prepend time string to log messages.
81  void setLogTimeString(bool log_time_string=true);
82 
83  /// Set prepend step count to log messages.
84  void setLogStepCount(bool log_step_count=true);
85 };
86 
87 } // end of namespace df
88 #endif // __LOG_MANAGER_H__
void operator=(LogManager const &)
Don&#39;t allow assignment.
~LogManager()
If logfile is open, close it.
int writeLog(const char *fmt,...) const
Write to logfile.
bool m_do_flush
True if flush to disk after write.
Definition: LogManager.h:29
void setLogTimeString(bool log_time_string=true)
Set prepend time string to log messages.
int getLogLevel() const
Get logging level.
int writeMyLog(std::string filename, const char *fmt,...)
Write to custom logfile, identified by filename.
static LogManager & getInstance()
Get the one and only instance of the LogManager.
bool m_log_step_count
True if prepend step count.
Definition: LogManager.h:32
FILE * m_p_f
Pointer to main logfile.
Definition: LogManager.h:33
void shutDown()
Shut down LogManager (close all logfiles).
A 2-d bounding box.
Definition: Box.h:10
int m_log_level
Logging level.
Definition: LogManager.h:30
bool m_log_time_string
True if prepend time.
Definition: LogManager.h:31
void setLogLevel(int new_log_level)
Set logging level.
Definition: Manager.h:20
int startUp()
Start up LogManager (open main logfile, usually "dragonfly.log").
LogManager()
Private since a singleton.
Definition: LogManager.h:23
std::map< std::string, FILE * > m_file_list
List of custom logfiles.
Definition: LogManager.h:34
void setLogStepCount(bool log_step_count=true)
Set prepend step count to log messages.
void setFlush(bool do_flush=true)
Set flush of logfile after each write.