debug prints - new suggested patch
Herb Lewis
hlewis at panasas.com
Wed Aug 8 13:26:53 MDT 2012
OK, I added Andrew's suggestion and printed the header if we are
using stdout, and made some more changes. Comments welcome.
My previous change broke the feature of indenting non-header lines so I
added the SOH character to the beginning of the header lines so we can
tell it is a header. This is then not printed in format_debug_text but lines
that do not start with this special character are indented if in timestamp
mode.
When "debug pid = yes" is set, (which only takes affect if one of the
timestamp
parameters is also set) then the non-header lines begin with the the
"[pid=xxxx] " string so you can tell which smbd the message belongs to
when you are not sending output to separate files.
-------------- next part --------------
--- lib/util/debug.c 2012-06-24 10:21:16.000000000 -0700
+++ lib/util/debug.c.new 2012-08-08 12:08:18.872126617 -0700
@@ -831,17 +831,34 @@
static void format_debug_text( const char *msg )
{
size_t i;
- bool timestamp = (state.logtype == DEBUG_FILE && (state.settings.timestamp_logs));
+ unsigned int mypid = 0;
+ bool headerline = false;
+ bool timestamp = (state.logtype == DEBUG_FILE &&
+ (state.settings.timestamp_logs ||
+ state.settings.debug_prefix_timestamp));
if (!format_bufr) {
debug_init();
}
+ if (state.settings.debug_pid) {
+ mypid = (unsigned int)getpid();
+ }
for( i = 0; msg[i]; i++ ) {
- /* Indent two spaces at each new line. */
- if(timestamp && 0 == format_pos) {
+ /* ASCII SOH means this is a header line */
+ if(i == 0 && msg[0] == '\001') {
+ headerline = true;
+ continue;
+ } else if(!headerline && timestamp && 0 == format_pos) {
+ /* Indent two spaces at each new line. */
+ headerline = false;
format_bufr[0] = format_bufr[1] = ' ';
format_pos = 2;
+ if(state.settings.debug_pid) {
+ format_pos += snprintf(&format_bufr[2], FORMAT_BUFR_MAX-3,
+ "[pid=%d] ", mypid);
+ }
+
}
/* If there's room, copy the character to the format buffer. */
@@ -923,11 +940,6 @@
syslog_level = level;
#endif
- /* Don't print a header if we're logging to stdout. */
- if ( state.logtype != DEBUG_FILE ) {
- return( true );
- }
-
/* Print the header if timestamps are turned on. If parameters are
* not yet loaded, then default to timestamps on.
*/
@@ -957,21 +969,24 @@
}
/* Print it all out at once to prevent split syslog output. */
+ /* ASCII SOH means this is a start of a timestamp header */
if( state.settings.debug_prefix_timestamp ) {
char *time_str = current_timestring(NULL,
state.settings.debug_hires_timestamp);
- (void)Debug1( "[%s, %2d%s] ",
+ (void)dbgtext( "\001[%s, %2d%s] %s: ",
time_str,
- level, header_str);
+ level, header_str, func);
talloc_free(time_str);
} else {
char *time_str = current_timestring(NULL,
state.settings.debug_hires_timestamp);
- (void)Debug1( "[%s, %2d%s] %s(%s)\n",
+ (void)dbgtext( "\001[%s, %2d%s] %s(%s)\n",
time_str,
level, header_str, location, func );
talloc_free(time_str);
}
+ } else {
+ (void)dbgtext( "%s[%d]: ", func, level);
}
errno = old_errno;
More information about the samba-technical
mailing list