summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2023-03-08 15:10:52 +0100
committerWerner Koch <wk@gnupg.org>2023-03-08 15:10:52 +0100
commitd2d1db88608349bbe00da3adabddc167f6852f9e (patch)
tree435c773a755458a1e7418e0782055be98da1e015
parentdirmngr: Minor code cleanup in the CRL cache. (diff)
downloadgnupg2-d2d1db88608349bbe00da3adabddc167f6852f9e.tar.xz
gnupg2-d2d1db88608349bbe00da3adabddc167f6852f9e.zip
gpg,gpgsm: New option --log-time
* g10/gpg.c (oLogTime): New. (opts): Add "log-time". (opt_log_time): New var. (main): Implement. * sm/gpgsm.c (oLogTime): New. (opts): Add "log-time". (opt_log_time): New var. (main): Implement.
-rw-r--r--doc/gpg.texi4
-rw-r--r--doc/gpgsm.texi4
-rw-r--r--g10/gpg.c9
-rw-r--r--sm/gpgsm.c10
4 files changed, 27 insertions, 0 deletions
diff --git a/doc/gpg.texi b/doc/gpg.texi
index 01b91abec..a6ab4d57d 100644
--- a/doc/gpg.texi
+++ b/doc/gpg.texi
@@ -3199,6 +3199,10 @@ Write log output to file descriptor @var{n} and not to STDERR.
Same as @option{--logger-fd}, except the logger data is written to
file @var{file}. Use @file{socket://} to log to s socket.
+@item --log-time
+@opindex log-time
+Prefix all log output with a timestamp even if no log file is used.
+
@item --attribute-fd @var{n}
@opindex attribute-fd
Write attribute subpackets to the file descriptor @var{n}. This is most
diff --git a/doc/gpgsm.texi b/doc/gpgsm.texi
index 42090a93f..a117009bd 100644
--- a/doc/gpgsm.texi
+++ b/doc/gpgsm.texi
@@ -408,6 +408,10 @@ Do not print a warning when the so called "secure memory" cannot be used.
When running in server mode, append all logging output to @var{file}.
Use @file{socket://} to log to socket.
+@item --log-time
+@opindex log-time
+Prefix all log output with a timestamp even if no log file is used.
+
@end table
diff --git a/g10/gpg.c b/g10/gpg.c
index 9ec956ac3..632fbb90f 100644
--- a/g10/gpg.c
+++ b/g10/gpg.c
@@ -337,6 +337,7 @@ enum cmd_and_opt_values
oEncryptToDefaultKey,
oLoggerFD,
oLoggerFile,
+ oLogTime,
oUtf8Strings,
oNoUtf8Strings,
oDisableCipherAlgo,
@@ -600,6 +601,7 @@ static gpgrt_opt_t opts[] = {
ARGPARSE_s_s (oLoggerFile, "log-file",
N_("|FILE|write server mode logs to FILE")),
ARGPARSE_s_s (oLoggerFile, "logger-file", "@"), /* 1.4 compatibility. */
+ ARGPARSE_s_n (oLogTime, "log-time", "@"),
ARGPARSE_s_n (oQuickRandom, "debug-quick-random", "@"),
@@ -1041,6 +1043,7 @@ static int utf8_strings =
static int maybe_setuid = 1;
static unsigned int opt_set_iobuf_size;
static unsigned int opt_set_iobuf_size_used;
+static int opt_log_time;
/* Collection of options used only in this module. */
static struct {
@@ -2864,6 +2867,9 @@ main (int argc, char **argv)
case oLoggerFile:
logfile = pargs.r.ret_str;
break;
+ case oLogTime:
+ opt_log_time = 1;
+ break;
case oWithFingerprint:
opt.with_fingerprint = 1;
@@ -3829,6 +3835,9 @@ main (int argc, char **argv)
| GPGRT_LOG_WITH_TIME
| GPGRT_LOG_WITH_PID ));
}
+ else if (opt_log_time)
+ log_set_prefix (NULL, (GPGRT_LOG_WITH_PREFIX|GPGRT_LOG_NO_REGISTRY
+ |GPGRT_LOG_WITH_TIME));
if (opt.verbose > 2)
log_info ("using character set '%s'\n", get_native_charset ());
diff --git a/sm/gpgsm.c b/sm/gpgsm.c
index f8b3856c2..8ca398360 100644
--- a/sm/gpgsm.c
+++ b/sm/gpgsm.c
@@ -114,6 +114,7 @@ enum cmd_and_opt_values {
oNoLogFile,
oAuditLog,
oHtmlAuditLog,
+ oLogTime,
oEnableSpecialFilenames,
@@ -288,6 +289,7 @@ static gpgrt_opt_t opts[] = {
N_("|FILE|write server mode logs to FILE")),
ARGPARSE_s_n (oNoLogFile, "no-log-file", "@"),
ARGPARSE_s_i (oLoggerFD, "logger-fd", "@"),
+ ARGPARSE_s_n (oLogTime, "log-time", "@"),
ARGPARSE_s_n (oNoSecmemWarn, "no-secmem-warning", "@"),
@@ -499,6 +501,9 @@ static int maybe_setuid = 1;
static const char *debug_level;
static unsigned int debug_value;
+/* Helper for --log-time; */
+static int opt_log_time;
+
/* Default value for include-certs. We need an extra macro for
gpgconf-list because the variable will be changed by the command
line option.
@@ -1247,6 +1252,7 @@ main ( int argc, char **argv)
case oLogFile: logfile = pargs.r.ret_str; break;
case oNoLogFile: logfile = NULL; break;
+ case oLogTime: opt_log_time = 1; break;
case oAuditLog: auditlog = pargs.r.ret_str; break;
case oHtmlAuditLog: htmlauditlog = pargs.r.ret_str; break;
@@ -1579,6 +1585,10 @@ main ( int argc, char **argv)
log_set_file (logfile);
log_set_prefix (NULL, GPGRT_LOG_WITH_PREFIX | GPGRT_LOG_WITH_TIME | GPGRT_LOG_WITH_PID);
}
+ else if (opt_log_time)
+ log_set_prefix (NULL, (GPGRT_LOG_WITH_PREFIX|GPGRT_LOG_NO_REGISTRY
+ |GPGRT_LOG_WITH_TIME));
+
if (gnupg_faked_time_p ())
{