debug: Move adding timeval and loglevel
authorVolker Lendecke <vl@samba.org>
Tue, 29 Jul 2014 15:26:22 +0000 (15:26 +0000)
committerMichael Adam <obnox@samba.org>
Thu, 31 Jul 2014 16:49:47 +0000 (18:49 +0200)
The whole routine incrementally creates the hdr_string, do it for the
time string and the debuglevel as well

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
lib/util/debug.c

index 0e8c1d390435be5b761ab6bc7815cf415acb4e20..f94f44310ff2d8465c88cfccf9a50cab06313ef2 100644 (file)
@@ -1003,15 +1003,20 @@ bool dbghdrclass(int level, int cls, const char *location, const char *func)
                return true;
        }
 
-       header_str[0] = '\0';
+       GetTimeOfDay(&tv);
+       timeval_str_buf(&tv, state.settings.debug_hires_timestamp, &tvbuf);
+
+       snprintf(header_str, sizeof(header_str), "[%s, %2d",
+                tvbuf.buf, level);
 
        if (unlikely(DEBUGLEVEL_CLASS[ cls ] >= 10)) {
                verbose = true;
        }
 
        if (verbose || state.settings.debug_pid) {
-               snprintf(header_str, sizeof(header_str), ", pid=%u",
-                        (unsigned int)getpid());
+               size_t hs_len = strlen(header_str);
+               snprintf(header_str + hs_len, sizeof(header_str) - hs_len,
+                        ", pid=%u", (unsigned int)getpid());
        }
 
        if (verbose || state.settings.debug_uid) {
@@ -1031,18 +1036,12 @@ bool dbghdrclass(int level, int cls, const char *location, const char *func)
                         classname_table[cls]);
        }
 
-       GetTimeOfDay(&tv);
-       timeval_str_buf(&tv, state.settings.debug_hires_timestamp, &tvbuf);
-
        /* Print it all out at once to prevent split syslog output. */
        if( state.settings.debug_prefix_timestamp ) {
-               (void)Debug1("[%s, %2d%s] ",
-                            tvbuf.buf,
-                            level, header_str);
+               (void)Debug1("%s] ", header_str);
        } else {
-               (void)Debug1("[%s, %2d%s] %s(%s)\n",
-                            tvbuf.buf,
-                            level, header_str, location, func );
+               (void)Debug1("%s] %s(%s)\n",
+                            header_str, location, func );
        }
 
        errno = old_errno;