154{
156 if (g_threshold > priority) {
157 return 0;
158 }
160 if (g_date.getDay() != date.getDay()) {
161 g_stream.close();
162 open();
163 }
164 std::stringstream ss;
165 ss << "[" << date.toString();
166 std::string color = "\x1b[49m\x1b[39m";
167 switch (priority) {
168 case DEBUG: color = "\x1b[49m\x1b[39m"; ss << "] [DEBUG] "; break;
169 case INFO: color = "\x1b[49m\x1b[32m"; ss << "] [INFO] "; break;
170 case NOTICE: color = "\x1b[49m\x1b[34m"; ss << "] [NOTICE] "; break;
171 case WARNING: color = "\x1b[49m\x1b[35m"; ss << "] [WARNING] "; break;
172 case ERROR: color = "\x1b[49m\x1b[31m"; ss << "] [ERROR] "; break;
173 case FATAL: color = "\x1b[41m\x1b[37m"; ss << "] [FATAL] "; break;
174 default: ss << "] [UNKNOWN] "; break;
175 }
176 static char* s = new char[1024 * 1024 * 5];
177 vsnprintf(s, 1024 * 1024 * 5, msg.c_str(), ap);
178 ss << s << std::endl;
179 std::string str = ss.str();
180 std::cerr << color << str << "\x1b[49m\x1b[39m";
181 if (g_opened) {
182 g_stream << str;
183 g_stream.flush();
184 g_filesize += str.size();
185 }
186 return (int) str.size();
187}
Lock Guard for a Mutex instance.