aboutsummaryrefslogtreecommitdiffstats
path: root/src/vty/logging_vty.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/vty/logging_vty.c')
-rw-r--r--src/vty/logging_vty.c190
1 files changed, 168 insertions, 22 deletions
diff --git a/src/vty/logging_vty.c b/src/vty/logging_vty.c
index 200b45a1..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>
@@ -131,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;
}
@@ -158,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;
}
@@ -225,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)",
@@ -356,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;
}
@@ -370,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);
}
@@ -394,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);
}
@@ -579,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;
}
@@ -600,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;
}
@@ -732,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"
@@ -760,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;
@@ -778,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;
@@ -804,8 +908,9 @@ DEFUN(cfg_no_log_stderr, cfg_no_log_stderr_cmd,
}
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;
@@ -815,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;
@@ -830,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];
@@ -839,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);
}
@@ -905,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
@@ -916,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",
@@ -926,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",
@@ -940,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
@@ -947,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) {
@@ -1028,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;
}
@@ -1062,7 +1203,7 @@ static void gen_vty_logp_cmd_strs(struct cmd_element *cmd)
/*! 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_lib_element_ve(&enable_logging_cmd);
install_lib_element_ve(&disable_logging_cmd);
@@ -1070,6 +1211,7 @@ void logging_vty_add_cmds()
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);
@@ -1104,6 +1246,7 @@ void logging_vty_add_cmds()
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);
@@ -1127,5 +1270,8 @@ void logging_vty_add_cmds()
install_lib_element(CONFIG_NODE, &cfg_log_syslog_local_cmd);
install_lib_element(CONFIG_NODE, &cfg_no_log_syslog_cmd);
#endif
+ 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);
}