jubilant-funicular
Logger.h
1 #ifndef NTA_LOGGER_H_INCLUDED
2 #define NTA_LOGGER_H_INCLUDED
3 
4 #include <fstream>
5 
6 #include "nta/Errors.h"
7 #include "nta/format.h"
8 
9 namespace nta {
11  class Logger {
12  private:
14  static std::ofstream m_logFile;
16  static std::ostream* m_secondLog;
17  static size_t m_tabs;
18  static const size_t TAB_SIZE;
19  public:
21  static void createLog();
23  static void useSecondLog(std::ostream& stream) { m_secondLog = std::addressof(stream); }
25  static void unuseSecondLog() { m_secondLog = nullptr; }
27  static void writeToLog(crstring entry);
28  template<typename... Args>
29  static void writeToLog(crstring entry, Args&&... args) {
30  writeToLog(utils::format(entry, std::forward<Args>(args)...));
31  }
33  static Error writeErrorToLog(crstring error, ErrorType type = OTHER);
34  template<typename... Args>
35  static Error writeErrorToLog(ErrorType type, crstring err, Args&&... args) {
36  return writeErrorToLog(utils::format(err, std::forward<Args>(args)...), type);
37  }
39  static void indent(size_t tab_size = TAB_SIZE);
41  static void unindent(size_t tab_size = TAB_SIZE);
42  };
44  class ScopeLog {
45  private:
46  const std::string on_exit;
47  public:
48  ScopeLog(crstring entry, crstring exit);
49  ~ScopeLog();
50  };
51 }
52 
53 #endif // NTA_LOGGER_H_INCLUDED
nta::Logger
stores program information in internal and external logs
Definition: Logger.h:11
nta::ScopeLog
Simple RAII type for logging entry/exit of scope.
Definition: Logger.h:44
nta::Logger::writeToLog
static void writeToLog(crstring entry)
writes an entry in the log
Definition: Logger.cpp:17
nta::Logger::unindent
static void unindent(size_t tab_size=TAB_SIZE)
unindents entries
Definition: Logger.cpp:46
nta::utils::format
std::string format(const std::string &fmt, Args &&... args)
Definition: format.h:88
nta::Logger::useSecondLog
static void useSecondLog(std::ostream &stream)
Sets a secondary stream for logging.
Definition: Logger.h:23
nta
Definition: Animation2D.h:6
nta::ErrorType
ErrorType
Types of Error.
Definition: Errors.h:13
nta::Logger::m_logFile
static std::ofstream m_logFile
the file that keeps the external log
Definition: Logger.h:14
nta::Logger::writeErrorToLog
static Error writeErrorToLog(crstring error, ErrorType type=OTHER)
writes entry in log and then notifies ErrorManager
Definition: Logger.cpp:31
nta::Logger::createLog
static void createLog()
creates the log
Definition: Logger.cpp:12
nta::Logger::unuseSecondLog
static void unuseSecondLog()
Stop using a secondary stream.
Definition: Logger.h:25
nta::Logger::m_secondLog
static std::ostream * m_secondLog
Optional secondary stream to log data to as well.
Definition: Logger.h:16
nta::Logger::indent
static void indent(size_t tab_size=TAB_SIZE)
indents entries
Definition: Logger.cpp:43