Explorar o código

Fixing various bugs in unit tests:
- Treated microseconds as milliseconds
- Add a default date format
- Fix ISO8601 format code
- Fix starting '{' in custom date format code
- Fix closing '}' in date formatting
- Fix %% parsing for following tokens.

Sam Jaffe %!s(int64=6) %!d(string=hai) anos
pai
achega
9f9b203461
Modificáronse 1 ficheiros con 5 adicións e 6 borrados
  1. 5 6
      src/format.cxx

+ 5 - 6
src/format.cxx

@@ -43,7 +43,7 @@ namespace logging {
     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);
+      snprintf(buf, sizeof(buf), fmt.c_str(), round.tv_usec/1000);
       return fmt_time(round, buf);
     }
   }
@@ -78,15 +78,15 @@ namespace logging {
 #define is( chr ) *next == chr
 #define is_string( str ) ! strncmp(next, str, strlen(str))
   string_generator date_token(char const * next) {
-    std::string predef_format;
+    std::string predef_format = "%%Y-%%m-%%d %%H:%%M:%%S,%.03d";
     if ( is_string("{ISO8601}")) {
-      predef_format = "%%Y-%%m-%%d %%H:%%M:%%S,%.03d";
+      predef_format = "%%Y-%%m-%%dT%%H:%%M:%%S.%.03dZ";
     } else if (is_string("{ABSOLUTE}")) {
       predef_format = "%%H:%%M:%%S,%.04d";
     } else if (is_string("{DATE}")) {
       predef_format = "%%d %%b %%Y %%H:%%M:%%S,%.04d";
     } else if (is('{')) {
-      return parse_date_format_string(next);
+      return parse_date_format_string(next+1);
     }
     return [=](logpacket const & lp ){
       return fmt_time_with_milis(lp.time, predef_format);
@@ -171,12 +171,11 @@ namespace logging {
 
       if (is('d')) {
         ++next;
-        if (is('{')) curr = std::strchr(next, '}');
         out.gen.push_back(convert(date_token(next)));
+        if (is('{')) next = std::strchr(next, '}');
       } else if (is('n')) {
         out.gen.push_back(convert(string_token(NEWLINE)));
       } else if (is('%')) {
-        ++next;
         out.gen.push_back(convert(string_token("%")));
       } else if (is('.') || is('-') || isdigit( *next )) {
         parse_with_bounds( next );