SynAPSE  0.6.0
Synergistic Analysis of Phase Space Evolution
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends
Pitch.hh
1 #ifndef PITCH_HH
2 #define PITCH_HH
3 
4 // C++ includes
5 #include <ostream>
6 #include <iostream>
7 #include <fstream>
8 #include <map>
9 #include <string>
10 #include <sstream>
11 
12 // Other includes
13 #include "Exception.hh"
14 #include "ExceptionLevel.hh"
15 
40 class Pitch {
41  public:
43  enum errorLevel {debug, info, warning, error, fatal, log};
44 
46  static std::ostream & mout();
47 
49  static std::ostream & mout(errorLevel level);
50 
52  static std::ostream & mout(Exceptions::exceptionLevel level);
53 
55  static void setAnOutput(errorLevel level, std::ostream& out);
56 
67  static void setOutputs(int verboseLevel, int logLevel);
68 
75  static void setStandardOutputs(int verboseLevel);
76 
82  static void setLog(int logLevel);
83 
85  static void closeLog();
86 
88  static std::string getLogName() { return logname; }
89 
91  static void setLogName(std::string aLogname) { logname = aLogname; }
92 
97  static void activateCout(bool isActive);
98 
100  static bool coutIsActive();
101 
106  static void activateCerr(bool isActive);
107 
109  static bool cerrIsActive();
110 
115  static void activateClog(bool isActive);
116 
118  static bool clogIsActive();
119 
121  static std::ostream& nullOut();
122 
124  static std::ostream& coutOut();
125 
127  static std::ostream& clogOut();
128 
130  static std::ostream& cerrOut();
131 
133  static std::string levelStr(errorLevel level);
134 
139  static void print(errorLevel level, std::string message);
140 
146  static void print(errorLevel level, std::string message, std::string func);
147 
148  private:
150  Pitch();
151 
155  static Pitch* getInstance();
156 
158  static void initialiseOutputs();
159 
161  static void setException();
162 
163  /* Static variables */
164  static std::map<errorLevel,
165  std::ostream*> output;
166  static std::ostream* voidout;
167  static std::ostream* stdout;
168  static std::ostream* stdlog;
169  static std::ostream* stderr;
170  static std::ofstream* logfile;
172  static const int default_log_level;
173  static std::string logname;
174  static Pitch* instance;
175 };
176 
177 #endif
static std::ostream & mout()
Shorthand that returns output to Pitch::mout(Pitch::debug)
Definition: Pitch.cc:21
static void activateCout(bool isActive)
Activate std::cout If isActive is false, redirects std::cout to /dev/null; if isActive is true...
Definition: Pitch.cc:100
static void print(errorLevel level, std::string message)
Prints a message with a certain severity level.
Definition: Pitch.cc:184
static Pitch * getInstance()
Ensures class is always instantiated whenever needed.
Definition: Pitch.cc:45
static const errorLevel default_error_level
The default error level.
Definition: Pitch.hh:171
static std::ostream * stdlog
ostream that points to std::log
Definition: Pitch.hh:168
static void setException()
Set Exception.
static bool coutIsActive()
Return false if std::cout points to voidout; else true.
Definition: Pitch.cc:108
static void activateCerr(bool isActive)
Activate std::cerr If isActive is false, redirects std::cerr to /dev/null; if isActive is true...
Definition: Pitch.cc:113
static void initialiseOutputs()
Setup outputs.
Definition: Pitch.cc:139
static std::ostream * voidout
Dummy ostream to send stuff to /dev/null.
Definition: Pitch.hh:166
static void setLog(int logLevel)
Set up the log file stream.
Definition: Pitch.cc:69
static Pitch * instance
Pointer to the singleton instance.
Definition: Pitch.hh:174
Pitch()
Constructor is called by any call to mout. Defines std::map output.
Definition: Pitch.cc:17
static void setOutputs(int verboseLevel, int logLevel)
Set the ostream for all items below "verboseLevel" to /dev/null or the log file (if the logLevel is s...
Definition: Pitch.cc:55
static void setStandardOutputs(int verboseLevel)
Turn on/off std::cout, std::cerr, std::clog Redirect the standard outputs to /dev/null or log file de...
Definition: Pitch.cc:93
static std::ostream * stderr
ostream that points to std::err
Definition: Pitch.hh:169
static std::string levelStr(errorLevel level)
Return the level of the error in plain english.
Definition: Pitch.cc:170
static std::ostream & clogOut()
Return ostream pointing to standard log (irrespective of verbose level)
Definition: Pitch.cc:160
static std::ostream & nullOut()
Return ostream pointing to /dev/null (irrespective of verbose level)
Definition: Pitch.cc:150
static std::map< errorLevel, std::ostream * > output
Links an ostream with each error level.
Definition: Pitch.hh:165
static std::ostream & cerrOut()
Return ostream pointing to standard error (irrespective of verb level)
Definition: Pitch.cc:165
static std::ofstream * logfile
ostream that points to a log file
Definition: Pitch.hh:170
exceptionLevel
ExceptionLevel enumerates the severity of the exception.
Definition: ExceptionLevel.hh:16
static void closeLog()
Close the log file and free the memory.
Definition: Pitch.cc:84
static bool cerrIsActive()
Return false if std::cerr points to voidout; else true.
Definition: Pitch.cc:121
Redirect output to std::out, std::cerr or file depending on severity.
Definition: Pitch.hh:40
static void setLogName(std::string aLogname)
Set the log file name.
Definition: Pitch.hh:91
static std::string logname
The log file name.
Definition: Pitch.hh:173
static std::string getLogName()
Return the log file name.
Definition: Pitch.hh:88
static bool clogIsActive()
Return false if std::clog points to voidout; else true.
Definition: Pitch.cc:134
static std::ostream * stdout
ostream that points to std::out
Definition: Pitch.hh:167
static std::ostream & coutOut()
Return ostream pointing to standard output (irrespective of verb level)
Definition: Pitch.cc:155
static void setAnOutput(errorLevel level, std::ostream &out)
Set the ostream for a given error level (Exceptions::Exception)
Definition: Pitch.cc:40
static const int default_log_level
The default log level.
Definition: Pitch.hh:172
static void activateClog(bool isActive)
Activate std::clog If isActive is false, redirects std::clog to /dev/null; if isActive is true...
Definition: Pitch.cc:126
errorLevel
Error level that determines where the output goes.
Definition: Pitch.hh:43