From 4eaec4e6d2e012ff6880d0c76a57b44bce62fe98 Mon Sep 17 00:00:00 2001 From: Vivek Kumar Dutta Date: Tue, 19 Nov 2024 05:17:07 +0000 Subject: [PATCH] Update log_level from uci --- utilities/src/ubus/bbf_config.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/utilities/src/ubus/bbf_config.c b/utilities/src/ubus/bbf_config.c index 8321880c..d2f7dfe0 100644 --- a/utilities/src/ubus/bbf_config.c +++ b/utilities/src/ubus/bbf_config.c @@ -22,6 +22,7 @@ #define MAX_SERVICE_NUM 16 #define MAX_INSTANCE_NUM 8 #define NAME_LENGTH 64 +#define DEFAULT_LOG_LEVEL LOG_INFO #define BBF_CONFIG_DAEMON_NAME "bbf_configd" #define CONFIG_CONFDIR "/etc/config/" @@ -855,7 +856,7 @@ static void usage(char *prog) fprintf(stderr, "Usage: %s [options]\n", prog); fprintf(stderr, "\n"); fprintf(stderr, "options:\n"); - fprintf(stderr, " -d Use multiple time to get more verbose debug logs (Debug: -dddd)\n"); + fprintf(stderr, " -l <0-4> Set the loglevel\n"); fprintf(stderr, " -h Displays this help\n"); fprintf(stderr, "\n"); } @@ -873,12 +874,17 @@ int main(int argc, char **argv) .cb = receive_notify_event, }; struct ubus_context *uctx; - int ch, log_level = 0; + int ch, log_level = DEFAULT_LOG_LEVEL; - while ((ch = getopt(argc, argv, "hd")) != -1) { + while ((ch = getopt(argc, argv, "hl:")) != -1) { switch (ch) { - case 'd': - log_level += 1; + case 'l': + if (optarg) { + log_level = (int)strtod(optarg, NULL); + if (log_level < 0 || log_level > 7) { + log_level = DEFAULT_LOG_LEVEL; + } + } break; case 'h': usage(argv[0]);