Sam Jaffe 6 years ago
parent
commit
58070c5e22
3 changed files with 18 additions and 8 deletions
  1. 6 0
      src/common.cxx
  2. 1 3
      src/common.h
  3. 11 5
      src/format.cxx

+ 6 - 0
src/common.cxx

@@ -40,3 +40,9 @@ std::string logging::timestamp() {
   std::strftime(buf, sizeof(buf), "%Y%m%dT%H%M%S", std::localtime(&round));
   return buf;
 }
+
+namespace logging {
+  std::ostream & operator<<(std::ostream & os, log_level l) {
+    return os << std::string(level_header(l));
+  }
+}

+ 1 - 3
src/common.h

@@ -16,7 +16,5 @@ namespace logging {
   timeval now();
   std::string timestamp();
 
-  std::ostream & operator<<(std::ostream & os, log_level l) {
-    return os << std::string(level_header(l));
-  }
+  std::ostream & operator<<(std::ostream & os, log_level l);
 }

+ 11 - 5
src/format.cxx

@@ -15,6 +15,7 @@
 #include <string>
 
 #include "logger/format.h"
+#include "common.h"
 #include "logger/logger.h"
 
 #if defined( _WIN32 )
@@ -49,7 +50,8 @@ namespace logging {
       return fmt_time(round, fmt.c_str());
     }
     
-    std::string fmt_time_with_milis(struct timeval round, std::string const & fmt) {
+    std::string fmt_time_with_milis(struct timeval round,
+                                    std::string const & fmt) {
       char buf[64] = {'\0'};
       snprintf(buf, sizeof(buf), fmt.c_str(), round.tv_usec);
       return fmt_time(round, buf);
@@ -59,8 +61,10 @@ namespace logging {
   
   string_generator parse_date_format_string( char const * str ) {
     char const * const end = strchr(str, '}');
-    if (end == nullptr)
-      throw format_parsing_exception{"expected date-format specifier to terminate"};
+    if (end == nullptr) {
+      std::string error_msg{"expected date-format specifier to terminate"};
+      throw format_parsing_exception{error_msg};
+    }
 
     char const * const has_millis = strstr( str, "%_ms");
     std::string fmtstring{str, end};
@@ -119,7 +123,8 @@ namespace logging {
         return lp.message;
       };
     } else {
-      throw unknown_format_specifier{std::string("unknown format character: '") + *next + "'"};
+      std::string error_msg{"unknown format character: '"};
+      throw unknown_format_specifier{error_msg + *next + "'"};
     }
   }
   
@@ -166,7 +171,8 @@ namespace logging {
     while ( ( next = std::strchr( curr, '%' ) + 1 )
            != nullptr ) {
       if ( end == next ) {
-        throw format_parsing_exception{"expected format specifier, got end of string"}; // TODO
+        std::string error_msg{"expected format specifier, got end of string"};
+        throw format_parsing_exception{error_msg}; // TODO
       }
       
       if ( curr < next -  1 ) {