]> git.ipfire.org Git - thirdparty/FORT-validator.git/commitdiff
Log: Remove clutter, add doc, patch -DDEBUG
authorAlberto Leiva Popper <ydahhrk@gmail.com>
Fri, 13 Sep 2019 19:19:56 +0000 (14:19 -0500)
committerAlberto Leiva Popper <ydahhrk@gmail.com>
Fri, 13 Sep 2019 19:20:32 +0000 (14:20 -0500)
Was printing too many lines for an obsolete reason.

docs/logging.md
docs/usage.md
src/log.c
src/log.h
src/object/certificate.c
src/object/crl.c

index 89a776ebee18acdabd83cca8cf9aa0bc7dedc90c..87670d5b38eada68e3bf7c02c81a4b915cc59403 100644 (file)
@@ -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.
+
index 9aac448e1e7f8014cd6627d73b04e572a9399b7b..ce84165dee6853c41ad24b6650122bd9e57244e5 100644 (file)
@@ -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:
 
 <pre><code class="terminal">$ {{ page.command }} --color-output (...)
 <span style="color:cyan">DBG: Manifest '62gPOPXWxxu0sQa4vQZYUBLaMbY.mft' {</span>
@@ -372,6 +372,8 @@ If enabled, the logging output will contain ANSI color codes. Meant for human co
 <span style="color:magenta">CRT: Programming error: Array size is 1 but array is NULL.</span>
 </code></pre>
 
+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)
index b89b5daef2be221cde3c41803e58b493800aeba5..89dbf341d59abcf9452530e6fdeec7755d0fec86 100644 (file)
--- 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)
index 51cf6c401a95602f5d03a9d9f49cb77dbd376a15..06e0a2e8d2381d58c0ef732c57fe9fd05a0c6a40 100644 (file)
--- 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);
index 0036e1b47b0d8e4dc62ef50db10d059ea1c60534..a81afe1fcbf4556ba5bd110e385b74050152f780 100644 (file)
@@ -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);
index 911217c62e08c44010327d0ce7fdc9d0054d1772..585cf7a608dd0c9dbf2d8cc9afee4fc554b8c967 100644 (file)
@@ -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) {