Skip to content

Commit

Permalink
Added option to disable colors in logging (issue meetecho#304)
Browse files Browse the repository at this point in the history
  • Loading branch information
lminiero committed Aug 25, 2015
1 parent 1f2c037 commit 64a3eff
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 6 deletions.
2 changes: 2 additions & 0 deletions conf/janus.cfg.sample.in
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ configs_folder = @confdir@ ; Configuration files folder
plugins_folder = @plugindir@ ; Plugins folder
;interface = 1.2.3.4 ; Interface to use (will be used in SDP)
debug_level = 4 ; Debug/logging level, valid values are 0-7
;debug_timestamps = yes ; Whether to show a timestamp for each log line
;debug_colors = no ; Whether colors should be disabled in the log
;apisecret = janusrocks ; String that all Janus requests must contain
; to be accepted/authorized by the Janus core.
; Useful if you're wrapping all Janus API requests
Expand Down
19 changes: 16 additions & 3 deletions debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
#include <glib/gprintf.h>

extern int janus_log_level;
extern int janus_log_timestamps;
extern gboolean janus_log_timestamps;
extern gboolean janus_log_colors;

/** @name Janus log colors
*/
Expand Down Expand Up @@ -53,7 +54,7 @@ extern int janus_log_timestamps;
#define LOG_MAX LOG_DBG

/*! \brief Coloured prefixes for errors and warnings logging. */
static const char *log_prefix[] = {
static const char *janus_log_prefix[] = {
"",
ANSI_COLOR_MAGENTA"[FATAL]"ANSI_COLOR_RESET" ",
ANSI_COLOR_RED"[ERR]"ANSI_COLOR_RESET" ",
Expand All @@ -63,6 +64,18 @@ static const char *log_prefix[] = {
"",
""
};

/*! \brief Prefixes (no colors) for errors and warnings logging. */
static const char *janus_log_nocolors_prefix[] = {
"",
"[FATAL] ",
"[ERR] ",
"[WARN] ",
"",
"",
"",
""
};
///@}

/** @name Janus log wrappers
Expand Down Expand Up @@ -90,7 +103,7 @@ do { \
"[%s:%s:%d] ", __FILE__, __FUNCTION__, __LINE__); \
} \
g_print("%s%s%s" format, \
janus_log_ts, log_prefix[level], janus_log_src, \
janus_log_ts, janus_log_colors ? janus_log_prefix[level] : janus_log_nocolors_prefix[level], janus_log_src, \
##__VA_ARGS__); \
} \
} while (0)
Expand Down
15 changes: 13 additions & 2 deletions janus.c
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,8 @@ gint janus_is_stopping(void) {

/* Logging */
int janus_log_level = 0;
int janus_log_timestamps = 0;
gboolean janus_log_timestamps = FALSE;
gboolean janus_log_colors = FALSE;
int lock_debug = 0;


Expand Down Expand Up @@ -2151,6 +2152,8 @@ int janus_process_incoming_admin_request(janus_request_source *source, json_t *r
json_object_set_new(reply, "transaction", json_string(transaction_text));
json_t *status = json_object();
json_object_set_new(status, "log_level", json_integer(janus_log_level));
json_object_set_new(status, "log_timestamps", json_integer(janus_log_timestamps));
json_object_set_new(status, "log_colors", json_integer(janus_log_colors));
json_object_set_new(status, "locking_debug", json_integer(lock_debug));
json_object_set_new(status, "libnice_debug", json_integer(janus_ice_is_ice_debugging_enabled()));
json_object_set_new(status, "max_nack_queue", json_integer(janus_get_max_nack_queue()));
Expand Down Expand Up @@ -3974,7 +3977,8 @@ gint main(int argc, char *argv[])

/* Logging level: default is info and no timestamps */
janus_log_level = LOG_INFO;
janus_log_timestamps = 0;
janus_log_timestamps = FALSE;
janus_log_colors = TRUE;
if(args_info.debug_level_given) {
if(args_info.debug_level_arg < LOG_NONE)
args_info.debug_level_arg = 0;
Expand Down Expand Up @@ -4048,6 +4052,9 @@ gint main(int argc, char *argv[])
if(args_info.debug_timestamps_given) {
janus_config_add_item(config, "general", "debug_timestamps", "yes");
}
if(args_info.disable_colors_given) {
janus_config_add_item(config, "general", "debug_colors", "no");
}
if(args_info.interface_given) {
janus_config_add_item(config, "general", "interface", args_info.interface_arg);
}
Expand Down Expand Up @@ -4199,6 +4206,10 @@ gint main(int argc, char *argv[])
if(item && item->value)
janus_log_timestamps = janus_is_true(item->value);
JANUS_PRINT("Debug/log timestamps are %s\n", janus_log_timestamps ? "enabled" : "disabled");
item = janus_config_get_item_drilldown(config, "general", "debug_colors");
if(item && item->value)
janus_log_colors = janus_is_true(item->value);
JANUS_PRINT("Debug/log colors are %s\n", janus_log_colors ? "enabled" : "disabled");

/* Any IP/interface to ignore? */
item = janus_config_get_item_drilldown(config, "nat", "ice_ignore_list");
Expand Down
1 change: 1 addition & 0 deletions janus.ggo
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ option "max-nack-queue" q "Maximum size of the NACK queue per user for retransmi
option "rtp-port-range" r "Port range to use for RTP/RTCP" string typestr="min-max" optional
option "debug-level" d "Debug/logging level (0=disable debugging, 7=maximum debug level; default=4)" int typestr="1-7" optional
option "debug-timestamps" D "Enable debug/logging timestamps" flag off
option "disable-colors" o "Disable color in the logging" flag off
option "apisecret" a "API secret all requests need to pass in order to be accepted by Janus (useful when wrapping Janus API requests in a server, none by default)" string typestr="randomstring" optional
option "enable-rabbitmq" R "Enable RabbitMQ support" flag off
option "rabbitmq-server" H "Address (host:port) of the RabbitMQ server to use (default=localhost:5672)" string typestr="string" optional
Expand Down
3 changes: 2 additions & 1 deletion postprocessing/janus-pp-rec.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@
#include "pp-opus.h"

int janus_log_level = 4;
int janus_log_timestamps = 0;
gboolean janus_log_timestamps = FALSE;
gboolean janus_log_colors = TRUE;

static janus_pp_frame_packet *list = NULL, *last = NULL;
int working = 0;
Expand Down

0 comments on commit 64a3eff

Please sign in to comment.