diff options
author | Neels Hofmeyr <neels@hofmeyr.de> | 2018-01-18 01:38:14 +0100 |
---|---|---|
committer | Neels Hofmeyr <nhofmeyr@sysmocom.de> | 2023-04-24 18:29:45 +0200 |
commit | 4beb8a2b4b0202fe8e6b69f7b80e18ed897a3253 (patch) | |
tree | c438362510425c98c2ab23ac2b375c5ae7901bcb | |
parent | 5ad230cd2ceee2550265c642991b4af34a1f286a (diff) |
logging vty: add 'logging print timestamp', deprecate other timestamp cmds
Deprecate previous logging timestamp config commands:
logging timestamp (0|1)
logging print extended-timestamp (0|1)
Add new single timestamp configuration command:
logging print timestamp (none|date-packed|ctime)
Another format called 'date' is added in patch
Icbd5192ea835e24b12fe057cc1ab56e9572d75c0. The idea is to have these
date formats:
date 2018-01-16,01:44:34.681 (new, "best" format)
date-packed 20180116014434681 (current 'print extended-timestamp 1')
ctime Sun Jan 1 01:44:34 2018 (current 'timestamp 1')
Change-Id: I58c792dda3cbcf8618648ba4429c27fa398a9e15
-rw-r--r-- | TODO-RELEASE | 2 | ||||
-rw-r--r-- | include/osmocom/core/logging.h | 14 | ||||
-rw-r--r-- | src/core/libosmocore.map | 1 | ||||
-rw-r--r-- | src/core/logging.c | 8 | ||||
-rw-r--r-- | src/vty/logging_vty.c | 59 | ||||
-rw-r--r-- | tests/logging/logging_vty_test.vty | 92 |
6 files changed, 136 insertions, 40 deletions
diff --git a/TODO-RELEASE b/TODO-RELEASE index 56855149..b104390d 100644 --- a/TODO-RELEASE +++ b/TODO-RELEASE @@ -20,3 +20,5 @@ core log_set_print_extended_timestamp() Replaced by log_set_print_timestamp2(). argument, logging now always snaps back to LOG_TIMSTAMP_NONE, instead of maybe going to LOG_TIMSTAMP_CTIME, depending on what flags were otherwise set. +vty logging 'logging timestamp (0|1)' deprecated, replaced by 'logging print timestamp (none|ctime)' +vty logging 'logging print extended-timestamp (0|1)' deprecated, replaced by 'logging print timestamp (none|date-packed)' diff --git a/include/osmocom/core/logging.h b/include/osmocom/core/logging.h index d05bc516..e0a1060a 100644 --- a/include/osmocom/core/logging.h +++ b/include/osmocom/core/logging.h @@ -10,6 +10,7 @@ #include <stdbool.h> #include <osmocom/core/defs.h> #include <osmocom/core/linuxlist.h> +#include <osmocom/core/utils.h> extern struct log_info *osmo_log_info; @@ -307,6 +308,19 @@ enum log_timestamp_format { LOG_TIMESTAMP_CTIME, }; +/*! Mapping between enum log_timestamp_format and strings. */ +extern const struct value_string log_timestamp_format_names[]; +/*! Map enum log_timestamp_format values to string constants. */ +static inline const char *log_timestamp_format_name(enum log_timestamp_format ltf) +{ + return get_value_string(log_timestamp_format_names, ltf); +} +/*! Map string constants to enum log_timestamp_format values. */ +static inline enum log_timestamp_format log_timestamp_format_val(const char *str) +{ + return (enum log_timestamp_format)get_string_value(log_timestamp_format_names, str); +} + /*! structure representing a logging target */ struct log_target { struct llist_head entry; /*!< linked list */ diff --git a/src/core/libosmocore.map b/src/core/libosmocore.map index 0cd6d3df..ac34a784 100644 --- a/src/core/libosmocore.map +++ b/src/core/libosmocore.map @@ -77,6 +77,7 @@ log_set_print_category; log_set_print_category_hex; log_set_print_extended_timestamp; log_set_print_timestamp2; +log_timestamp_format_names; log_set_print_filename; log_set_print_filename2; log_set_print_filename_pos; diff --git a/src/core/logging.c b/src/core/logging.c index 53e7de26..218652fa 100644 --- a/src/core/logging.c +++ b/src/core/logging.c @@ -1577,4 +1577,12 @@ int log_check_level(int subsys, unsigned int level) return 0; } +/*! Mapping between enum log_timestamp_format and strings. */ +const struct value_string log_timestamp_format_names[] = { + { LOG_TIMESTAMP_NONE, "none" }, + { LOG_TIMESTAMP_DATE_PACKED, "date-packed" }, + { LOG_TIMESTAMP_CTIME, "ctime" }, + {} +}; + /*! @} */ diff --git a/src/vty/logging_vty.c b/src/vty/logging_vty.c index d3c8b870..f76810f3 100644 --- a/src/vty/logging_vty.c +++ b/src/vty/logging_vty.c @@ -206,34 +206,40 @@ DEFUN(logging_timezone, RET_WITH_UNLOCK(CMD_SUCCESS); } -DEFUN(logging_timestamp, +DEFUN_DEPRECATED(logging_timestamp, logging_timestamp_cmd, "logging timestamp (0|1)", - LOGGING_STR "Configure log message timestamping\n" + LOGGING_STR "Use 'logging print timestamp' instead --" + " Configure log message timestamping\n" "Don't prefix each log message\n" - "Prefix each log message with current timestamp\n") + "Prefix each log message with a verbose date format as returned by ctime()\n") { struct log_target *tgt; ACQUIRE_VTY_LOG_TGT_WITH_LOCK(vty, tgt); log_set_print_timestamp2(tgt, atoi(argv[0]) ? LOG_TIMESTAMP_CTIME : LOG_TIMESTAMP_NONE); + vty_out(vty, "%% Deprecated: do not use 'logging timestamp (0|1)' anymore," + " instead use 'logging print timestamp (none|ctime)'%s", VTY_NEWLINE); RET_WITH_UNLOCK(CMD_SUCCESS); } -DEFUN(logging_prnt_ext_timestamp, +DEFUN_DEPRECATED(logging_prnt_ext_timestamp, logging_prnt_ext_timestamp_cmd, "logging print extended-timestamp (0|1)", LOGGING_STR "Log output settings\n" - "Configure log message timestamping\n" + "Use 'logging print timestamp' instead --" + " Configure log message date-packed timestamping\n" "Don't prefix each log message\n" - "Prefix each log message with current timestamp with YYYYMMDDhhmmssnnn\n") + "Prefix each log message with current timestamp as YYYYMMDDhhmmssnnn\n") { struct log_target *tgt; ACQUIRE_VTY_LOG_TGT_WITH_LOCK(vty, tgt); log_set_print_timestamp2(tgt, atoi(argv[0]) ? LOG_TIMESTAMP_DATE_PACKED : LOG_TIMESTAMP_NONE); + vty_out(vty, "%% Deprecated: do not use 'logging print extended-timestamp (0|1)' anymore," + " instead use 'logging print timestamp (none|date-packed)'%s", VTY_NEWLINE); RET_WITH_UNLOCK(CMD_SUCCESS); } @@ -253,6 +259,31 @@ DEFUN(logging_prnt_tid, RET_WITH_UNLOCK(CMD_SUCCESS); } +DEFUN(logging_prnt_timestamp, + logging_prnt_timestamp_cmd, + "logging print timestamp (none|date-packed|ctime)", + LOGGING_STR "Log output settings\n" + "Configure log message timestamping\n" + "Don't prefix each log message\n" + "Prefix with YYYYMMDDHHmmssmmm\n" + "Prefix with a verbose date format as returned by ctime()\n") +{ + struct log_target *tgt = osmo_log_vty2tgt(vty); + unsigned int val; + + if (!tgt) + return CMD_WARNING; + + val = log_timestamp_format_val(argv[0]); + if (val < 0) { + vty_out(vty, "Could not parse argument: '%s'%s", argv[0], VTY_NEWLINE); + return CMD_WARNING; + } + + log_set_print_timestamp2(tgt, val); + return CMD_SUCCESS; +} + DEFUN(logging_prnt_cat, logging_prnt_cat_cmd, "logging print category (0|1)", @@ -1073,17 +1104,9 @@ static int config_write_log_single(struct vty *vty, struct log_target *tgt) vty_out(vty, " logging print thread-id %d%s", tgt->print_tid ? 1 : 0, VTY_NEWLINE); - switch (tgt->timestamp_format) { - case LOG_TIMESTAMP_DATE_PACKED: - vty_out(vty, " logging print extended-timestamp 1%s", VTY_NEWLINE); - break; - case LOG_TIMESTAMP_CTIME: - vty_out(vty, " logging timestamp 1%s", VTY_NEWLINE); - break; - default: - vty_out(vty, " logging timestamp 0%s", VTY_NEWLINE); - break; - } + if (tgt->timestamp_format != LOG_TIMESTAMP_NONE) + vty_out(vty, " logging print timestamp %s%s", + log_timestamp_format_name(tgt->timestamp_format), VTY_NEWLINE); switch (tgt->timezone) { case LOG_TIMEZONE_UTC: @@ -1237,6 +1260,7 @@ void logging_vty_add_cmds(void) install_lib_element_ve(&logging_fltr_all_cmd); install_lib_element_ve(&logging_use_clr_cmd); install_lib_element_ve(&logging_timestamp_cmd); + install_lib_element_ve(&logging_prnt_timestamp_cmd); install_lib_element_ve(&logging_prnt_ext_timestamp_cmd); install_lib_element_ve(&logging_timezone_cmd); install_lib_element_ve(&logging_prnt_tid_cmd); @@ -1273,6 +1297,7 @@ void logging_vty_add_cmds(void) install_lib_element(CFG_LOG_NODE, &logging_fltr_all_cmd); install_lib_element(CFG_LOG_NODE, &logging_use_clr_cmd); install_lib_element(CFG_LOG_NODE, &logging_timestamp_cmd); + install_lib_element(CFG_LOG_NODE, &logging_prnt_timestamp_cmd); install_lib_element(CFG_LOG_NODE, &logging_prnt_ext_timestamp_cmd); install_lib_element(CFG_LOG_NODE, &logging_timezone_cmd); install_lib_element(CFG_LOG_NODE, &logging_prnt_tid_cmd); diff --git a/tests/logging/logging_vty_test.vty b/tests/logging/logging_vty_test.vty index fa94cdd5..2fad234a 100644 --- a/tests/logging/logging_vty_test.vty +++ b/tests/logging/logging_vty_test.vty @@ -46,8 +46,7 @@ logging_vty_test# list logging disable logging filter all (0|1) logging color (0|1) - logging timestamp (0|1) - logging print extended-timestamp (0|1) + logging print timestamp (none|date-packed|ctime) logging timezone (localtime|utc) logging print thread-id (0|1) logging print category (0|1) @@ -66,15 +65,14 @@ logging_vty_test# logging ? disable Disables logging to this vty filter Filter log messages color Configure color-printing for log messages - timestamp Configure log message timestamping print Log output settings timezone Configure time zone for log message timestamping set-log-mask Set the logmask of this logging target level Set the log level for a specified category +logging_vty_test# ### Deprecated command's doc not shown logging_vty_test# logging timestamp ? - 0 Don't prefix each log message - 1 Prefix each log message with current timestamp +% There is no matched command. logging_vty_test# logging timezone ? localtime Log timestamps in the system's local time @@ -120,16 +118,21 @@ logging_vty_test# logging level set-all ? fatal Log only fatal messages logging_vty_test# logging print ? - extended-timestamp Configure log message timestamping - thread-id Configure log message logging Thread ID - category Configure log message - category-hex Configure log message - level Configure log message - file Configure log message - + timestamp Configure log message timestamping + thread-id Configure log message logging Thread ID + category Configure log message + category-hex Configure log message + level Configure log message + file Configure log message + +logging_vty_test# logging print timestamp ? + none Don't prefix each log message + date-packed Prefix with YYYYMMDDHHmmssmmm + ctime Prefix with a verbose date format as returned by ctime() + +logging_vty_test# ### Deprecated command's doc not shown logging_vty_test# logging print extended-timestamp ? - 0 Don't prefix each log message - 1 Prefix each log message with current timestamp with YYYYMMDDhhmmssnnn +% There is no matched command. logging_vty_test# logging print thread-id ? 0 Don't prefix each log message @@ -179,52 +182,73 @@ logging_vty_test(config-log)# show running-config ... log stderr ... !timestamp - logging timestamp 0 + +logging_vty_test(config-log)# logging print timestamp date-packed +logging_vty_test(config-log)# show running-config +... +log stderr +... !timestamp + logging print timestamp date-packed +... !timestamp + +logging_vty_test(config-log)# logging print timestamp ctime +logging_vty_test(config-log)# show running-config +... +log stderr +... !timestamp + logging print timestamp ctime +... !timestamp + +logging_vty_test(config-log)# logging print timestamp none +logging_vty_test(config-log)# show running-config +... +log stderr ... !timestamp +logging_vty_test(config-log)# ### Legacy cmds still work: 'logging timestamp' and 'logging print extended-timestamp' logging_vty_test(config-log)# logging timestamp 1 +% Deprecated: do not use 'logging timestamp (0|1)' anymore, instead use 'logging print timestamp (none|ctime)' logging_vty_test(config-log)# show running-config ... log stderr ... !timestamp - logging timestamp 1 + logging print timestamp ctime ... !timestamp logging_vty_test(config-log)# ### with 'extended-timestamp 1', 'logging timestamp' is not shown logging_vty_test(config-log)# logging print extended-timestamp 1 +% Deprecated: do not use 'logging print extended-timestamp (0|1)' anymore, instead use 'logging print timestamp (none|date-packed)' logging_vty_test(config-log)# show running-config ... log stderr ... !timestamp - logging print extended-timestamp 1 + logging print timestamp date-packed ... !timestamp logging_vty_test(config-log)# ### 'timestamp 0' also removes 'extended-timestamp 1' logging_vty_test(config-log)# logging timestamp 0 +% Deprecated: do not use 'logging timestamp (0|1)' anymore, instead use 'logging print timestamp (none|ctime)' logging_vty_test(config-log)# show running-config ... log stderr ... !timestamp - logging timestamp 0 -... !timestamp logging_vty_test(config-log)# ### 'extended-timestamp 0' also removes 'timestamp 1' logging_vty_test(config-log)# logging timestamp 1 +% Deprecated: do not use 'logging timestamp (0|1)' anymore, instead use 'logging print timestamp (none|ctime)' logging_vty_test(config-log)# logging print extended-timestamp 0 +% Deprecated: do not use 'logging print extended-timestamp (0|1)' anymore, instead use 'logging print timestamp (none|date-packed)' logging_vty_test(config-log)# show running-config ... log stderr ... !timestamp - logging timestamp 0 -... !timestamp logging_vty_test(config-log)# logging timestamp 0 +% Deprecated: do not use 'logging timestamp (0|1)' anymore, instead use 'logging print timestamp (none|ctime)' logging_vty_test(config-log)# show running-config ... log stderr ... !timestamp - logging timestamp 0 -... !timestamp logging_vty_test(config-log)# exit logging_vty_test(config)# no log stderr @@ -232,24 +256,46 @@ logging_vty_test(config)# exit logging_vty_test# logging timezone utc +logging_vty_test# log-test +DAA DEBUG :) + +logging_vty_test# logging print timestamp ctime +logging_vty_test# log-test +Sun Sep 23 20:55:00 1979 DAA DEBUG :) + +logging_vty_test# logging print timestamp date-packed +logging_vty_test# log-test +19790923205500423423 DAA DEBUG :) + +logging_vty_test# logging print timestamp none +logging_vty_test# log-test +DAA DEBUG :) + +logging_vty_test# ### Legacy cmds still work: 'logging timestamp' and 'logging print extended-timestamp' logging_vty_test# logging timestamp 1 +% Deprecated: do not use 'logging timestamp (0|1)' anymore, instead use 'logging print timestamp (none|ctime)' logging_vty_test# log-test Sun Sep 23 20:55:00 1979 DAA DEBUG :) logging_vty_test# logging print extended-timestamp 1 +% Deprecated: do not use 'logging print extended-timestamp (0|1)' anymore, instead use 'logging print timestamp (none|date-packed)' logging_vty_test# log-test 19790923205500423423 DAA DEBUG :) logging_vty_test# logging timestamp 0 +% Deprecated: do not use 'logging timestamp (0|1)' anymore, instead use 'logging print timestamp (none|ctime)' logging_vty_test# log-test DAA DEBUG :) logging_vty_test# logging timestamp 1 +% Deprecated: do not use 'logging timestamp (0|1)' anymore, instead use 'logging print timestamp (none|ctime)' logging_vty_test# logging print extended-timestamp 0 +% Deprecated: do not use 'logging print extended-timestamp (0|1)' anymore, instead use 'logging print timestamp (none|date-packed)' logging_vty_test# log-test DAA DEBUG :) logging_vty_test# logging timestamp 0 +% Deprecated: do not use 'logging timestamp (0|1)' anymore, instead use 'logging print timestamp (none|ctime)' logging_vty_test# log-test DAA DEBUG :) |