diff --git a/src/log.cpp b/src/log.cpp old mode 100644 new mode 100755 index fe1459f..b3de3e9 --- a/src/log.cpp +++ b/src/log.cpp @@ -33,7 +33,7 @@ namespace gz { std::mutex Log::mtx; #endif Log::Log(std::string logfile, bool showLog, bool storeLog, std::string&& prefix_, Color prefixColor, bool clearLogfileOnRestart, unsigned int writeAfterLines) - : showLog(showLog), storeLog(storeLog), prefixColor(prefixColor), prefix(prefix_ + ": "), prefixLength(prefix.size() + LOG_TIMESTAMP_CHAR_COUNT - 1), writeToFileAfterLines(writeAfterLines) { + : iter(0), writeToFileAfterLines(writeAfterLines), showLog(showLog), storeLog(storeLog), prefixColor(prefixColor), prefix(prefix_ + ": "), prefixLength(prefix.size() + LOG_TIMESTAMP_CHAR_COUNT - 1) { // get absolute path to the logfile fs::path logpath(logfile); if (!logpath.is_absolute()) { @@ -43,7 +43,7 @@ namespace gz { if (!fs::is_directory(logpath.parent_path())) { fs::create_directory(logpath.parent_path()); } - logFile = std::move(logpath.string()); + logFile = logpath.string(); // if clearLogfileOnRestart, open the file to clear it if (clearLogfileOnRestart and fs::is_regular_file(logfile)) { @@ -52,7 +52,7 @@ namespace gz { } if (writeToFileAfterLines == 0) { writeToFileAfterLines = 1; } - logLines.resize(writeAfterLines); + logLines.resize(writeToFileAfterLines); // reserve memory for strings if (LOG_RESERVE_STRING_SIZE > 0) { for (size_t i = 0; i < logLines.size(); i++) { @@ -74,7 +74,6 @@ namespace gz { std::time_t t = std::time(0); struct std::tm *tmp; tmp = std::localtime(&t); - // stores the date and time in time: yyyy-mm-dd hh:mm:ss: std::strftime(time, sizeof(time), "%F %T: ", tmp); } diff --git a/src/log.hpp b/src/log.hpp old mode 100644 new mode 100755 index 0e5d276..58bc7ce --- a/src/log.hpp +++ b/src/log.hpp @@ -29,10 +29,11 @@ namespace gz { // // CONCEPTS // - /// is appendable to std::string + /// is (similar or convertible to) std::string template - /* concept Stringy = std::same_as || std::convertible_to; */ - concept Stringy = requires(T t, std::string s) { s += t; }; + concept Stringy = std::same_as || std::convertible_to; + /// is appendable to std::string + /* concept Stringy = requires(T t, std::string s) { s += t; }; */ /// has .to_string() member template @@ -57,7 +58,11 @@ namespace gz { /// Type having printable .x and .y members template concept Vector2Printable = !Printable && - requires(T t) { { t.x } -> Printable; { t.y } -> Printable; }; + requires(T t) { + { t.x } -> Printable; + { t.y } -> Printable; + requires sizeof(t.x) * 2 == sizeof(T); + }; /// Pair having printable elements template @@ -111,8 +116,7 @@ namespace gz { * 1-7 include for example: * - int, float, bool... * - std::vector, std::list - * - std::map> if A.to_string() returns a string - * - ... + * - std::map> if A.to_string() returns a string - ... */ template concept Logable = LogableNotPointer || LogableSmartPointer; @@ -179,7 +183,8 @@ class Log { #ifdef LOG_MULTITHREAD mtx.lock(); #endif - logLines[iter] = getTime(); + getTime(); + logLines[iter] = time; logLines[iter] += prefix; vlog(" ", std::forward(args)...); logLines[iter] += "\n"; @@ -244,7 +249,7 @@ class Log { mtx.lock(); #endif getTime(); - logLines[iter] = time; + logLines[iter] = std::string(time); logLines[iter] += prefix + ": " + type + ": "; vlog(" ", std::forward(args)...); logLines[iter] += "\n"; @@ -336,6 +341,7 @@ class Log { for (auto it = t.begin(); it != t.end(); it++) { vlog(", ", *it); } + logLines[iter].erase(logLines[iter].size() - 2); logLines[iter] += "]"; logLines[iter] += appendChars; vlog(" ", std::forward< Args>(args)...); @@ -367,7 +373,7 @@ class Log { /// Where the lines are stored std::vector logLines; /// The current position in logLines - size_t iter; + size_t iter = 0; /// When iter reaches writeToFileAfterLines, write log to file unsigned int writeToFileAfterLines; /// Absolute path to the logfile