00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "Logger.h"
00021 #include <iostream>
00022 #include <string>
00023
00024 using namespace std;
00025
00026 namespace mdw
00027 {
00028 Logger *Logger::_instance;
00029 Logger::Logger (Stream &s) : _underlyer (s), _stream (*this), _start (true)
00030 {
00031 }
00032
00033 Logger::~Logger()
00034 {
00035 }
00036
00037 void Logger::initialise (Stream &s)
00038 {
00039 _instance = new Logger (s);
00040 _instance->init();
00041 }
00042 Logger &Logger::getInstance()
00043 {
00044 }
00045
00046 void Logger::setDebugMode (const string &className, bool active, int level)
00047 {
00048 }
00049
00050 void Logger::log (LogType_t type, const std::string &message, int level, bool end, const char* file, int line)
00051 {
00052 log (type, message.data(), message.size(), level, end, file, line);
00053 }
00054
00055 void Logger::log (LogType_t type, const char *buff, int size, int level, bool end, const char* file, int line)
00056 {
00057 if (_start)
00058 {
00059 logStart (type, file, line);
00060 }
00061 _underlyer.output (buff, size);
00062 _start = end;
00063 }
00064
00065 void Logger::logStart (LogType_t type, const char* file, int line)
00066 {
00067
00068 switch (type)
00069 {
00070 case Fatal_e:
00071 _underlyer << " FATAL ";
00072 break;
00073 case Error_e:
00074 _underlyer << " ERROR ";
00075 break;
00076 case Warn_e:
00077 _underlyer << " WARN ";
00078 break;
00079 case Info_e:
00080 _underlyer << " INFO ";
00081 break;
00082 case Debug_e:
00083 _underlyer << " DEBUG ";
00084 break;
00085 }
00086 _underlyer << file << ":" << line << " ";
00087 }
00088
00089 void Logger::init()
00090 {
00091 }
00092
00093 Logger::LogStream &Logger::getStreamInt()
00094 {
00095 return _stream;
00096 }
00097
00098 Stream &Logger::getStream()
00099 {
00100 return _underlyer;
00101 }
00102
00103 }