# HG changeset patch # User Sebastien Jodogne # Date 1445420751 -7200 # Node ID b6f656a0bf2c1c11233a36da1bde73630e4298ec # Parent bc34c69b594a6385ccf694f6cfb1542fffdff613 "--logdir" creates a single log file instead of 3 separate files for errors/warnings/infos diff -r bc34c69b594a -r b6f656a0bf2c Core/Logging.cpp --- a/Core/Logging.cpp Wed Oct 21 10:34:29 2015 +0200 +++ b/Core/Logging.cpp Wed Oct 21 11:45:51 2015 +0200 @@ -144,9 +144,7 @@ std::ostream* warning_; std::ostream* info_; - std::auto_ptr errorFile_; - std::auto_ptr warningFile_; - std::auto_ptr infoFile_; + std::auto_ptr file_; LoggingState() : infoEnabled_(false), @@ -172,14 +170,14 @@ { static void GetLogPath(boost::filesystem::path& log, boost::filesystem::path& link, - const char* level, + const std::string& suffix, const std::string& directory) { /** From Google Log documentation: Unless otherwise specified, logs will be written to the filename - "...log..", + "...log.", followed by the date, time, and pid (you can't prevent the date, time, and pid from being in the filename). @@ -208,21 +206,17 @@ std::string programName = exe.filename().replace_extension("").string(); - log = (root / (programName + ".log." + - std::string(level) + "." + - std::string(date))); - - link = (root / (programName + "." + std::string(level))); + log = (root / (programName + ".log" + suffix + "." + std::string(date))); + link = (root / (programName + ".log" + suffix)); } - static void PrepareLogFile(std::ostream*& stream, - std::auto_ptr& file, - const char* level, + static void PrepareLogFile(std::auto_ptr& file, + const std::string& suffix, const std::string& directory) { boost::filesystem::path log, link; - GetLogPath(log, link, level, directory); + GetLogPath(log, link, suffix, directory); #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) boost::filesystem::remove(link); @@ -230,7 +224,6 @@ #endif file.reset(new std::ofstream(log.string().c_str())); - stream = file.get(); } @@ -273,9 +266,11 @@ boost::mutex::scoped_lock lock(loggingMutex_); assert(loggingState_.get() != NULL); - PrepareLogFile(loggingState_->error_, loggingState_->errorFile_, "ERROR", path); - PrepareLogFile(loggingState_->warning_, loggingState_->warningFile_, "WARNING", path); - PrepareLogFile(loggingState_->info_, loggingState_->infoFile_, "INFO", path); + PrepareLogFile(loggingState_->file_, "" /* no suffix */, path); + + loggingState_->warning_ = loggingState_->file_.get(); + loggingState_->error_ = loggingState_->file_.get(); + loggingState_->info_ = loggingState_->file_.get(); } InternalLogger::InternalLogger(const char* level, diff -r bc34c69b594a -r b6f656a0bf2c NEWS --- a/NEWS Wed Oct 21 10:34:29 2015 +0200 +++ b/NEWS Wed Oct 21 11:45:51 2015 +0200 @@ -28,6 +28,7 @@ * "/system" URI gives information about the plugins used for storage area and DB back-end * Plugin callbacks should now return explicit "OrthancPluginErrorCode" instead of integers * "/tools/create-dicom" can create tags with unknown VR +* "--logdir" creates a single log file instead of 3 separate files for errors/warnings/infos Version 0.9.4 (2015/09/16)