From: Alberto Leiva Popper Date: Fri, 13 Sep 2019 19:19:56 +0000 (-0500) Subject: Log: Remove clutter, add doc, patch -DDEBUG X-Git-Tag: v1.1.0~1^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=509936eb03f479c92ad878fb16897629e64f58f0;p=thirdparty%2FFORT-validator.git Log: Remove clutter, add doc, patch -DDEBUG Was printing too many lines for an obsolete reason. --- diff --git a/docs/logging.md b/docs/logging.md index 89a776eb..87670d5b 100644 --- a/docs/logging.md +++ b/docs/logging.md @@ -9,3 +9,16 @@ title: Logging During the brief period in which configuration has not been completely parsed yet (and therefore, Fort is not yet aware of the desired running mode), the standard streams and syslog are used simultaneously. +Fort uses exactly five syslog levels of priority. These are their meanings: + +- `crit`: Programming errors. (These lead to program termination.) +- `err`: Validation failures. (RPKI object rejected.) +- `warning`: Suspicious validation outcome. (RPKI object not rejected.) +- `info`: Information deemed useful to the user: + - Configuration echo at the beginning. + - Server binding status. + - Additional noise we're considering downgrading to `debug`. +- `debug`: Information deemed useful to the developer. These messages are usually compiled out of the binary by default. If you want them, you need to enable `-DDEBUG` (eg. by uncommenting [`CFLAGS_DEBUG`](https://github.com/NICMx/FORT-validator/blob/master/src/Makefile.am#L3)). + +When standard streams are enabled, `info` and `debug` are printed in standard output, while rest are printed in standard error. + diff --git a/docs/usage.md b/docs/usage.md index 9aac448e..ce84165d 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -362,7 +362,7 @@ SLURM file, or directory containing SLURM files. See [SLURM](slurm.html). - **Type:** None - **Availability:** `argv` and JSON -If enabled, the logging output will contain ANSI color codes. Meant for human consumption. +If enabled, the logging output will contain ANSI color codes. Meant for human consumption:
$ {{ page.command }} --color-output (...)
 DBG: Manifest '62gPOPXWxxu0sQa4vQZYUBLaMbY.mft' {
@@ -372,6 +372,8 @@ If enabled, the logging output will contain ANSI color codes. Meant for human co
 CRT: Programming error: Array size is 1 but array is NULL.
 
+At present, this flag only affects standard output and standard error. Color codes are not sent to syslog, regardless of this flag. + ### `--log.file-name-format` - **Type:** Enumeration (`global-url`, `local-path`, `file-name`) @@ -401,6 +403,8 @@ $ {{ page.command }} --log.file-name-format file-name --local-repository reposi ERR: baz.cer: Certificate validation failed: certificate has expired {% endhighlight %} +This flag affects standard output, standard error and syslog. + ### `--output.roa` - **Type:** String (Path to file) diff --git a/src/log.c b/src/log.c index b89b5dae..89dbf341 100644 --- a/src/log.c +++ b/src/log.c @@ -105,45 +105,41 @@ __fprintf(int level, char const *format, ...) fprintf(lvl->stream, "\n"); } -static bool -pr_file_name(int level) -{ - char const *file_name; - - file_name = fnstack_peek(); - if (file_name == NULL) - return false; - - if (syslog_enabled) - syslog(level, "%s:", file_name); - if (fprintf_enabled) - __fprintf(level, "%s:", file_name); - - return true; -} - #define MSG_LEN 512 static void -pr_syslog(int level, bool indent, const char *format, va_list args) +pr_syslog(int level, const char *format, va_list args) { + char const *file_name; + struct level const *lvl; char msg[MSG_LEN]; + + file_name = fnstack_peek(); + lvl = level2struct(level); + /* Can't use vsyslog(); it's not portable. */ vsnprintf(msg, MSG_LEN, format, args); - syslog(level, "%s%s", indent ? " " : "", msg); + if (file_name != NULL) + syslog(level, "%s: %s: %s", lvl->label, file_name, msg); + else + syslog(level, "%s: %s", lvl->label, msg); } static void -pr_stream(int level, bool indent, const char *format, va_list args) +pr_stream(int level, const char *format, va_list args) { - struct level const *lvl = level2struct(level); + char const *file_name; + struct level const *lvl; + + file_name = fnstack_peek(); + lvl = level2struct(level); if (config_get_color_output()) fprintf(lvl->stream, "%s", lvl->color); fprintf(lvl->stream, "%s: ", lvl->label); - if (indent) - fprintf(lvl->stream, " "); + if (file_name != NULL) + fprintf(lvl->stream, "%s: ", file_name); vfprintf(lvl->stream, format, args); if (config_get_color_output()) @@ -155,19 +151,16 @@ pr_stream(int level, bool indent, const char *format, va_list args) #define PR_SIMPLE(level) \ do { \ va_list args; \ - bool indent; \ - \ - indent = pr_file_name(level); \ \ if (syslog_enabled) { \ va_start(args, format); \ - pr_syslog(level, indent, format, args); \ + pr_syslog(level, format, args); \ va_end(args); \ } \ \ if (fprintf_enabled) { \ va_start(args, format); \ - pr_stream(level, indent, format, args); \ + pr_stream(level, format, args); \ va_end(args); \ } \ } while (0) diff --git a/src/log.h b/src/log.h index 51cf6c40..06e0a2e8 100644 --- a/src/log.h +++ b/src/log.h @@ -55,12 +55,16 @@ void pr_debug(const char *, ...) CHECK_FORMAT(1, 2); #define pr_debug(...) do {} while (0) #endif +/* Non-errors deemed useful to the user. */ void pr_info(const char *, ...) CHECK_FORMAT(1, 2); +/* Issues that did not trigger RPKI object rejection. */ int pr_warn(const char *, ...) CHECK_FORMAT(1, 2); +/* Errors that trigger RPKI object rejection. */ int pr_err(const char *, ...) CHECK_FORMAT(1, 2); int pr_errno(int, const char *, ...) CHECK_FORMAT(2, 3); int crypto_err(const char *, ...) CHECK_FORMAT(1, 2); int pr_enomem(void); +/* Programming errors */ __dead void pr_crit(const char *, ...) CHECK_FORMAT(1, 2); int incidence(enum incidence_id, const char *, ...) CHECK_FORMAT(2, 3); diff --git a/src/object/certificate.c b/src/object/certificate.c index 0036e1b4..a81afe1f 100644 --- a/src/object/certificate.c +++ b/src/object/certificate.c @@ -61,10 +61,9 @@ validate_serial_number(X509 *cert) return crypto_err("Could not parse certificate serial number"); #ifdef DEBUG - pr_debug_prefix(); fprintf(stdout, "serial Number: "); BN_print_fp(stdout, number); - pr_debug_suffix(); + fprintf(stdout, "\n"); #endif error = x509stack_store_serial(validation_certstack(state), number); diff --git a/src/object/crl.c b/src/object/crl.c index 911217c6..585cf7a6 100644 --- a/src/object/crl.c +++ b/src/object/crl.c @@ -69,11 +69,10 @@ validate_revoked(X509_CRL *crl) continue; } - pr_debug_prefix(); fprintf(stdout, "Revoked: "); BN_print_fp(stdout, serial_bn); BN_free(serial_bn); - pr_debug_suffix(); + fprintf(stdout, "\n"); #endif if (X509_REVOKED_get0_revocationDate(revoked) == NULL) {