12 std::ostream *Log::out = &std::cerr;
14 std::ostream *Log::outInstance = NULL;
16 boost::mutex Log::mutex_;
18 std::string Log::msgColor = NUKLEI_LBLUE;
19 std::string Log::errorColor = NUKLEI_LRED;
20 std::string Log::nocolor = NUKLEI_NOCOLOR;
22 const std::string Log::TypeNames[] = {
"NEVER",
"FATAL",
"ERROR",
"WARN",
"INFO",
"LOG",
"DEBUG" };
24 void Log::setOutput(
const std::string &filename)
29 outInstance =
new std::ofstream(filename.c_str(), std::ios::out);
36 void Log::setOutput(std::ostream *stream)
43 void Log::log(
const char* file,
48 boost::unique_lock<boost::mutex> lock(mutex_);
49 LAST_OUTPUT_LINE_IS_PROGRESS =
false;
50 std::string color_start, color_stop;
51 if (INTERACTIVE_SHELL)
53 if (level <= WARN) color_start = errorColor;
54 else if (level <= LOG) color_start = msgColor;
55 else color_start = nocolor;
58 stream() << color_start << file <<
":" << line <<
59 " " << color_stop << TypeNames[level] <<
" - " <<
60 color_start << breakLines(s) <<
61 color_stop << std::endl;
64 std::string Log::breakLines(
const std::string &s)
66 std::string input =
"\n" + s +
"\n";
67 std::string output, line, token;
69 output.reserve(input.size());
72 const std::string lineBreak =
"\n ";
75 std::string ctxIndent;
79 const unsigned int width = 80;
81 for (std::string::const_iterator i = input.begin();
86 if (token.size() == 0)
89 else if (line.size() == 0)
94 else if (line.size() + 1 + token.size() < width - indent.size())
96 line.append(
" " + token );
99 else if (line.size() + 1 + token.size() == width - indent.size())
101 output.append( indent + line +
" " + token);
105 else if (line.size() + 1 + token.size() > width - indent.size())
109 output.append( indent + line );
112 if (token.size() >= width)
114 output.append( indent + token );
126 if (line.size() == 0 && token.size() != 0)
127 output.append(indent + token);
128 else if (line.size() + 1 + token.size() <= width - indent.size())
130 output.append( indent + line +
" " + token );
134 output.append( indent + line + indent + token );
139 for (i++; i != input.end(); i++)
141 if (*i ==
' ') ctxIndent.append(
" ");
144 indent = lineBreak + ctxIndent;