diff options
author | Determinant <[email protected]> | 2018-07-03 20:28:34 -0400 |
---|---|---|
committer | Determinant <[email protected]> | 2018-07-03 20:28:34 -0400 |
commit | 9e89c3b330a8d7cc4fb256411b755c126ba37ec3 (patch) | |
tree | 5808c13078322e35bd7a3992122dad91c1125680 | |
parent | 2b956e784e740853a19ed8856f296a166a270e62 (diff) |
...
-rw-r--r-- | CMakeLists.txt | 4 | ||||
-rw-r--r-- | include/salticidae/util.h | 10 | ||||
-rw-r--r-- | src/util.cpp | 10 |
3 files changed, 14 insertions, 10 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 5931322..b358842 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -41,9 +41,9 @@ if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) endif() if(CMAKE_BUILD_TYPE STREQUAL "Debug") - add_definitions(-DHOTSTUFF_DEBUG_LOG) + add_definitions(-DSALTICIDAE_DEBUG_LOG) elseif(CMAKE_BUILD_TYPE STREQUAL "Release") - add_definitions(-DHOTSTUFF_NORMAL_LOG) + add_definitions(-DSALTICIDAE_NORMAL_LOG) endif() #set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -no-pie -pg") diff --git a/include/salticidae/util.h b/include/salticidae/util.h index 19d87cb..e5d653a 100644 --- a/include/salticidae/util.h +++ b/include/salticidae/util.h @@ -51,12 +51,16 @@ class Logger { protected: FILE *output; bool opened; + const char *prefix; void write(const char *tag, const char *fmt, va_list ap); public: - Logger() : output(stderr), opened(false) {} - Logger(FILE *f) : output(f) {} - Logger(const char *filename): opened(true) { + Logger(const char *prefix): + output(stderr), opened(false), prefix(prefix) {} + Logger(const char *prefix, FILE *f): + output(f), opened(false), prefix(prefix) {} + Logger(const char *prefix, const char *filename): + opened(true), prefix(prefix) { if ((output = fopen(filename, "w")) == nullptr) throw SalticidaeError("logger cannot open file"); } diff --git a/src/util.cpp b/src/util.cpp index 9a24a8c..9ea3b83 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -85,7 +85,7 @@ SalticidaeError::operator std::string() const { } void Logger::write(const char *tag, const char *fmt, va_list ap) { - fprintf(output, "%s [%s] ", get_current_datetime().c_str(), tag); + fprintf(output, "%s [%s %s] ", get_current_datetime().c_str(), prefix, tag); vfprintf(output, fmt, ap); fprintf(output, "\n"); } @@ -100,24 +100,24 @@ void Logger::debug(const char *fmt, ...) { void Logger::info(const char *fmt, ...) { va_list ap; va_start(ap, fmt); - write("salticidae info", fmt, ap); + write("info", fmt, ap); va_end(ap); } void Logger::warning(const char *fmt, ...) { va_list ap; va_start(ap, fmt); - write("salticidae warn", fmt, ap); + write("warn", fmt, ap); va_end(ap); } void Logger::error(const char *fmt, ...) { va_list ap; va_start(ap, fmt); - write("salticida error", fmt, ap); + write("error", fmt, ap); va_end(ap); } -Logger logger; +Logger logger("salticidae"); void ElapsedTime::start() { struct timezone tz; |