FileOutput.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 using namespace mermaid::support::logging;
00035
00036 FileOutput::FileOutput (std::string fileName) :
00037 fileName_ (fileName),
00038 fileStream_ (fileName.c_str(), std::ios::app)
00039 {
00040 fileStream_.fill ('0');
00041 }
00042
00043 shared_ptr<FileOutput> FileOutput::build (std::string fileName)
00044 {
00045 return shared_ptr<FileOutput> (new FileOutput (fileName));
00046 }
00047
00048 void FileOutput::outputMessage (const LogMessage& logMessage)
00049 {
00050
00051 time_t timep = logMessage.getTime();
00052 struct tm * t = gmtime (&timep);
00053 fileStream_.width (2);
00054 fileStream_ << t->tm_mday << "/";
00055 fileStream_.width (2);
00056 fileStream_ << t->tm_mon << "/";
00057 fileStream_.width (4);
00058 fileStream_ << 1900 + t->tm_year << "-";
00059 fileStream_.width (2);
00060 fileStream_ << t->tm_hour << ":";
00061 fileStream_.width (2);
00062 fileStream_ << t->tm_min << ":";
00063 fileStream_.width (2);
00064 fileStream_ << t->tm_sec << " ";
00065
00066
00067 if (logMessage.getPrefix().size() > 0) {
00068 fileStream_ << logMessage.getPrefix() << ": ";
00069 }
00070
00071
00072 switch (logMessage.getLogLevel()) {
00073 case LOG_ERROR:
00074 fileStream_ << "ERROR: ";
00075 break;
00076 case LOG_WARN:
00077 fileStream_ << "WARN: ";
00078 break;
00079 case LOG_INFO:
00080 fileStream_ << "INFO: ";
00081 break;
00082 case LOG_BEGIN:
00083 for (int i = 0; i < logMessage.getIndentation(); i++) {
00084 fileStream_ << "| ";
00085 }
00086 fileStream_ << "/---------- ";
00087 break;
00088 case LOG_SEPARATOR:
00089 if (logMessage.getIndentation() > 0) {
00090 for (int i = 0; i < (logMessage.getIndentation() - 1); i++) {
00091 fileStream_ << "| ";
00092 }
00093 fileStream_ << "+-";
00094 }
00095 fileStream_ << "--------- ";
00096 break;
00097 case LOG_STEP:
00098 for (int i = 0; i < logMessage.getIndentation(); i++) {
00099 fileStream_ << "| ";
00100 }
00101 break;
00102 case LOG_END:
00103 for (int i = 0; i < logMessage.getIndentation(); i++) {
00104 fileStream_ << "| ";
00105 }
00106 fileStream_ << "\\---------- ";
00107 break;
00108 }
00109
00110
00111 fileStream_ << logMessage.getMessage();
00112
00113
00114 fileStream_ << std::endl;
00115 fileStream_.flush();
00116 }