diff options
Diffstat (limited to 'src/vty/logging_vty.c')
-rw-r--r-- | src/vty/logging_vty.c | 296 |
1 files changed, 225 insertions, 71 deletions
diff --git a/src/vty/logging_vty.c b/src/vty/logging_vty.c index c51b4373..678ae686 100644 --- a/src/vty/logging_vty.c +++ b/src/vty/logging_vty.c @@ -15,16 +15,12 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * */ #include <stdlib.h> #include <string.h> -#include "../../config.h" +#include "config.h" #include <osmocom/core/talloc.h> #include <osmocom/core/logging.h> @@ -33,6 +29,7 @@ #include <osmocom/core/strrb.h> #include <osmocom/core/loggingrb.h> #include <osmocom/core/gsmtap.h> +#include <osmocom/core/application.h> #include <osmocom/vty/command.h> #include <osmocom/vty/buffer.h> @@ -130,7 +127,7 @@ DEFUN(enable_logging, conn = (struct telnet_connection *) vty->priv; if (conn->dbg) { - vty_out(vty, "Logging already enabled.%s", VTY_NEWLINE); + vty_out(vty, "%% Logging already enabled.%s", VTY_NEWLINE); return CMD_WARNING; } @@ -157,7 +154,7 @@ struct log_target *osmo_log_vty2tgt(struct vty *vty) conn = (struct telnet_connection *) vty->priv; if (!conn->dbg) - vty_out(vty, "Logging was not enabled.%s", VTY_NEWLINE); + vty_out(vty, "%% Logging was not enabled.%s", VTY_NEWLINE); return conn->dbg; } @@ -224,6 +221,22 @@ DEFUN(logging_prnt_ext_timestamp, RET_WITH_UNLOCK(CMD_SUCCESS); } +DEFUN(logging_prnt_tid, + logging_prnt_tid_cmd, + "logging print thread-id (0|1)", + LOGGING_STR "Log output settings\n" + "Configure log message logging Thread ID\n" + "Don't prefix each log message\n" + "Prefix each log message with current Thread ID\n") +{ + struct log_target *tgt; + + ACQUIRE_VTY_LOG_TGT_WITH_LOCK(vty, tgt); + + log_set_print_tid(tgt, atoi(argv[0])); + RET_WITH_UNLOCK(CMD_SUCCESS); +} + DEFUN(logging_prnt_cat, logging_prnt_cat_cmd, "logging print category (0|1)", @@ -337,6 +350,9 @@ static void gen_logging_level_cmd_strs(struct cmd_element *cmd, osmo_talloc_asprintf(tall_log_ctx, cmd_str, ") %s", level_args); osmo_talloc_asprintf(tall_log_ctx, doc_str, "%s", level_strs); + talloc_set_name_const(cmd_str, "vty_log_level_cmd_str"); + talloc_set_name_const(doc_str, "vty_log_level_doc_str"); + cmd->string = cmd_str; cmd->doc = doc_str; } @@ -352,12 +368,12 @@ DEFUN(logging_level, int level = log_parse_level(argv[1]); if (level < 0) { - vty_out(vty, "Invalid level `%s'%s", argv[1], VTY_NEWLINE); + vty_out(vty, "%% Invalid level '%s'%s", argv[1], VTY_NEWLINE); return CMD_WARNING; } if (category < 0) { - vty_out(vty, "Invalid category `%s'%s", argv[0], VTY_NEWLINE); + vty_out(vty, "%% Invalid category '%s'%s", argv[0], VTY_NEWLINE); return CMD_WARNING; } @@ -366,6 +382,10 @@ DEFUN(logging_level, tgt->categories[category].enabled = 1; tgt->categories[category].loglevel = level; +#if !defined(EMBEDDED) + log_cache_update(category, 1, level); +#endif + RET_WITH_UNLOCK(CMD_SUCCESS); } @@ -390,6 +410,9 @@ DEFUN(logging_level_set_all, logging_level_set_all_cmd, cat->enabled = 1; cat->loglevel = level; +#if !defined(EMBEDDED) + log_cache_update(i, 1, level); +#endif } RET_WITH_UNLOCK(CMD_SUCCESS); } @@ -575,7 +598,7 @@ gDEFUN(cfg_description, cfg_description_cmd, char **dptr = vty->index_sub; if (!dptr) { - vty_out(vty, "vty->index_sub == NULL%s", VTY_NEWLINE); + vty_out(vty, "%% vty->index_sub == NULL%s", VTY_NEWLINE); return CMD_WARNING; } @@ -596,7 +619,7 @@ gDEFUN(cfg_no_description, cfg_no_description_cmd, char **dptr = vty->index_sub; if (!dptr) { - vty_out(vty, "vty->index_sub == NULL%s", VTY_NEWLINE); + vty_out(vty, "%% vty->index_sub == NULL%s", VTY_NEWLINE); return CMD_WARNING; } @@ -728,6 +751,64 @@ DEFUN(cfg_no_log_syslog, cfg_no_log_syslog_cmd, } #endif /* HAVE_SYSLOG_H */ +DEFUN(cfg_log_systemd_journal, cfg_log_systemd_journal_cmd, + "log systemd-journal [raw]", + LOG_STR "Logging to systemd-journal\n" + "Offload rendering of the meta information (location, category) to systemd\n") +{ +#ifdef ENABLE_SYSTEMD_LOGGING + struct log_target *tgt; + bool raw = argc > 0; + + log_tgt_mutex_lock(); + tgt = log_target_find(LOG_TGT_TYPE_SYSTEMD, NULL); + if (tgt == NULL) { + tgt = log_target_create_systemd(raw); + if (tgt == NULL) { + vty_out(vty, "%% Unable to create systemd-journal " + "log target%s", VTY_NEWLINE); + RET_WITH_UNLOCK(CMD_WARNING); + } + log_add_target(tgt); + } else if (tgt->sd_journal.raw != raw) { + log_target_systemd_set_raw(tgt, raw); + } + + vty->index = tgt; + vty->node = CFG_LOG_NODE; + + RET_WITH_UNLOCK(CMD_SUCCESS); +#else + vty_out(vty, "%% systemd-journal logging is not available " + "in this build of libosmocore%s", VTY_NEWLINE); + return CMD_WARNING; +#endif /* ENABLE_SYSTEMD_LOGGING */ +} + +DEFUN(cfg_no_log_systemd_journal, cfg_no_log_systemd_journal_cmd, + "no log systemd-journal", + NO_STR LOG_STR "Logging to systemd-journal\n") +{ +#ifdef ENABLE_SYSTEMD_LOGGING + struct log_target *tgt; + + log_tgt_mutex_lock(); + tgt = log_target_find(LOG_TGT_TYPE_SYSTEMD, NULL); + if (!tgt) { + vty_out(vty, "%% No systemd-journal logging active%s", VTY_NEWLINE); + RET_WITH_UNLOCK(CMD_WARNING); + } + + log_target_destroy(tgt); + + RET_WITH_UNLOCK(CMD_SUCCESS); +#else + vty_out(vty, "%% systemd-journal logging is not available " + "in this build of libosmocore%s", VTY_NEWLINE); + return CMD_WARNING; +#endif /* ENABLE_SYSTEMD_LOGGING */ +} + DEFUN(cfg_log_gsmtap, cfg_log_gsmtap_cmd, "log gsmtap [HOSTNAME]", LOG_STR "Logging via GSMTAP\n" @@ -756,9 +837,31 @@ DEFUN(cfg_log_gsmtap, cfg_log_gsmtap_cmd, RET_WITH_UNLOCK(CMD_SUCCESS); } +DEFUN(cfg_no_log_gsmtap, cfg_no_log_gsmtap_cmd, + "no log gsmtap [HOSTNAME]", + NO_STR LOG_STR "Logging via GSMTAP\n" + "Host name to send the GSMTAP logging to (UDP port 4729)\n") +{ + const char *hostname = argc ? argv[0] : "127.0.0.1"; + struct log_target *tgt; + + log_tgt_mutex_lock(); + tgt = log_target_find(LOG_TGT_TYPE_GSMTAP, hostname); + if (tgt == NULL) { + vty_out(vty, "%% Unable to find GSMTAP log target for %s%s", + hostname, VTY_NEWLINE); + RET_WITH_UNLOCK(CMD_WARNING); + } + + log_target_destroy(tgt); + + RET_WITH_UNLOCK(CMD_SUCCESS); +} + DEFUN(cfg_log_stderr, cfg_log_stderr_cmd, - "log stderr", - LOG_STR "Logging via STDERR of the process\n") + "log stderr [blocking-io]", + LOG_STR "Logging via STDERR of the process\n" + "Use blocking, synchronous I/O\n") { struct log_target *tgt; @@ -774,6 +877,11 @@ DEFUN(cfg_log_stderr, cfg_log_stderr_cmd, log_add_target(tgt); } + if (argc > 0 && !strcmp(argv[0], "blocking-io")) + log_target_file_switch_to_stream(tgt); + else + log_target_file_switch_to_wqueue(tgt); + vty->index = tgt; vty->node = CFG_LOG_NODE; @@ -794,13 +902,15 @@ DEFUN(cfg_no_log_stderr, cfg_no_log_stderr_cmd, } log_target_destroy(tgt); + osmo_stderr_target = NULL; RET_WITH_UNLOCK(CMD_SUCCESS); } DEFUN(cfg_log_file, cfg_log_file_cmd, - "log file .FILENAME", - LOG_STR "Logging to text file\n" "Filename\n") + "log file FILENAME [blocking-io]", + LOG_STR "Logging to text file\n" "Filename\n" + "Use blocking, synchronous I/O\n") { const char *fname = argv[0]; struct log_target *tgt; @@ -810,13 +920,18 @@ DEFUN(cfg_log_file, cfg_log_file_cmd, if (!tgt) { tgt = log_target_create_file(fname); if (!tgt) { - vty_out(vty, "%% Unable to create file `%s'%s", + vty_out(vty, "%% Unable to create file '%s'%s", fname, VTY_NEWLINE); RET_WITH_UNLOCK(CMD_WARNING); } log_add_target(tgt); } + if (argc > 1 && !strcmp(argv[1], "blocking-io")) + log_target_file_switch_to_stream(tgt); + else + log_target_file_switch_to_wqueue(tgt); + vty->index = tgt; vty->node = CFG_LOG_NODE; @@ -825,7 +940,7 @@ DEFUN(cfg_log_file, cfg_log_file_cmd, DEFUN(cfg_no_log_file, cfg_no_log_file_cmd, - "no log file .FILENAME", + "no log file FILENAME", NO_STR LOG_STR "Logging to text file\n" "Filename\n") { const char *fname = argv[0]; @@ -834,7 +949,7 @@ DEFUN(cfg_no_log_file, cfg_no_log_file_cmd, log_tgt_mutex_lock(); tgt = log_target_find(LOG_TGT_TYPE_FILE, fname); if (!tgt) { - vty_out(vty, "%% No such log file `%s'%s", + vty_out(vty, "%% No such log file '%s'%s", fname, VTY_NEWLINE); RET_WITH_UNLOCK(CMD_WARNING); } @@ -900,7 +1015,10 @@ static int config_write_log_single(struct vty *vty, struct log_target *tgt) return 1; break; case LOG_TGT_TYPE_STDERR: - vty_out(vty, "log stderr%s", VTY_NEWLINE); + if (tgt->tgt_file.wqueue) + vty_out(vty, "log stderr%s", VTY_NEWLINE); + else + vty_out(vty, "log stderr blocking-io%s", VTY_NEWLINE); break; case LOG_TGT_TYPE_SYSLOG: #ifdef HAVE_SYSLOG_H @@ -911,7 +1029,10 @@ static int config_write_log_single(struct vty *vty, struct log_target *tgt) #endif break; case LOG_TGT_TYPE_FILE: - vty_out(vty, "log file %s%s", tgt->tgt_file.fname, VTY_NEWLINE); + if (tgt->tgt_file.wqueue) + vty_out(vty, "log file %s%s", tgt->tgt_file.fname, VTY_NEWLINE); + else + vty_out(vty, "log file %s blocking-io%s", tgt->tgt_file.fname, VTY_NEWLINE); break; case LOG_TGT_TYPE_STRRB: vty_out(vty, "log alarms %zu%s", @@ -921,6 +1042,11 @@ static int config_write_log_single(struct vty *vty, struct log_target *tgt) vty_out(vty, "log gsmtap %s%s", tgt->tgt_gsmtap.hostname, VTY_NEWLINE); break; + case LOG_TGT_TYPE_SYSTEMD: + vty_out(vty, "log systemd-journal%s%s", + tgt->sd_journal.raw ? " raw" : "", + VTY_NEWLINE); + break; } vty_out(vty, " logging filter all %u%s", @@ -935,6 +1061,8 @@ static int config_write_log_single(struct vty *vty, struct log_target *tgt) tgt->print_category_hex ? 1 : 0, VTY_NEWLINE); vty_out(vty, " logging print category %d%s", tgt->print_category ? 1 : 0, VTY_NEWLINE); + vty_out(vty, " logging print thread-id %d%s", + tgt->print_tid ? 1 : 0, VTY_NEWLINE); if (tgt->print_ext_timestamp) vty_out(vty, " logging print extended-timestamp 1%s", VTY_NEWLINE); else @@ -942,8 +1070,9 @@ static int config_write_log_single(struct vty *vty, struct log_target *tgt) tgt->print_timestamp ? 1 : 0, VTY_NEWLINE); if (tgt->print_level) vty_out(vty, " logging print level 1%s", VTY_NEWLINE); - vty_out(vty, " logging print file %s%s", + vty_out(vty, " logging print file %s%s%s", get_value_string(logging_print_file_args, tgt->print_filename2), + tgt->print_filename_pos == LOG_FILENAME_POS_LINE_END ? " last" : "", VTY_NEWLINE); if (tgt->loglevel) { @@ -1011,7 +1140,7 @@ void logging_vty_add_deprecated_subsys(void *ctx, const char *name) "Deprecated Category\n"; cmd->attr = CMD_ATTR_DEPRECATED; - install_element(CFG_LOG_NODE, cmd); + install_lib_element(CFG_LOG_NODE, cmd); } /* logp (<categories>) (debug|...|fatal) .LOGMESSAGE*/ @@ -1023,6 +1152,23 @@ DEFUN(vty_logp, int category = log_parse_category(argv[0]); int level = log_parse_level(argv[1]); char *str = argv_concat(argv, argc, 2); + + if (level < 0) { + vty_out(vty, "%% Invalid level '%s'%s", argv[1], VTY_NEWLINE); + return CMD_WARNING; + } + + if (category < 0) { + vty_out(vty, "%% Invalid category '%s'%s", argv[0], VTY_NEWLINE); + return CMD_WARNING; + } + + /* Properly handle library specific sub-systems */ + if ((unsigned int) category >= osmo_log_info->num_cat_user) { + category -= osmo_log_info->num_cat_user - 1; + category *= -1; + } + LOGP(category, level, "%s\n", str); return CMD_SUCCESS; } @@ -1048,26 +1194,30 @@ static void gen_vty_logp_cmd_strs(struct cmd_element *cmd) osmo_talloc_asprintf(tall_log_ctx, doc_str, "Arbitrary message to log on given category and log level\n"); + talloc_set_name_const(cmd_str, "vty_logp_cmd_str"); + talloc_set_name_const(doc_str, "vty_logp_doc_str"); + cmd->string = cmd_str; cmd->doc = doc_str; } /*! Register logging related commands to the VTY. Call this once from * your application if you want to support those commands. */ -void logging_vty_add_cmds() +void logging_vty_add_cmds(void) { - install_element_ve(&enable_logging_cmd); - install_element_ve(&disable_logging_cmd); - install_element_ve(&logging_fltr_all_cmd); - install_element_ve(&logging_use_clr_cmd); - install_element_ve(&logging_prnt_timestamp_cmd); - install_element_ve(&logging_prnt_ext_timestamp_cmd); - install_element_ve(&logging_prnt_cat_cmd); - install_element_ve(&logging_prnt_cat_hex_cmd); - install_element_ve(&logging_prnt_level_cmd); - install_element_ve(&logging_prnt_file_cmd); - install_element_ve(&logging_set_category_mask_cmd); - install_element_ve(&logging_set_category_mask_old_cmd); + install_lib_element_ve(&enable_logging_cmd); + install_lib_element_ve(&disable_logging_cmd); + install_lib_element_ve(&logging_fltr_all_cmd); + install_lib_element_ve(&logging_use_clr_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); + install_lib_element_ve(&logging_prnt_cat_hex_cmd); + install_lib_element_ve(&logging_prnt_level_cmd); + install_lib_element_ve(&logging_prnt_file_cmd); + install_lib_element_ve(&logging_set_category_mask_cmd); + install_lib_element_ve(&logging_set_category_mask_old_cmd); /* logging level (<categories>) (debug|...|fatal) */ gen_logging_level_cmd_strs(&logging_level_cmd, @@ -1077,47 +1227,51 @@ void logging_vty_add_cmds() gen_logging_level_cmd_strs(&deprecated_logging_level_everything_cmd, "everything", EVERYTHING_STR); - install_element_ve(&logging_level_cmd); - install_element_ve(&logging_level_set_all_cmd); - install_element_ve(&logging_level_force_all_cmd); - install_element_ve(&no_logging_level_force_all_cmd); - install_element_ve(&deprecated_logging_level_everything_cmd); - install_element_ve(&deprecated_logging_level_all_cmd); - install_element_ve(&deprecated_logging_level_all_everything_cmd); + install_lib_element_ve(&logging_level_cmd); + install_lib_element_ve(&logging_level_set_all_cmd); + install_lib_element_ve(&logging_level_force_all_cmd); + install_lib_element_ve(&no_logging_level_force_all_cmd); + install_lib_element_ve(&deprecated_logging_level_everything_cmd); + install_lib_element_ve(&deprecated_logging_level_all_cmd); + install_lib_element_ve(&deprecated_logging_level_all_everything_cmd); gen_vty_logp_cmd_strs(&vty_logp_cmd); - install_element_ve(&vty_logp_cmd); + install_lib_element_ve(&vty_logp_cmd); - install_element_ve(&show_logging_vty_cmd); - install_element_ve(&show_alarms_cmd); + install_lib_element_ve(&show_logging_vty_cmd); + install_lib_element_ve(&show_alarms_cmd); install_node(&cfg_log_node, config_write_log); - install_element(CFG_LOG_NODE, &logging_fltr_all_cmd); - install_element(CFG_LOG_NODE, &logging_use_clr_cmd); - install_element(CFG_LOG_NODE, &logging_prnt_timestamp_cmd); - install_element(CFG_LOG_NODE, &logging_prnt_ext_timestamp_cmd); - install_element(CFG_LOG_NODE, &logging_prnt_cat_cmd); - install_element(CFG_LOG_NODE, &logging_prnt_cat_hex_cmd); - install_element(CFG_LOG_NODE, &logging_prnt_level_cmd); - install_element(CFG_LOG_NODE, &logging_prnt_file_cmd); - install_element(CFG_LOG_NODE, &logging_level_cmd); - install_element(CFG_LOG_NODE, &logging_level_set_all_cmd); - install_element(CFG_LOG_NODE, &logging_level_force_all_cmd); - install_element(CFG_LOG_NODE, &no_logging_level_force_all_cmd); - install_element(CFG_LOG_NODE, &deprecated_logging_level_everything_cmd); - install_element(CFG_LOG_NODE, &deprecated_logging_level_all_cmd); - install_element(CFG_LOG_NODE, &deprecated_logging_level_all_everything_cmd); - - install_element(CONFIG_NODE, &cfg_log_stderr_cmd); - install_element(CONFIG_NODE, &cfg_no_log_stderr_cmd); - install_element(CONFIG_NODE, &cfg_log_file_cmd); - install_element(CONFIG_NODE, &cfg_no_log_file_cmd); - install_element(CONFIG_NODE, &cfg_log_alarms_cmd); - install_element(CONFIG_NODE, &cfg_no_log_alarms_cmd); + 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_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); + install_lib_element(CFG_LOG_NODE, &logging_prnt_cat_hex_cmd); + install_lib_element(CFG_LOG_NODE, &logging_prnt_level_cmd); + install_lib_element(CFG_LOG_NODE, &logging_prnt_file_cmd); + install_lib_element(CFG_LOG_NODE, &logging_level_cmd); + install_lib_element(CFG_LOG_NODE, &logging_level_set_all_cmd); + install_lib_element(CFG_LOG_NODE, &logging_level_force_all_cmd); + install_lib_element(CFG_LOG_NODE, &no_logging_level_force_all_cmd); + install_lib_element(CFG_LOG_NODE, &deprecated_logging_level_everything_cmd); + install_lib_element(CFG_LOG_NODE, &deprecated_logging_level_all_cmd); + install_lib_element(CFG_LOG_NODE, &deprecated_logging_level_all_everything_cmd); + + install_lib_element(CONFIG_NODE, &cfg_log_stderr_cmd); + install_lib_element(CONFIG_NODE, &cfg_no_log_stderr_cmd); + install_lib_element(CONFIG_NODE, &cfg_log_file_cmd); + install_lib_element(CONFIG_NODE, &cfg_no_log_file_cmd); + install_lib_element(CONFIG_NODE, &cfg_log_alarms_cmd); + install_lib_element(CONFIG_NODE, &cfg_no_log_alarms_cmd); #ifdef HAVE_SYSLOG_H - install_element(CONFIG_NODE, &cfg_log_syslog_cmd); - install_element(CONFIG_NODE, &cfg_log_syslog_local_cmd); - install_element(CONFIG_NODE, &cfg_no_log_syslog_cmd); + install_lib_element(CONFIG_NODE, &cfg_log_syslog_cmd); + install_lib_element(CONFIG_NODE, &cfg_log_syslog_local_cmd); + install_lib_element(CONFIG_NODE, &cfg_no_log_syslog_cmd); #endif - install_element(CONFIG_NODE, &cfg_log_gsmtap_cmd); + install_lib_element(CONFIG_NODE, &cfg_log_systemd_journal_cmd); + install_lib_element(CONFIG_NODE, &cfg_no_log_systemd_journal_cmd); + install_lib_element(CONFIG_NODE, &cfg_log_gsmtap_cmd); + install_lib_element(CONFIG_NODE, &cfg_no_log_gsmtap_cmd); } |