[PATCH 1/5] log: Refactor evaluation of log level
Torsten Hilbrich
torsten.hilbrich at secunet.com
Tue May 30 05:39:52 UTC 2017
Am 29.05.2017 um 13:27 schrieb Aleksander Morgado:
> Hey Torsten,
>
> On 22/05/17 07:49, Torsten Hilbrich wrote:
[...]
>> diff --git a/src/mm-log.c b/src/mm-log.c
>> index bac0fce..e0255c3 100644
>> --- a/src/mm-log.c
>> +++ b/src/mm-log.c
>> @@ -65,6 +65,22 @@ static const LogDesc level_descs[] = {
>> static GString *msgbuf = NULL;
>> static volatile gsize msgbuf_once = 0;
>>
>> +static int
>> +mm_to_syslog_priority(int level)
>
> A whitespace is missing before the "(".
>
> Also, I'm thinking we could actually setup a typedef enum for the MM logging level, something like
>
> typedef enum {
> MM_LOG_LEVEL_ERR = 0x00000001,
> MM_LOG_LEVEL_WARN = 0x00000002,
> MM_LOG_LEVEL_INFO = 0x00000004,
> MM_LOG_LEVEL_DEBUG = 0x00000008
> } MMLogLevel;
>
> What do you think?
This is a nice idea. I will check what changes are needed elsewhere in
the code and prepare an extra patch for this.
>
> I'm suggesting this because this would let us pass "MMLogLevel level" in this new method, which the compiler will treat in a more strict way when checking for missing items in the switch.
>
>> +{
>> + switch (level) {
>> + case LOGL_DEBUG:
>> + return LOG_DEBUG;
>> + case LOGL_WARN:
>> + return LOG_WARNING;
>> + case LOGL_INFO:
>> + return LOG_INFO;
>> + case LOGL_ERR:
>> + return LOG_ERR;
>> + }
>> + return LOG_INFO;
>
> And if we add the new typedef, this fallback return LOG_INFO would also go away, and we can set here g_assert_not_reached().
Will change that too.
Torsten
More information about the ModemManager-devel
mailing list