fluidvis
Log4SX.h
1 #ifndef _LOG4SX_LOG4SX_H_
2 #define _LOG4SX_LOG4SX_H_
3 
9 #include <export/Export.h>
10 #include <sx/Exception.h>
11 #include <string>
12 #include <fstream>
13 #include <vector>
14 #include <map>
15 #include <boost/timer.hpp>
16 using namespace std;
17 
18 namespace sx {
19 
30  enum LogLevel {
31  L_HARMLESS = 0,
32  L_WARNING = 1,
33  L_ERROR = 2,
34  L_FATAL_ERROR = 3,
35  L_NONE = 4
36  };
37 
44  class Level {
45  private:
46 
50  LogLevel level;
51 
52  public:
53 
62  EXL Level(LogLevel level);
63 
67  EXL Level(const Level &l);
68 
72  EXL Level &operator = (const Level &l);
73 
77  EXL LogLevel getLevel() const;
78  };
79 
88  class LogMarkup {
89  protected:
90 
94  string message;
95 
96  public:
97 
106  EXL LogMarkup(string message);
107 
111  EXL LogMarkup(const LogMarkup &lm);
112 
116  EXL LogMarkup &operator = (const LogMarkup &lm);
117 
121  EXL virtual ~LogMarkup();
122 
126  EXL string getMessage() const;
127 
128  };
129 
135  class Annotation {
136  private:
137 
141  string annotation;
142 
143  public:
144 
153  EXL Annotation(string annotation);
154 
158  EXL Annotation(const Annotation &a);
159 
163  EXL Annotation &operator = (const Annotation &a);
164 
168  EXL string getAnnotation() const;
169 
170  };
171 
184  class Logger {
185  private:
186 
193  static map<string,Logger *> loggers;
194 
201  static Logger *defaultLogger;
202 
212  static Logger *initDefaultLogger();
213 
217  Logger(const Logger &);
218 
222  Logger &operator = (const Logger &);
223 
224  protected:
225 
234 
241 
246  EXL Logger();
247 
252  bool takeMessage() const;
253 
254  public:
255 
259  EXL static string newLine();
260 
271  EXL static void addLogger(string ID, Logger *logger);
272 
281  EXL static void setDefaultLogger(string ID);
282 
288  EXL static Logger & get();
289 
297  EXL static void deleteLogger(string ID);
298 
302  EXL virtual ~Logger();
303 
307  EXL void setMinLevel(LogLevel level);
308 
312  EXL LogLevel getMinLevel() const;
313 
317  EXL LogLevel getLevel() const;
318 
327  EXL virtual Logger & operator << (const Level l);
328 
339  EXL virtual Logger & operator << (const LogMarkup m) = 0;
340 
352  EXL virtual Logger & operator << (const Annotation a) = 0;
353 
358  EXL virtual Logger & operator << (char value) = 0;
359 
364  EXL virtual Logger & operator << (unsigned char value) = 0;
365 
370  EXL virtual Logger & operator << (short value) = 0;
371 
376  EXL virtual Logger & operator << (unsigned short value) = 0;
377 
382  EXL virtual Logger & operator << (int value) = 0;
383 
388  EXL virtual Logger & operator << (unsigned int value) = 0;
389 
394  EXL virtual Logger & operator << (long value) = 0;
395 
400  EXL virtual Logger & operator << (unsigned long value) = 0;
401 
406  EXL virtual Logger & operator << (float value) = 0;
407 
412  EXL virtual Logger & operator << (double value) = 0;
413 
418  EXL virtual Logger & operator << (string value) = 0;
419 
420  };
421 
428  class ConsoleLogger: public Logger {
429  private:
430 
434  ConsoleLogger(const ConsoleLogger &);
435 
439  ConsoleLogger &operator = (const ConsoleLogger &);
440 
441 
442  public:
443 
447  EXL ConsoleLogger();
448 
452  EXL ~ConsoleLogger();
453 
457  EXL Logger &operator << (const Level level);
458 
465  EXL Logger & operator << (const LogMarkup m);
466 
473  EXL Logger & operator << (const Annotation a);
474 
480  EXL Logger & operator << (char value);
481 
487  EXL Logger & operator << (unsigned char value);
488 
494  EXL Logger & operator << (short value);
495 
501  EXL Logger & operator << (unsigned short value);
502 
508  EXL Logger & operator << (int value);
509 
515  EXL Logger & operator << (unsigned int value);
516 
522  EXL Logger & operator << (long value);
523 
529  EXL Logger & operator << (unsigned long value);
530 
536  EXL Logger & operator << (float value);
537 
543  EXL Logger & operator << (double value);
544 
550  EXL Logger & operator << (string value);
551  };
552 
559  class ListMarkup: public LogMarkup {
560  private:
561 
565  vector<char> chars;
566 
570  vector<unsigned char> uchars;
571 
575  vector<short> shorts;
576 
580  vector<unsigned short> ushorts;
581 
585  vector<int> ints;
586 
590  vector<unsigned int> uints;
591 
595  vector<long> longs;
596 
600  vector<unsigned long> ulongs;
601 
605  vector<float> floats;
606 
610  vector<double> doubles;
611 
615  vector<string> strings;
616 
620  vector<Annotation> annotations;
621 
622  public:
623 
629  EXL ListMarkup(string message);
630 
634  EXL ListMarkup(const ListMarkup &m);
635 
639  EXL ListMarkup &operator = (const ListMarkup &m);
640 
644  EXL ~ListMarkup();
645 
649  EXL vector<char> & getChars();
650 
654  EXL vector<unsigned char> & getUchars();
655 
659  EXL vector<short> & getShorts();
660 
664  EXL vector<unsigned short> & getUshorts();
665 
669  EXL vector<int> & getInts();
670 
674  EXL vector<unsigned int> & getUints();
675 
679  EXL vector<long> & getLongs();
680 
684  EXL vector<unsigned long> & getUlongs();
685 
689  EXL vector<float> & getFloats();
690 
694  EXL vector<double> & getDoubles();
695 
699  EXL vector<string> & getStrings();
700 
704  EXL vector<Annotation> & getAnnotations();
705 
706  };
707 
715  class ListLogger: public Logger {
716  private:
717 
723  ListMarkup *defaultMarkup;
724 
731  map<string,ListMarkup> markups;
732 
736  ListLogger(const ListLogger &);
737 
741  ListLogger &operator = (const ListLogger &);
742 
743  public:
744 
748  EXL ListLogger();
749 
753  EXL ~ListLogger();
754 
758  EXL Logger &operator << (const Level level);
759 
768  EXL Logger & operator << (const LogMarkup m);
769 
773  EXL Logger & operator << (const Annotation a);
774 
781  EXL Logger & operator << (char value);
782 
789  EXL Logger & operator << (unsigned char value);
790 
797  EXL Logger & operator << (short value);
798 
805  EXL Logger & operator << (unsigned short value);
806 
813  EXL Logger & operator << (int value);
814 
821  EXL Logger & operator << (unsigned int value);
822 
829  EXL Logger & operator << (long value);
830 
837  EXL Logger & operator << (unsigned long value);
838 
845  EXL Logger & operator << (float value);
846 
853  EXL Logger & operator << (double value);
854 
861  EXL Logger & operator << (string value);
862 
871  EXL map<string,ListMarkup> & getMarkups();
872 
883  EXL Annotation getAnnotationEntry(string ID, unsigned int index);
884 
895  EXL char getCharEntry(string ID, unsigned int index);
896 
907  EXL unsigned char getUcharEntry(string ID, unsigned int index);
908 
919  EXL short getShortEntry(string ID, unsigned int index);
920 
931  EXL unsigned short getUshortEntry(string ID, unsigned int index);
932 
943  EXL int getIntEntry(string ID, unsigned int index);
944 
955  EXL unsigned int getUintEntry(string ID, unsigned int index);
956 
967  EXL long getLongEntry(string ID, unsigned int index);
968 
979  EXL unsigned long getUlongEntry(string ID, unsigned int index);
980 
991  EXL float getFloatEntry(string ID, unsigned int index);
992 
1003  EXL double getDoubleEntry(string ID, unsigned int index);
1004 
1015  EXL string getStringEntry(string ID, unsigned int index);
1016 
1017  };
1018 
1023 
1035 
1043 
1050 
1051  };
1052 
1062  class FileLogger: public Logger {
1063  private:
1064 
1071  ofstream file;
1072 
1076  bool errorbit;
1077 
1082  FileLoggerState state;
1083 
1087  boost::timer timeMeasurement;
1088 
1092  string INTERNAL_TABLE_PRINT_FUNCTION();
1093  string INTERNAL_SEPARATE_ANNOTATION();
1094  string INTERNAL_FINISH_TABLE();
1095 
1099  FileLogger(const FileLogger &);
1100 
1104  FileLogger &operator = (const FileLogger &);
1105 
1106  public:
1107 
1113  EXL FileLogger(string filename);
1114 
1118  EXL ~FileLogger();
1119 
1124  EXL bool hasErrors() const;
1125 
1131  EXL void close();
1132 
1136  EXL Logger &operator << (const Level level);
1137 
1144  EXL Logger & operator << (const LogMarkup m);
1145 
1152  EXL Logger & operator << (const Annotation a);
1153 
1159  EXL Logger & operator << (char value);
1160 
1166  EXL Logger & operator << (unsigned char value);
1167 
1173  EXL Logger & operator << (short value);
1174 
1180  EXL Logger & operator << (unsigned short value);
1181 
1187  EXL Logger & operator << (int value);
1188 
1194  EXL Logger & operator << (unsigned int value);
1195 
1201  EXL Logger & operator << (long value);
1202 
1208  EXL Logger & operator << (unsigned long value);
1209 
1215  EXL Logger & operator << (float value);
1216 
1222  EXL Logger & operator << (double value);
1223 
1229  EXL Logger & operator << (string value);
1230  };
1231 
1232 }
1233 
1240 #ifdef _IS_LOGGING_
1241  #define SXout(MSG) sx::Logger::get() << MSG;
1242 #else
1243  #define SXout(MSG)
1244 #endif
1245 
1246 #endif
LogLevel
Definition: Log4SX.h:30
Definition: Log4SX.h:428
LogLevel minLevel
Definition: Log4SX.h:233
LogLevel level
Definition: Log4SX.h:240
Definition: Log4SX.h:1062
Definition: Log4SX.h:1049
FileLoggerState
Definition: Log4SX.h:1022
Definition: Log4SX.h:1034
Definition: Log4SX.h:559
Definition: Log4SX.h:88
Definition: Log4SX.h:184
Definition: Log4SX.h:715
Definition: Log4SX.h:1042
string message
Definition: Log4SX.h:94
Definition: Log4SX.h:44
Definition: Log4SX.h:135
Definition: Exception.h:13