1 // SPDX-License-Identifier: LGPL-2.1+
2 // Copyright (C) 2022, Linaro Ltd - Daniel Lezcano <daniel.lezcano@linaro.org>
9 static const char *__ident
= "unknown";
12 static const char * const loglvl
[] = {
13 [LOG_DEBUG
] = "DEBUG",
15 [LOG_NOTICE
] = "NOTICE",
16 [LOG_WARNING
] = "WARN",
18 [LOG_CRIT
] = "CRITICAL",
19 [LOG_ALERT
] = "ALERT",
20 [LOG_EMERG
] = "EMERG",
23 int log_str2level(const char *lvl
)
27 for (i
= 0; i
< sizeof(loglvl
) / sizeof(loglvl
[LOG_DEBUG
]); i
++)
28 if (!strcmp(lvl
, loglvl
[i
]))
34 extern void logit(int level
, const char *format
, ...)
38 va_start(args
, format
);
40 if (__options
& TO_SYSLOG
)
41 vsyslog(level
, format
, args
);
43 if (__options
& TO_STDERR
)
44 vfprintf(stderr
, format
, args
);
46 if (__options
& TO_STDOUT
)
47 vfprintf(stdout
, format
, args
);
52 int log_init(int level
, const char *ident
, int options
)
57 if (level
> LOG_DEBUG
)
66 if (options
& TO_SYSLOG
) {
67 openlog(__ident
, options
| LOG_NDELAY
, LOG_USER
);
68 setlogmask(LOG_UPTO(level
));