Hello,
Here is the new, complete version of timestamp patch. I added '-dt'
handling to all apps which already supported '-d <nn>'. Some of them
didn't mentioned '-d' in usage message, so I added there some info too.
The only (noticable) change is location of 'dbg_timestamp' variable. I
moved it from src/stored/stored.h to src/lib/message.h.
Whole patch included in attachment.
Regards,
Mariusz Czulada
Dnia 12-10-2007 o godz. 14:14 Kern Sibbald napisał(a):
> On Friday 12 October 2007 11:43, Mariusz Czulada wrote:
> > Hi,
> >
> > Dnia 11-10-2007 o godz. 18:13 Kern Sibbald napisał(a):
> > > Hello,
> > >
> > > On Thursday 11 October 2007 17:05, Mariusz Czulada wrote:
> > > > Hello,
> > > >
> > > > I wanted a timestamp to be printed in SD output, for correlating SD
> > > > events with other system activities. I made some changes in three files
> > > > and 'svn diff'-ed them as a patch (in attachment).
> > > >
> > > > src/stored/stored.h:
> > > > - added 'dbg_timestamp' extern variable for indication if time needed
> > > > in output.
> > > >
> > > > src/stored/stored.c:
> > > > - changed usage text - added '-dt' option to switch timestamps on
> > > > - changed usage text - changed '-dnn' to '-d <nn>'. <nn> is not treated
> > > > literally, but substituted, like <file> or <group>, I think.
> > > > - added procesing of 't' parameter when '-d' option is used.
> > > >
> > > > src/lib/message.c:
> > > > - added 'dbg_timestamp' as a global variable.
> > > > - added code in 'd_msg' function to print date and time, when debugging
> > > > is on and 'dbg_timestamp' variable is set to 'true'.
> > > >
> > > > Hope it could be useful for others :-)
> > >
> > > Yes, the patch looks like it is useful to users wanting a timestamp
> > > (something
> > > Eric has requested). The only thing that I see that may not work
> > > correctly
> > > is your implementation of -dt. It seems to me that if someone enters
> > > a -d116, it is going to turn on the timestamp debugging rather than
> > > setting
> > > the level to 116. I'm not an expert in command line arguments, but would
> > > need to resolve this question before applying the patch.
> >
> > If -d parameter is not (or does not starts with) 't', everything is
> > processed as previously, in 'else' block, where debug level is ser.
> > Timestamping is turned on only when -dt is passed, and the order of -d
> > options is not important.
> >
> > BTW. I see that most of the tools use -d<nn> option, so I'll add the
> > code to other programs, so -dt option will work in all binaries (already
> > supporting -d<nn>). Then will resend a new complete patch. OK?
>
> Yes.
----------------------------------------------------
Walka o Mistrzostwo Świata! Krzysztof DIABLO Włodarczyk
20.10 po raz kolejny stanie ringu! Musisz to zobaczy!
Kliknij:
http://klik.wp.pl/?adr=http%3A%2F%2Fcorto.www.wp.pl%2Fas%2Folympic.html&sid=57
Index: src/dird/dird.c
===================================================================
--- src/dird/dird.c (wersja 5750)
+++ src/dird/dird.c (kopia robocza)
@@ -94,7 +94,8 @@
"\nVersion: %s (%s)\n\n"
"Usage: dird [-f -s] [-c config_file] [-d debug_level] [config_file]\n"
" -c <file> set configuration file to file\n"
-" -dnn set debug level to nn\n"
+" -d <nn> set debug level to <nn>\n"
+" -dt print timestamp in debug output\n"
" -f run in foreground (for debugging)\n"
" -g groupid\n"
" -r <job> run <job> now\n"
@@ -149,9 +150,13 @@
break;
case 'd': /* set debug level */
- debug_level = atoi(optarg);
- if (debug_level <= 0) {
- debug_level = 1;
+ if (*optarg == 't') {
+ dbg_timestamp = true;
+ } else {
+ debug_level = atoi(optarg);
+ if (debug_level <= 0) {
+ debug_level = 1;
+ }
}
Dmsg1(10, "Debug level = %d\n", debug_level);
break;
Index: src/filed/filed.c
===================================================================
--- src/filed/filed.c (wersja 5750)
+++ src/filed/filed.c (kopia robocza)
@@ -65,7 +65,8 @@
"\nVersion: %s (%s)\n\n"
"Usage: bacula-fd [-f -s] [-c config_file] [-d debug_level]\n"
" -c <file> use <file> as configuration file\n"
-" -dnn set debug level to nn\n"
+" -d <nn> set debug level to <nn>\n"
+" -dt print timestamp in debug output\n"
" -f run in foreground (for debugging)\n"
" -g groupid\n"
" -s no signals (for debugging)\n"
@@ -114,9 +115,13 @@
break;
case 'd': /* debug level */
- debug_level = atoi(optarg);
- if (debug_level <= 0) {
- debug_level = 1;
+ if (*optarg == 't') {
+ dbg_timestamp = true;
+ } else {
+ debug_level = atoi(optarg);
+ if (debug_level <= 0) {
+ debug_level = 1;
+ }
}
break;
Index: src/tools/testls.c
===================================================================
--- src/tools/testls.c (wersja 5750)
+++ src/tools/testls.c (kopia robocza)
@@ -55,7 +55,8 @@
"\n"
"Usage: testls [-d debug_level] [-] [pattern1 ...]\n"
" -a print extended attributes (Win32 debug)\n"
-" -dnn set debug level to nn\n"
+" -d <nn> set debug level to <nn>\n"
+" -dt print timestamp in debug output\n"
" -e specify file of exclude patterns\n"
" -i specify file of include patterns\n"
" - read pattern(s) from stdin\n"
@@ -94,9 +95,13 @@
break;
case 'd': /* set debug level */
- debug_level = atoi(optarg);
- if (debug_level <= 0) {
- debug_level = 1;
+ if (*optarg == 't') {
+ dbg_timestamp = true;
+ } else {
+ debug_level = atoi(optarg);
+ if (debug_level <= 0) {
+ debug_level = 1;
+ }
}
break;
Index: src/tools/bregtest.c
===================================================================
--- src/tools/bregtest.c (wersja 5750)
+++ src/tools/bregtest.c (kopia robocza)
@@ -54,6 +54,8 @@
" -f specify file of data to be matched\n"
" -e specify expression\n"
" -s sed output\n"
+" -d <nn> set debug level to <nn>\n"
+" -dt print timestamp in debug output\n"
" -? print this message.\n"
"\n");
@@ -77,9 +79,13 @@
while ((ch = getopt(argc, argv, "sd:f:e:")) != -1) {
switch (ch) {
case 'd': /* set debug level */
- debug_level = atoi(optarg);
- if (debug_level <= 0) {
- debug_level = 1;
+ if (*optarg == 't') {
+ dbg_timestamp = true;
+ } else {
+ debug_level = atoi(optarg);
+ if (debug_level <= 0) {
+ debug_level = 1;
+ }
}
break;
Index: src/tools/testfind.c
===================================================================
--- src/tools/testfind.c (wersja 5750)
+++ src/tools/testfind.c (kopia robocza)
@@ -66,7 +66,8 @@
"\n"
"Usage: testfind [-d debug_level] [-] [pattern1 ...]\n"
" -a print extended attributes (Win32 debug)\n"
-" -dnn set debug level to nn\n"
+" -d <nn> set debug level to <nn>\n"
+" -dt print timestamp in debug output\n"
" -c specify config file containing FileSet resources\n"
" -f specify which FileSet to use\n"
" -? print this message.\n"
@@ -108,10 +109,14 @@
break;
case 'd': /* set debug level */
+ if (*optarg == 't') {
+ dbg_timestamp = true;
+ } else {
debug_level = atoi(optarg);
if (debug_level <= 0) {
debug_level = 1;
}
+ }
break;
case 'f': /* exclude patterns */
Index: src/tools/bbatch.c
===================================================================
--- src/tools/bbatch.c (wersja 5750)
+++ src/tools/bbatch.c (kopia robocza)
@@ -80,7 +80,8 @@
" will start 3 thread and load dat1, dat and datx in your catalog\n"
"See bbatch.c to generate datafile\n\n"
"Usage: bbatch [ options ] -w working/dir -f datafile\n"
-" -d <nn> set debug level to nn\n"
+" -d <nn> set debug level to <nn>\n"
+" -dt print timestamp in debug output\n"
" -n <name> specify the database name (default bacula)\n"
" -u <user> specify database user name (default bacula)\n"
" -P <password specify database password (default none)\n"
@@ -113,9 +114,14 @@
while ((ch = getopt(argc, argv, "h:c:d:n:P:Su:vf:w:?")) != -1) {
switch (ch) {
case 'd': /* debug level */
- debug_level = atoi(optarg);
- if (debug_level <= 0)
- debug_level = 1;
+ if (*optarg == 't') {
+ dbg_timestamp = true;
+ } else {
+ debug_level = atoi(optarg);
+ if (debug_level <= 0) {
+ debug_level = 1;
+ }
+ }
break;
case 'h':
Index: src/tools/dbcheck.c
===================================================================
--- src/tools/dbcheck.c (wersja 5750)
+++ src/tools/dbcheck.c (kopia robocza)
@@ -105,7 +105,8 @@
" -b batch mode\n"
" -C catalog name in the director conf file\n"
" -c director conf filename\n"
-" -dnn set debug level to nn\n"
+" -d <nn> set debug level to <nn>\n"
+" -dt print timestamp in debug output\n"
" -f fix inconsistencies\n"
" -v verbose\n"
" -? print this message\n\n");
@@ -145,9 +146,14 @@
break;
case 'd': /* debug level */
- debug_level = atoi(optarg);
- if (debug_level <= 0)
- debug_level = 1;
+ if (*optarg == 't') {
+ dbg_timestamp = true;
+ } else {
+ debug_level = atoi(optarg);
+ if (debug_level <= 0) {
+ debug_level = 1;
+ }
+ }
break;
case 'f': /* fix inconsistencies */
Index: src/tools/bsmtp.c
===================================================================
--- src/tools/bsmtp.c (wersja 5750)
+++ src/tools/bsmtp.c (kopia robocza)
@@ -187,7 +187,8 @@
"Usage: %s [-f from] [-h mailhost] [-s subject] [-c copy] [recipient ...]\n"
" -8 set charset utf-8\n"
" -c set the Cc: field\n"
-" -dnn set debug level to nn\n"
+" -d <nn> set debug level to <nn>\n"
+" -dt print timestamp in debug output\n"
" -f set the From: field\n"
" -h use mailhost:port as the SMTP server\n"
" -s set the Subject: field\n"
@@ -286,9 +287,13 @@
break;
case 'd': /* set debug level */
- debug_level = atoi(optarg);
- if (debug_level <= 0) {
- debug_level = 1;
+ if (*optarg == 't') {
+ dbg_timestamp = true;
+ } else {
+ debug_level = atoi(optarg);
+ if (debug_level <= 0) {
+ debug_level = 1;
+ }
}
Dmsg1(20, "Debug level = %d\n", debug_level);
break;
Index: src/tools/bregex.c
===================================================================
--- src/tools/bregex.c (wersja 5750)
+++ src/tools/bregex.c (kopia robocza)
@@ -65,6 +65,8 @@
" -f specify file of data to be matched\n"
" -l suppress line numbers\n"
" -n print lines that do not match\n"
+" -d <nn> set debug level to <nn>\n"
+" -dt print timestamp in debug output\n"
" -? print this message.\n"
"\n\n");
@@ -93,9 +95,13 @@
while ((ch = getopt(argc, argv, "d:f:n?")) != -1) {
switch (ch) {
case 'd': /* set debug level */
- debug_level = atoi(optarg);
- if (debug_level <= 0) {
- debug_level = 1;
+ if (*optarg == 't') {
+ dbg_timestamp = true;
+ } else {
+ debug_level = atoi(optarg);
+ if (debug_level <= 0) {
+ debug_level = 1;
+ }
}
break;
Index: src/stored/stored.c
===================================================================
--- src/stored/stored.c (wersja 5750)
+++ src/stored/stored.c (kopia robocza)
@@ -82,7 +82,8 @@
"\nVersion: %s (%s)\n\n"
"Usage: stored [options] [-c config_file] [config_file]\n"
" -c <file> use <file> as configuration file\n"
-" -dnn set debug level to nn\n"
+" -d <nn> set debug level to <nn>\n"
+" -dt print timestamp in debug output\n"
" -f run in foreground (for debugging)\n"
" -g <group> set groupid to group\n"
" -p proceed despite I/O errors\n"
@@ -142,9 +143,13 @@
break;
case 'd': /* debug level */
- debug_level = atoi(optarg);
- if (debug_level <= 0) {
- debug_level = 1;
+ if (*optarg == 't') {
+ dbg_timestamp = true;
+ } else {
+ debug_level = atoi(optarg);
+ if (debug_level <= 0) {
+ debug_level = 1;
+ }
}
break;
Index: src/stored/bcopy.c
===================================================================
--- src/stored/bcopy.c (wersja 5750)
+++ src/stored/bcopy.c (kopia robocza)
@@ -73,7 +73,8 @@
"Usage: bcopy [-d debug_level] <input-archive> <output-archive>\n"
" -b bootstrap specify a bootstrap file\n"
" -c <file> specify configuration file\n"
-" -d <nn> set debug level to nn\n"
+" -d <nn> set debug level to <nn>\n"
+" -dt print timestamp in debug output\n"
" -i specify input Volume names (separated by |)\n"
" -o specify output Volume names (separated by |)\n"
" -p proceed inspite of errors\n"
@@ -112,9 +113,14 @@
break;
case 'd': /* debug level */
- debug_level = atoi(optarg);
- if (debug_level <= 0)
- debug_level = 1;
+ if (*optarg == 't') {
+ dbg_timestamp = true;
+ } else {
+ debug_level = atoi(optarg);
+ if (debug_level <= 0) {
+ debug_level = 1;
+ }
+ }
break;
case 'i': /* input Volume name */
Index: src/stored/bextract.c
===================================================================
--- src/stored/bextract.c (wersja 5750)
+++ src/stored/bextract.c (kopia robocza)
@@ -79,7 +79,8 @@
"Usage: bextract <options> <bacula-archive-device-name> <directory-to-store-files>\n"
" -b <file> specify a bootstrap file\n"
" -c <file> specify a configuration file\n"
-" -d <nn> set debug level to nn\n"
+" -d <nn> set debug level to <nn>\n"
+" -dt print timestamp in debug output\n"
" -e <file> exclude list\n"
" -i <file> include list\n"
" -p proceed inspite of I/O errors\n"
@@ -126,9 +127,14 @@
break;
case 'd': /* debug level */
- debug_level = atoi(optarg);
- if (debug_level <= 0)
- debug_level = 1;
+ if (*optarg == 't') {
+ dbg_timestamp = true;
+ } else {
+ debug_level = atoi(optarg);
+ if (debug_level <= 0) {
+ debug_level = 1;
+ }
+ }
break;
case 'e': /* exclude list */
Index: src/stored/bls.c
===================================================================
--- src/stored/bls.c (wersja 5750)
+++ src/stored/bls.c (kopia robocza)
@@ -79,7 +79,8 @@
"Usage: bls [options] <device-name>\n"
" -b <file> specify a bootstrap file\n"
" -c <file> specify a config file\n"
-" -d <level> specify debug level\n"
+" -d <nn> set debug level to <nn>\n"
+" -dt print timestamp in debug output\n"
" -e <file> exclude list\n"
" -i <file> include list\n"
" -j list jobs\n"
@@ -130,9 +131,14 @@
break;
case 'd': /* debug level */
- debug_level = atoi(optarg);
- if (debug_level <= 0)
- debug_level = 1;
+ if (*optarg == 't') {
+ dbg_timestamp = true;
+ } else {
+ debug_level = atoi(optarg);
+ if (debug_level <= 0) {
+ debug_level = 1;
+ }
+ }
break;
case 'e': /* exclude list */
Index: src/stored/bscan.c
===================================================================
--- src/stored/bscan.c (wersja 5750)
+++ src/stored/bscan.c (kopia robocza)
@@ -116,7 +116,8 @@
"Usage: bscan [ options ] <bacula-archive>\n"
" -b bootstrap specify a bootstrap file\n"
" -c <file> specify configuration file\n"
-" -d <nn> set debug level to nn\n"
+" -d <nn> set debug level to <nn>\n"
+" -dt print timestamp in debug output\n"
" -m update media info in database\n"
" -n <name> specify the database name (default bacula)\n"
" -u <user> specify database user name (default bacula)\n"
@@ -166,9 +167,14 @@
break;
case 'd': /* debug level */
- debug_level = atoi(optarg);
- if (debug_level <= 0)
- debug_level = 1;
+ if (*optarg == 't') {
+ dbg_timestamp = true;
+ } else {
+ debug_level = atoi(optarg);
+ if (debug_level <= 0) {
+ debug_level = 1;
+ }
+ }
break;
case 'h':
Index: src/stored/btape.c
===================================================================
--- src/stored/btape.c (wersja 5750)
+++ src/stored/btape.c (kopia robocza)
@@ -220,9 +220,13 @@
break;
case 'd': /* set debug level */
- debug_level = atoi(optarg);
- if (debug_level <= 0) {
- debug_level = 1;
+ if (*optarg == 't') {
+ dbg_timestamp = true;
+ } else {
+ debug_level = atoi(optarg);
+ if (debug_level <= 0) {
+ debug_level = 1;
+ }
}
break;
@@ -2598,7 +2602,8 @@
"Usage: btape <options> <device_name>\n"
" -b <file> specify bootstrap file\n"
" -c <file> set configuration file to file\n"
-" -d <nn> set debug level to nn\n"
+" -d <nn> set debug level to <nn>\n"
+" -dt print timestamp in debug output\n"
" -p proceed inspite of I/O errors\n"
" -s turn off signals\n"
" -v be verbose\n"
Index: src/console/console.c
===================================================================
--- src/console/console.c (wersja 5750)
+++ src/console/console.c (kopia robocza)
@@ -114,7 +114,8 @@
"\nVersion: " VERSION " (" BDATE ") %s %s %s\n\n"
"Usage: bconsole [-s] [-c config_file] [-d debug_level]\n"
" -c <file> set configuration file to file\n"
-" -dnn set debug level to nn\n"
+" -d <nn> set debug level to <nn>\n"
+" -dt print timestamp in debug output\n"
" -n no conio\n"
" -s no signals\n"
" -t test - read configuration and exit\n"
@@ -532,9 +533,13 @@
break;
case 'd':
- debug_level = atoi(optarg);
- if (debug_level <= 0) {
- debug_level = 1;
+ if (*optarg == 't') {
+ dbg_timestamp = true;
+ } else {
+ debug_level = atoi(optarg);
+ if (debug_level <= 0) {
+ debug_level = 1;
+ }
}
break;
Index: src/tray-monitor/tray-monitor.c
===================================================================
--- src/tray-monitor/tray-monitor.c (wersja 5750)
+++ src/tray-monitor/tray-monitor.c (kopia robocza)
@@ -112,7 +112,8 @@
"\nVersion: %s (%s) %s %s %s\n\n"
"Usage: tray-monitor [-c config_file] [-d debug_level]\n"
" -c <file> set configuration file to file\n"
-" -dnn set debug level to nn\n"
+" -d <nn> set debug level to <nn>\n"
+" -dt print timestamp in debug output\n"
" -t test - read configuration and exit\n"
" -? print this message.\n"
"\n"), 2004, VERSION, BDATE, HOST_OS, DISTNAME, DISTVER);
@@ -219,9 +220,13 @@
break;
case 'd':
- debug_level = atoi(optarg);
- if (debug_level <= 0) {
- debug_level = 1;
+ if (*optarg == 't') {
+ dbg_timestamp = true;
+ } else {
+ debug_level = atoi(optarg);
+ if (debug_level <= 0) {
+ debug_level = 1;
+ }
}
break;
Index: src/lib/message.c
===================================================================
--- src/lib/message.c (wersja 5750)
+++ src/lib/message.c (kopia robocza)
@@ -50,6 +50,7 @@
const char *working_directory = NULL; /* working directory path stored here */
int verbose = 0; /* increase User messages */
int debug_level = 1; /* debug level */
+bool dbg_timestamp = false; /* print timestamp in debug output */
time_t daemon_start_time = 0; /* Daemon start time */
const char *version = VERSION " (" BDATE ")";
char my_name[30]; /* daemon name is stored here */
@@ -843,6 +844,7 @@
int len;
va_list arg_ptr;
bool details = true;
+ time_t mtime;
if (level < 0) {
details = false;
@@ -850,6 +852,15 @@
}
if (level <= debug_level) {
+ if (dbg_timestamp) {
+ mtime = time(NULL);
+ bstrftimes(buf, sizeof(buf), mtime);
+ len = strlen(buf);
+ buf[len++] = ' ';
+ buf[len] = 0;
+ fputs(buf, stdout);
+ }
+
#ifdef FULL_LOCATION
if (details) {
len = bsnprintf(buf, sizeof(buf), "%s: %s:%d-%u ",
Index: src/lib/message.h
===================================================================
--- src/lib/message.h (wersja 5750)
+++ src/lib/message.h (kopia robocza)
@@ -154,6 +154,7 @@
extern DLL_IMP_EXP sql_escape p_sql_escape;
extern DLL_IMP_EXP int debug_level;
+extern DLL_IMP_EXP bool dbg_timestamp; /* print timestamp in debug output */
extern DLL_IMP_EXP int verbose;
extern DLL_IMP_EXP char my_name[];
extern DLL_IMP_EXP const char * working_directory;
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Bacula-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bacula-devel