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.
This commit is contained in:
Werner Koch 2023-03-08 15:10:52 +01:00
parent 2d088176b4
commit d2d1db8860
No known key found for this signature in database
GPG Key ID: E3FDFF218E45B72B
4 changed files with 27 additions and 0 deletions

View File

@ -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

View File

@ -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

View File

@ -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 ());

View File

@ -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 ())
{