TerminalOutput.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include "config.h"
00031
00032 #include "Logger.hpp"
00033
00034 #include <iostream>
00035
00036 using namespace mermaid::support::logging;
00037
00038 using std::cerr;
00039
00040 namespace
00041 {
00042 int to_init_flag = 0;
00043 }
00044
00045 shared_ptr<ThreadSafeOutput> TerminalOutput::instance_;
00046
00047 shared_ptr<ThreadSafeOutput> TerminalOutput::build()
00048 {
00049 if (to_init_flag == 0) {
00050 instance_ = ThreadSafeOutput::build (shared_ptr<TerminalOutput> (new TerminalOutput()));
00051 to_init_flag = 1;
00052 }
00053 return instance_;
00054 }
00055
00056 void TerminalOutput::outputMessage (const LogMessage& logMessage)
00057 {
00058
00059 time_t timep = logMessage.getTime();
00060 struct tm * t = gmtime (&timep);
00061 char prevFill = cerr.fill();
00062 cerr.fill ('0');
00063 cerr.width (2);
00064 cerr << t->tm_hour << ":";
00065 cerr.width (2);
00066 cerr << t->tm_min << ":";
00067 cerr.width (2);
00068 cerr << t->tm_sec << " ";
00069 cerr.fill (prevFill);
00070
00071
00072 if (logMessage.getPrefix().size() > 0) {
00073 cerr << logMessage.getPrefix() << ": ";
00074 }
00075
00076
00077 switch (logMessage.getLogLevel()) {
00078 case LOG_ERROR:
00079 cerr << "ERROR: ";
00080 break;
00081 case LOG_WARN:
00082 cerr << "WARN: ";
00083 break;
00084 case LOG_INFO:
00085 cerr << "INFO: ";
00086 break;
00087 case LOG_BEGIN:
00088 for (int i = 0; i < logMessage.getIndentation(); i++) {
00089 cerr << "| ";
00090 }
00091 cerr << "/---------- ";
00092 break;
00093 case LOG_SEPARATOR:
00094 if (logMessage.getIndentation() > 0) {
00095 for (int i = 0; i < (logMessage.getIndentation() - 1); i++) {
00096 cerr << "| ";
00097 }
00098 cerr << "+-";
00099 }
00100 cerr << "--------- ";
00101 break;
00102 case LOG_STEP:
00103 for (int i = 0; i < logMessage.getIndentation(); i++) {
00104 cerr << "| ";
00105 }
00106 break;
00107 case LOG_END:
00108 for (int i = 0; i < logMessage.getIndentation(); i++) {
00109 cerr << "| ";
00110 }
00111 cerr << "\\---------- ";
00112 break;
00113 }
00114
00115
00116 cerr << logMessage.getMessage();
00117
00118
00119 cerr << std::endl;
00120 cerr.flush();
00121 }