1
0
Fork 0
mirror of https://github.com/albfan/miraclecast.git synced 2025-02-12 22:21:55 +00:00

Parse text log level

closes #42
This commit is contained in:
albfan 2015-08-22 11:07:13 +02:00
parent 73adee82bf
commit 117ed2071b
8 changed files with 36 additions and 34 deletions

View file

@ -27,6 +27,7 @@
#include <sys/types.h>
#include <systemd/sd-bus.h>
#include "shl_dlist.h"
#include "shl_log.h"
#ifndef CTL_CTL_H
#define CTL_CTL_H
@ -123,34 +124,6 @@ extern int cli_max_sev;
void cli_printv(const char *fmt, va_list args);
void cli_printf(const char *fmt, ...);
enum {
#ifndef LOG_FATAL
LOG_FATAL = 0,
#endif
#ifndef LOG_ALERT
LOG_ALERT = 1,
#endif
#ifndef LOG_CRITICAL
LOG_CRITICAL = 2,
#endif
#ifndef LOG_ERROR
LOG_ERROR = 3,
#endif
#ifndef LOG_WARNING
LOG_WARNING = 4,
#endif
#ifndef LOG_NOTICE
LOG_NOTICE = 5,
#endif
#ifndef LOG_INFO
LOG_INFO = 6,
#endif
#ifndef LOG_DEBUG
LOG_DEBUG = 7,
#endif
LOG_SEV_NUM,
};
#define cli_log(_fmt, ...) \
cli_printf(_fmt "\n", ##__VA_ARGS__)
#define cli_log_fn(_fmt, ...) \

View file

@ -703,7 +703,7 @@ static int parse_argv(int argc, char *argv[])
puts(PACKAGE_STRING);
return 0;
case ARG_LOG_LEVEL:
cli_max_sev = atoi(optarg);
cli_max_sev = log_parse_arg(optarg);
break;
case ARG_AUDIO:
gst_audio_en = atoi(optarg);

View file

@ -514,7 +514,7 @@ static int parse_argv(int argc, char *argv[])
puts(PACKAGE_STRING);
return 0;
case ARG_LOG_LEVEL:
cli_max_sev = atoi(optarg);
cli_max_sev = log_parse_arg(optarg);
break;
case '?':
return -EINVAL;

View file

@ -818,7 +818,7 @@ static int parse_argv(int argc, char *argv[])
puts(PACKAGE_STRING);
return 0;
case ARG_LOG_LEVEL:
log_max_sev = atoi(optarg);
log_max_sev = log_parse_arg(optarg);
break;
case ARG_LOG_TIME:
log_init_time();

View file

@ -99,7 +99,7 @@ static int parse_argv(int argc, char *argv[])
puts(PACKAGE_STRING);
return 0;
case ARG_LOG_LEVEL:
log_max_sev = atoi(optarg);
log_max_sev = log_parse_arg(optarg);
break;
case ARG_LOG_TIME:
log_init_time();

View file

@ -238,3 +238,30 @@ void log_llog(void *data,
{
log_submit(file, line, func, subs, sev, format, args);
}
int log_parse_arg(char *optarg)
{
int log_max_sev;
if(!strcasecmp(optarg, "fatal")) {
log_max_sev = LOG_FATAL;
} else if(!strcasecmp(optarg, "alert")) {
log_max_sev = LOG_ALERT;
} else if(!strcasecmp(optarg, "critical")) {
log_max_sev = LOG_CRITICAL;
} else if(!strcasecmp(optarg, "error")) {
log_max_sev = LOG_ERROR;
} else if(!strcasecmp(optarg, "warning")) {
log_max_sev = LOG_WARNING;
} else if(!strcasecmp(optarg, "notice")) {
log_max_sev = LOG_NOTICE;
} else if(!strcasecmp(optarg, "info")) {
log_max_sev = LOG_INFO;
} else if(!strcasecmp(optarg, "debug")) {
log_max_sev = LOG_DEBUG;
} else if(!strcasecmp(optarg, "trace")) {
log_max_sev = LOG_TRACE;
} else {
log_max_sev = atoi(optarg);
}
return log_max_sev;
}

View file

@ -116,6 +116,8 @@ void log_llog(void *data,
const char *format,
va_list args);
int log_parse_arg(char *optarg);
static inline __attribute__((format(printf, 2, 3)))
void log_dummyf(unsigned int sev, const char *format, ...)
{

View file

@ -502,7 +502,7 @@ static int parse_argv(int argc, char *argv[])
puts(PACKAGE_STRING);
return 0;
case ARG_LOG_LEVEL:
log_max_sev = atoi(optarg);
log_max_sev = log_parse_arg(optarg);
break;
case ARG_LOG_TIME:
log_init_time();
@ -512,7 +512,7 @@ static int parse_argv(int argc, char *argv[])
arg_wpa_bindir = optarg;
break;
case ARG_WPA_LOGLEVEL:
arg_wpa_loglevel = atoi(optarg);
arg_wpa_loglevel = log_parse_arg(optarg);
break;
case '?':
return -EINVAL;