From 3ab7c92d360927f14f5f13d8c944f428455532a6 Mon Sep 17 00:00:00 2001 From: Eryn Wells Date: Sat, 2 Aug 2014 00:27:50 -0700 Subject: [PATCH] Duplicate logging symbols :( --- src/SConscript | 1 + src/log.cc | 119 +++++++++++++++++++++++++++++++++++++++++++++++++ src/log.hh | 103 +++--------------------------------------- 3 files changed, 125 insertions(+), 98 deletions(-) create mode 100644 src/log.cc diff --git a/src/SConscript b/src/SConscript index e4a52eb..370bd02 100644 --- a/src/SConscript +++ b/src/SConscript @@ -20,6 +20,7 @@ files = [ 'basics.cc', 'camera.cc', 'light.cc', + 'log.cc', 'material.cc', 'object.cc', 'objectBox.cc', diff --git a/src/log.cc b/src/log.cc new file mode 100644 index 0000000..91ce299 --- /dev/null +++ b/src/log.cc @@ -0,0 +1,119 @@ +/* log.cc + * vim: set tw=80: + * Eryn Wells + */ + +#include "log.hh" + + +namespace charles { +namespace log { + +/** Useful predefined levels. */ +namespace level { + const unsigned int Error = 10; + const unsigned int Warning = 20; + const unsigned int Info = 30; + const unsigned int Debug = 40; + const unsigned int Trace = 50; +}; + + +unsigned int Log::sLevel = 0; +std::ostream* Log::sOutput = nullptr; +Log::LoggerMap Log::sLoggers; + + +/* static */ void +Log::Init(const std::string& filename, + unsigned int level) +{ + assert(sOutput == nullptr); + sOutput = new std::ofstream(filename); + sLevel = level; + + Log("ROOT", 1) << "Opening log file " << filename; + Log("ROOT", 1) << "Log level set to " << sLevel; +} + + +/* static */ void +Log::Close() +{ + assert(sOutput != nullptr); + delete sOutput; + sOutput = nullptr; +} + + +/** + * Construct a Log object. + * + * @param [in] name The name of the log stream. If this name hasn't been + * seen before, a new one will be created for you. + * @param [in] level The level. If this is higher than the level of the log + * stream, nothing will be output. + */ +Log::Log(const std::string& name, + unsigned int level) + : mName(name), + mLevel(level), + mOutput(Log::GetLogger(name)) +{ + using namespace std::chrono; + + /* Write a log message leader: "