aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeels Hofmeyr <neels@hofmeyr.de>2018-01-18 01:38:14 +0100
committerNeels Hofmeyr <nhofmeyr@sysmocom.de>2024-05-07 18:06:47 +0200
commit53ed56a805cc9954a93662fc15b764126de26ab9 (patch)
tree6555aa5162c86e682498562cdf6d0a251a2e89b4
parent71bf79b6aa2d7b8e8d68c9884b2d3dbb3355699e (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-RELEASE3
-rw-r--r--include/osmocom/core/logging.h14
-rw-r--r--src/core/libosmocore.map1
-rw-r--r--src/core/logging.c8
-rw-r--r--src/vty/logging_vty.c59
5 files changed, 67 insertions, 18 deletions
diff --git a/TODO-RELEASE b/TODO-RELEASE
index 851e16e8..ec54696b 100644
--- a/TODO-RELEASE
+++ b/TODO-RELEASE
@@ -31,4 +31,5 @@ libosmocore deprecate API log_set_print_extended_timestamp() replaced by log_set
the behavior of calling log_set_print_timestamp(0) and
log_set_print_extended_timestamp(0) changes: when calling with zero
argument, logging now always snaps back to LOG_TIMSTAMP_NONE, instead of
- the current behavior: maybe go to LOG_TIMSTAMP_CTIME, depending on what flags were otherwise set.
+vty logging deprecate cfg 'logging timestamp (0|1)' deprecated, replaced by 'logging print timestamp (none|ctime)'
+vty logging deprecate cfg '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 26162bff..623b9319 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;
@@ -303,6 +304,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 3a344474..63053fd8 100644
--- a/src/core/libosmocore.map
+++ b/src/core/libosmocore.map
@@ -83,6 +83,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 04bd34e5..7a271381 100644
--- a/src/core/logging.c
+++ b/src/core/logging.c
@@ -1695,4 +1695,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 0f2ca8c7..a22d5469 100644
--- a/src/vty/logging_vty.c
+++ b/src/vty/logging_vty.c
@@ -190,34 +190,40 @@ DEFUN(logging_use_clr,
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);
}
@@ -237,6 +243,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)",
@@ -1063,17 +1094,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);
if (tgt->print_level)
vty_out(vty, " logging print level 1%s", VTY_NEWLINE);
@@ -1217,6 +1240,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_prnt_tid_cmd);
install_lib_element_ve(&logging_prnt_cat_cmd);
@@ -1252,6 +1276,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_prnt_tid_cmd);
install_lib_element(CFG_LOG_NODE, &logging_prnt_cat_cmd);