aboutsummaryrefslogtreecommitdiffstats
path: root/src/logging.c
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2024-04-12 13:16:59 +0000
committerWerner Koch <[email protected]>2024-04-12 13:16:59 +0000
commit0a39fbefcb55379de1cdf1049de303c5ca0691b3 (patch)
treef592fb0e8ea295e1af3ef384245b94e5087fbd5c /src/logging.c
parentargparser: avoid endless loop due to a conf file read error. (diff)
downloadlibgpg-error-0a39fbefcb55379de1cdf1049de303c5ca0691b3.tar.gz
libgpg-error-0a39fbefcb55379de1cdf1049de303c5ca0691b3.zip
logging: Add a truncate keyword to log_printhex.
* src/logging.c (_gpgrt_logv_printhex): Add keyword support. -- A keyword in the format string is indicated by a leading pipe symbo, and exlamation mark, an arbitrary string of keywords, and a fina pipe sumbol. The only supprted keyword righty now is "trunc". Thus gpgrt_log_printhex (buf, buflen, "|!trunc|The buffer:") Will output not more that 32 hex bytes after "The buffer:" and instead of wrapping indicate the truncation by an Unicode horizontal ellipsis (#x2026).
Diffstat (limited to 'src/logging.c')
-rw-r--r--src/logging.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/logging.c b/src/logging.c
index 9008ba4..9b15da3 100644
--- a/src/logging.c
+++ b/src/logging.c
@@ -1169,10 +1169,23 @@ _gpgrt_logv_printhex (const void *buffer, size_t length,
int wrap = 0;
int cnt = 0;
const unsigned char *p;
+ int trunc = 0; /* Only print a shortened string. */
/* FIXME: This printing is not yet protected by _gpgrt_flockfile. */
if (fmt && *fmt)
{
+ const char *s;
+
+ if (*fmt == '|' && fmt[1] == '!' && (s=strchr (fmt+2, '|')) && s[1])
+ {
+ /* Skip initial keywords and parse them. */
+ fmt += 2;
+ if (strstr (fmt, "trunc"))
+ trunc = 1;
+
+ fmt = s+1;
+ }
+
_gpgrt_logv_internal (GPGRT_LOGLVL_DEBUG, 0, NULL, NULL, fmt, arg_ptr);
wrap = 1;
}
@@ -1187,6 +1200,12 @@ _gpgrt_logv_printhex (const void *buffer, size_t length,
_gpgrt_log_printf ("%02x", *p);
if (wrap && ++cnt == 32 && length)
{
+ if (trunc)
+ {
+ _gpgrt_log_printf (" …");
+ break;
+ }
+
cnt = 0;
/* (we indicate continuations with a backslash) */
_gpgrt_log_printf (" \\\n");