Changeset 2296
- Timestamp:
- 26/09/2008 21:22:26 (3 years ago)
- Location:
- box/trunk/lib/common
- Files:
-
- 2 edited
-
Logging.cpp (modified) (2 diffs)
-
Logging.h (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
box/trunk/lib/common/Logging.cpp
r2279 r2296 223 223 } 224 224 225 Logger::Logger(Log::Level Level) 226 : mCurrentLevel(Level) 227 { 228 Logging::Add(this); 229 } 230 225 231 Logger::~Logger() 226 232 { … … 401 407 ::openlog(mName.c_str(), LOG_PID, LOG_LOCAL6); 402 408 } 409 410 bool FileLogger::Log(Log::Level Level, const std::string& rFile, 411 int line, std::string& rMessage) 412 { 413 if (Level > GetLevel()) 414 { 415 return true; 416 } 417 418 /* avoid infinite loop if this throws an exception */ 419 Logging::Remove(this); 420 421 std::ostringstream buf; 422 buf << FormatTime(GetCurrentBoxTime(), false); 423 buf << " "; 424 425 if (Level <= Log::FATAL) 426 { 427 buf << "[FATAL] "; 428 } 429 else if (Level <= Log::ERROR) 430 { 431 buf << "[ERROR] "; 432 } 433 else if (Level <= Log::WARNING) 434 { 435 buf << "[WARNING] "; 436 } 437 else if (Level <= Log::NOTICE) 438 { 439 buf << "[NOTICE] "; 440 } 441 else if (Level <= Log::INFO) 442 { 443 buf << "[INFO] "; 444 } 445 else if (Level <= Log::TRACE) 446 { 447 buf << "[TRACE] "; 448 } 449 450 buf << rMessage << "\n"; 451 std::string output = buf.str(); 452 453 #ifdef WIN32 454 ConvertUtf8ToConsole(output.c_str(), output); 455 #endif 456 457 mLogFile.Write(output.c_str(), output.length()); 458 459 Logging::Add(this); 460 return true; 461 } -
box/trunk/lib/common/Logging.h
r2279 r2296 15 15 #include <sstream> 16 16 #include <vector> 17 18 #include "FileStream.h" 17 19 18 20 /* … … 116 118 public: 117 119 Logger(); 120 Logger(Log::Level level); 118 121 virtual ~Logger(); 119 122 … … 269 272 }; 270 273 274 class FileLogger : public Logger 275 { 276 private: 277 FileStream mLogFile; 278 FileLogger(const FileLogger& forbidden) 279 : mLogFile("") { /* do not call */ } 280 281 public: 282 FileLogger(const std::string& rFileName, Log::Level Level) 283 : Logger(Level), 284 mLogFile(rFileName, O_WRONLY | O_CREAT | O_APPEND) 285 { } 286 287 virtual bool Log(Log::Level Level, const std::string& rFile, 288 int Line, std::string& rMessage); 289 290 virtual const char* GetType() { return "FileLogger"; } 291 virtual void SetProgramName(const std::string& rProgramName) { } 292 }; 293 271 294 #endif // LOGGING__H
Note: See TracChangeset
for help on using the changeset viewer.
