From: pcarana Date: Sat, 13 Jun 2020 00:34:57 +0000 (-0500) Subject: Replace args '*log.prefix' for '*log.tag', add help message. X-Git-Tag: v1.3.0~8 X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=91454e231a66295e55fab51f708a95f9c141caa6;p=thirdparty%2FFORT-validator.git Replace args '*log.prefix' for '*log.tag', add help message. +Do the replacement at code, docs and unit tests. +Add a help message that's printed whenever there's an error at the configuration arguments. +Fix a broken unit test. +Fix the description of 'validation-log.tag'. +Fix some errors at configuration examples ('examples/config.json') and at the web docs ('usage.html#--configuration-file'). --- diff --git a/docs/logging.md b/docs/logging.md index 2c4a2cb0..c003c7e9 100644 --- a/docs/logging.md +++ b/docs/logging.md @@ -7,14 +7,14 @@ url-log-output: "[`--log.output`](usage.html#--logoutput)" url-log-color-output: "[`--log.color-output`](usage.html#--logcolor-output)" url-log-file-name-format: "[`--log.file-name-format`](usage.html#--logfile-name-format)" url-log-facility: "[`--log.facility`](usage.html#--logfacility)" -url-log-prefix: "[`--log.prefix`](usage.html#--logprefix)" +url-log-tag: "[`--log.tag`](usage.html#--logtag)" url-vlog-enabled: "[`--validation-log.enabled`](usage.html#--validation-logenabled)" url-vlog-level: "[`--validation-log.level`](usage.html#--validation-loglevel)" url-vlog-output: "[`--validation-log.output`](usage.html#--validation-logoutput)" url-vlog-color-output: "[`--validation-log.color-output`](usage.html#--validation-logcolor-output)" url-vlog-file-name-format: "[`--validation-log.file-name-format`](usage.html#--validation-logfile-name-format)" url-vlog-facility: "[`--validation-log.facility`](usage.html#--validation-logfacility)" -url-vlog-prefix: "[`--validation-log.prefix`](usage.html#--validation-logprefix)" +url-vlog-tag: "[`--validation-log.tag`](usage.html#--validation-logtag)" --- # {{ page.title }} @@ -31,7 +31,7 @@ url-vlog-prefix: "[`--validation-log.prefix`](usage.html#--validation-logprefix) 4. [Color output](#color-output) 5. [File name format](#file-name-format) 6. [Facility](#facility) - 7. [Prefix](#prefix) + 7. [Tag](#tag) ## Log types @@ -78,9 +78,9 @@ The operation log arguments are those that have the prefix `log.`, while the val - [`color-output`](#color-output) - [`file-name-format`](#file-name-format) - [`facility`](#facility) -- [`prefix`](#prefix) +- [`tag`](#tag) -For instance, to enable the validation log the argument {{ page.url-vlog-enabled }} should be used (prefix: `validation-log.`, suffix: `enabled`). +For instance, to enable the "validation log", the argument {{ page.url-vlog-enabled }} should be used (prefix: `validation-log.`, suffix: `enabled`). The following sub-sections describe how each argument works. @@ -192,18 +192,18 @@ The arguments of each log type are: - {{ page.url-log-facility }} - {{ page.url-vlog-facility }} -### Prefix +### Tag -Text prefix that will be added to each message of the corresponding log type. The prefix will be added after the message level, inside square brackets. +Text tag that will be added to each message of the corresponding log type. The tag will be added after the message level, inside square brackets. It's a simple mean to differentiate each message according to its type, probably useful if the [`*.output`](#output) is the same for both log types. E.g. If a validation error is found, it could be logged like this: {% highlight bash %} -$ {{ page.command }} --validation-log.prefix="Validation" (...) +$ {{ page.command }} --validation-log.tag="Validation" (...) ERR [Validation]: rsync://rpki.example.com/foo/bar/baz.cer: Certificate validation failed: certificate has expired {% endhighlight %} The arguments of each log type are: -- {{ page.url-log-prefix }} -- {{ page.url-vlog-prefix }} +- {{ page.url-log-tag }} +- {{ page.url-vlog-tag }} diff --git a/docs/usage.md b/docs/usage.md index 4af65fcb..de6311ad 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -33,14 +33,14 @@ command: fort 22. [`--log.color-output`](#--logcolor-output) 23. [`--log.file-name-format`](#--logfile-name-format) 24. [`--log.facility`](#--logfacility) - 25. [`--log.prefix`](#--logprefix) + 25. [`--log.tag`](#--logtag) 26. [`--validation-log.enabled`](#--validation-logenabled) 27. [`--validation-log.level`](#--validation-loglevel) 28. [`--validation-log.output`](#--validation-logoutput) 29. [`--validation-log.color-output`](#--validation-logcolor-output) 30. [`--validation-log.file-name-format`](#--validation-logfile-name-format) 31. [`--validation-log.facility`](#--validation-logfacility) - 32. [`--validation-log.prefix`](#--validation-logprefix) + 32. [`--validation-log.tag`](#--validation-logtag) 33. [`--http.user-agent`](#--httpuser-agent) 34. [`--http.connect-timeout`](#--httpconnect-timeout) 35. [`--http.transfer-timeout`](#--httptransfer-timeout) @@ -99,14 +99,14 @@ command: fort [--log.color-output] [--log.file-name-format=global-url|local-path|file-name] [--log.facility=auth|authpriv|cron|daemon|ftp|kern|lpr|mail|news|syslog|user|uucp|local0|local1|local2|local3|local4|local5|local6|local7] - [--log.prefix=] + [--log.tag=] [--validation-log.enabled=true|false] [--validation-log.level=error|warning|info|debug] [--validation-log.output=syslog|console] [--validation-log.color-output] [--validation-log.file-name-format=global-url|local-path|file-name] [--validation-log.facility=auth|authpriv|cron|daemon|ftp|kern|lpr|mail|news|syslog|user|uucp|local0|local1|local2|local3|local4|local5|local6|local7] - [--validation-log.prefix=] + [--validation-log.tag=] [--rrdp.enabled=true|false] [--rrdp.priority=] [--rrdp.retry.count=] @@ -463,15 +463,15 @@ Syslog facility utilized for operation logs (meaningful only if [`--log.output`] Read more at [Logging](logging.html) and at [Logging > Configuration > Facility](logging.html#facility). -### `--log.prefix` +### `--log.tag` - **Type:** String - **Availability:** `argv` and JSON - **Default:** `NULL` -Text prefix that will be added to the operation log messages (it will appear inside square brackets). +Text tag that will be added to the operation log messages (it will appear inside square brackets). -Read more at [Logging](logging.html) and at [Logging > Configuration > Prefix](logging.html#prefix). +Read more at [Logging](logging.html) and at [Logging > Configuration > Tag](logging.html#tag). ### `--validation-log.enabled` @@ -541,15 +541,15 @@ Syslog facility utilized for validation logs (meaningful only if [`--validation- Read more at [Logging](logging.html) and at [Logging > Configuration > Facility](logging.html#facility). -### `--validation-log.prefix` +### `--validation-log.tag` - **Type:** String - **Availability:** `argv` and JSON - **Default:** `Validation` -Text prefix that will be added to the validation log messages (it will appear inside square brackets). +Text tag that will be added to the validation log messages (it will appear inside square brackets). -Read more at [Logging](logging.html) and at [Logging > Configuration > Prefix](logging.html#prefix). +Read more at [Logging](logging.html) and at [Logging > Configuration > Tag](logging.html#tag). ### `--http.user-agent` @@ -721,10 +721,23 @@ The configuration options are mostly the same as the ones from the `argv` interf }, "log": { + "enabled": true, "level": "warning", "output": "console", "color-output": true, - "file-name-format": "file-name" + "file-name-format": "file-name", + "facility": "daemon", + "tag": "Operation" + }, + + "validation-log": { + "enabled": false, + "level": "warning", + "output": "console", + "color-output": true, + "file-name-format": "global-url", + "facility": "daemon", + "tag": "Validation" }, "http": { diff --git a/examples/config.json b/examples/config.json index 5eb87ab8..a2031e88 100644 --- a/examples/config.json +++ b/examples/config.json @@ -18,7 +18,7 @@ }, "slurm": "/tmp/fort/", "log": { - "enable": true, + "enabled": true, "level": "warning", "output": "console", "color-output": false, @@ -26,13 +26,13 @@ "facility": "daemon" }, "validation-log": { - "enable": false, + "enabled": false, "level": "warning", "output": "console", "color-output": false, "file-name-format": "global-url", "facility": "daemon", - "prefix": "[Validation]" + "tag": "Validation" }, "http": { "user-agent": "fort/1.3.0", diff --git a/man/fort.8 b/man/fort.8 index beed77ef..92841749 100644 --- a/man/fort.8 +++ b/man/fort.8 @@ -527,9 +527,9 @@ Read more about logs at FORT validator's web docs, module 'Logging'. .RE .P -.B \-\-log.prefix=\fISTRING\fR +.B \-\-log.tag=\fISTRING\fR .RS 4 -Text prefix that will be added to the operation log messages (it will appear +Text tag that will be added to the operation log messages (it will appear inside square brackets). .P By default, it has a NULL value. @@ -646,9 +646,9 @@ Read more about logs at FORT validator's web docs, module 'Logging'. .RE .P -.B \-\-validation-log.prefix=\fISTRING\fR +.B \-\-validation-log.tag=\fISTRING\fR .RS 4 -Text prefix that will be added to the validation log messages (it will appear +Text tag that will be added to the validation log messages (it will appear inside square brackets). .P By default, it has the value \fIValidation\fR. @@ -1085,7 +1085,7 @@ to a specific value: "color-output": true, "file-name-format": "local-path", "facility": "daemon", - "prefix": "Operation" + "tag": "Operation" }, "validation-log": { "enabled": false, @@ -1094,7 +1094,7 @@ to a specific value: "color-output": true, "file-name-format": "local-path", "facility": "daemon", - "prefix": "Validation" + "tag": "Validation" }, "http": { "user-agent": "fort/1.3.0", diff --git a/src/config.c b/src/config.c index a4f1854d..809450cb 100644 --- a/src/config.c +++ b/src/config.c @@ -133,8 +133,8 @@ struct rpki_config { struct { /** Enables operation logs **/ bool enabled; - /** Prefix to identify operation logs **/ - char *prefix; + /** String tag to identify operation logs **/ + char *tag; /** Print ANSI color codes? */ bool color; /** Format in which file names will be printed. */ @@ -150,8 +150,8 @@ struct rpki_config { struct { /** Enables validation Logs **/ bool enabled; - /** Prefix to identify validation logs **/ - char *prefix; + /** String tag to identify validation logs **/ + char *tag; /** Print ANSI color codes? */ bool color; /** Format in which file names will be printed. */ @@ -545,10 +545,10 @@ static const struct option_field options[] = { .doc = "Log level to print message of equal or higher importance", }, { .id = 4003, - .name = "log.prefix", + .name = "log.tag", .type = >_string, - .offset = offsetof(struct rpki_config, log.prefix), - .doc = "Prefix to identify operation logs", + .offset = offsetof(struct rpki_config, log.tag), + .doc = "Text tag to identify operation logs", .arg_doc = "", }, { .id = 4004, @@ -590,10 +590,10 @@ static const struct option_field options[] = { .doc = "Log level to print message of equal or higher importance", }, { .id = 4013, - .name = "validation-log.prefix", + .name = "validation-log.tag", .type = >_string, - .offset = offsetof(struct rpki_config, validation_log.prefix), - .doc = "Prefix to identify operation logs", + .offset = offsetof(struct rpki_config, validation_log.tag), + .doc = "Text tag to identify validation logs", .arg_doc = "", }, { .id = 4014, @@ -890,7 +890,7 @@ set_default_values(void) rpki_config.log.color = false; rpki_config.log.filename_format = FNF_GLOBAL; rpki_config.log.facility = LOG_DAEMON; - rpki_config.log.prefix = NULL; + rpki_config.log.tag = NULL; rpki_config.validation_log.enabled = false; rpki_config.validation_log.output = CONSOLE; @@ -898,10 +898,10 @@ set_default_values(void) rpki_config.validation_log.color = false; rpki_config.validation_log.filename_format = FNF_GLOBAL; rpki_config.validation_log.facility = LOG_DAEMON; - rpki_config.validation_log.prefix = strdup("Validation"); - if (rpki_config.validation_log.prefix == NULL) { + rpki_config.validation_log.tag = strdup("Validation"); + if (rpki_config.validation_log.tag == NULL) { error = pr_enomem(); - goto revert_validation_log_prefix; + goto revert_validation_log_tag; } rpki_config.output.roa = NULL; @@ -911,7 +911,7 @@ set_default_values(void) rpki_config.stale_repository_period = 43200; /* 12 hours */ return 0; -revert_validation_log_prefix: +revert_validation_log_tag: free(rpki_config.http.user_agent); revert_flat_array: string_array_cleanup(&rpki_config.rsync.args.flat); @@ -1061,9 +1061,11 @@ handle_flags_config(int argc, char **argv) log_start(); end: - if (error) + if (error) { free_rpki_config(); - else + pr_op_err("Try '%s --usage' or '%s --help' for more information.", + program_name, program_name); + } else print_config(); free(long_opts); @@ -1170,9 +1172,9 @@ config_get_op_log_enabled(void) } char const * -config_get_op_log_prefix(void) +config_get_op_log_tag(void) { - return rpki_config.log.prefix; + return rpki_config.log.tag; } bool @@ -1212,9 +1214,9 @@ config_get_val_log_enabled(void) } char const * -config_get_val_log_prefix(void) +config_get_val_log_tag(void) { - return rpki_config.validation_log.prefix; + return rpki_config.validation_log.tag; } bool diff --git a/src/config.h b/src/config.h index d27410bc..0a2230dd 100644 --- a/src/config.h +++ b/src/config.h @@ -54,7 +54,7 @@ unsigned int config_get_stale_repository_period(void); /* Logging getters */ bool config_get_op_log_enabled(void); -char const * config_get_op_log_prefix(void); +char const * config_get_op_log_tag(void); bool config_get_op_log_color_output(void); enum filename_format config_get_op_log_filename_format(void); uint8_t config_get_op_log_level(void); @@ -62,7 +62,7 @@ enum log_output config_get_op_log_output(void); uint32_t config_get_op_log_facility(void); bool config_get_val_log_enabled(void); -char const * config_get_val_log_prefix(void); +char const * config_get_val_log_tag(void); bool config_get_val_log_color_output(void); enum filename_format config_get_val_log_filename_format(void); uint8_t config_get_val_log_level(void); diff --git a/src/log.c b/src/log.c index 74669a7a..235c3ce1 100644 --- a/src/log.c +++ b/src/log.c @@ -274,7 +274,7 @@ pr_stream(int level, char const *prefix, const char *format, bool color_output, #define PR_OP_SIMPLE(level) \ do { \ va_list args; \ - char const *prefix = config_get_op_log_prefix(); \ + char const *prefix = config_get_op_log_tag(); \ bool color = config_get_op_log_color_output(); \ int facility = config_get_op_log_facility(); \ \ @@ -302,7 +302,7 @@ pr_stream(int level, char const *prefix, const char *format, bool color_output, #define PR_VAL_SIMPLE(level) \ do { \ va_list args; \ - char const *prefix = config_get_val_log_prefix(); \ + char const *prefix = config_get_val_log_tag(); \ bool color = config_get_val_log_color_output(); \ int facility = config_get_val_log_facility(); \ \ @@ -462,7 +462,7 @@ pr_op_errno(int error, const char *format, ...) return pr_errno(error, op_syslog_enabled, op_fprintf_enabled, config_get_op_log_facility(), config_get_op_log_color_output(), - config_get_op_log_prefix()); + config_get_op_log_tag()); } int @@ -473,7 +473,7 @@ pr_val_errno(int error, const char *format, ...) return pr_errno(error, val_syslog_enabled, val_fprintf_enabled, config_get_val_log_facility(), config_get_val_log_color_output(), - config_get_val_log_prefix()); + config_get_val_log_tag()); } static int @@ -481,9 +481,9 @@ log_op_crypto_error(const char *str, size_t len, void *arg) { if (op_syslog_enabled) pr_simple_syslog(LOG_ERR, config_get_op_log_facility(), - config_get_op_log_prefix(), str); + config_get_op_log_tag(), str); if (op_fprintf_enabled) - __fprintf(LOG_ERR, config_get_op_log_prefix(), + __fprintf(LOG_ERR, config_get_op_log_tag(), config_get_op_log_color_output(), " - %s", str); return 1; @@ -494,9 +494,9 @@ log_val_crypto_error(const char *str, size_t len, void *arg) { if (val_syslog_enabled) pr_simple_syslog(LOG_ERR, config_get_val_log_facility(), - config_get_val_log_prefix(), str); + config_get_val_log_tag(), str); if (val_fprintf_enabled) - __fprintf(LOG_ERR, config_get_val_log_prefix(), + __fprintf(LOG_ERR, config_get_val_log_tag(), config_get_val_log_color_output(), " - %s", str); return 1; @@ -549,7 +549,7 @@ op_crypto_err(const char *format, ...) return crypto_err(log_op_crypto_error, op_fprintf_enabled, op_syslog_enabled, config_get_op_log_color_output(), - config_get_op_log_facility(), config_get_op_log_prefix()); + config_get_op_log_facility(), config_get_op_log_tag()); } /** @@ -571,7 +571,7 @@ val_crypto_err(const char *format, ...) return crypto_err(log_val_crypto_error, val_fprintf_enabled, val_syslog_enabled, config_get_val_log_color_output(), - config_get_val_log_facility(), config_get_val_log_prefix()); + config_get_val_log_facility(), config_get_val_log_tag()); } /** @@ -582,9 +582,9 @@ pr_enomem(void) { if (op_syslog_enabled) pr_simple_syslog(LOG_ERR, config_get_op_log_facility(), - config_get_op_log_prefix(), "Out of memory."); + config_get_op_log_tag(), "Out of memory."); if (op_fprintf_enabled) - __fprintf(LOG_ERR, config_get_op_log_prefix(), + __fprintf(LOG_ERR, config_get_op_log_tag(), config_get_op_log_color_output(), "Out of memory.\n"); return -ENOMEM; diff --git a/test/impersonator.c b/test/impersonator.c index ac420607..94b0a03e 100644 --- a/test/impersonator.c +++ b/test/impersonator.c @@ -162,7 +162,7 @@ config_get_op_log_enabled(void) } char const * -config_get_op_log_prefix(void) +config_get_op_log_tag(void) { return NULL; } @@ -204,7 +204,7 @@ config_get_val_log_enabled(void) } char const * -config_get_val_log_prefix(void) +config_get_val_log_tag(void) { return "VALIDATION"; } diff --git a/test/tal_test.c b/test/tal_test.c index ce3f5233..7f8a9fe8 100644 --- a/test/tal_test.c +++ b/test/tal_test.c @@ -44,7 +44,7 @@ validation_destroy(struct validation *state) } int -process_file_or_dir(char const *location, char const *file_ext, +process_file_or_dir(char const *location, char const *file_ext, bool empty_err, process_file_cb cb, void *arg) { return 0;