[PATCH 3/5] log: Add mapping from glib loglevel to syslog priority

Aleksander Morgado aleksander at aleksander.es
Mon May 29 11:28:22 UTC 2017


On 22/05/17 07:49, Torsten Hilbrich wrote:
> Improves readability of log_handler function.
> ---
>  src/mm-log.c | 45 +++++++++++++++++++++------------------------
>  1 file changed, 21 insertions(+), 24 deletions(-)
> 
> diff --git a/src/mm-log.c b/src/mm-log.c
> index ec622dc..bedf88f 100644
> --- a/src/mm-log.c
> +++ b/src/mm-log.c
> @@ -82,6 +82,26 @@ mm_to_syslog_priority(int level)
>      return LOG_INFO;
>  }
>  
> +static int
> +glib_to_syslog_priority(int level)
> +{

Whitespace missing before the "(".

Also, can we pass a GLogLevelFlags instead of a plain int here?

> +    switch (level) {
> +    case G_LOG_LEVEL_ERROR:
> +        return LOG_CRIT;
> +    case G_LOG_LEVEL_CRITICAL:
> +        return LOG_ERR;
> +    case G_LOG_LEVEL_WARNING:
> +        return LOG_WARNING;
> +    case G_LOG_LEVEL_MESSAGE:
> +        return LOG_NOTICE;
> +    case G_LOG_LEVEL_DEBUG:
> +        return LOG_DEBUG;
> +    case G_LOG_LEVEL_INFO:

Just add a "default:" here and remove the last fallback "return LOG_INFO;" at the end of the method.

> +        return LOG_INFO;
> +    }
> +    return LOG_INFO;
> +}
> +
>  static const char *
>  log_level_description(int level)
>  {
> @@ -166,33 +186,10 @@ log_handler (const gchar *log_domain,
>               const gchar *message,
>               gpointer ignored)
>  {
> -    int syslog_priority;
>      ssize_t ign;
>  
> -    switch (level) {
> -    case G_LOG_LEVEL_ERROR:
> -        syslog_priority = LOG_CRIT;
> -        break;
> -    case G_LOG_LEVEL_CRITICAL:
> -        syslog_priority = LOG_ERR;
> -        break;
> -    case G_LOG_LEVEL_WARNING:
> -        syslog_priority = LOG_WARNING;
> -        break;
> -    case G_LOG_LEVEL_MESSAGE:
> -        syslog_priority = LOG_NOTICE;
> -        break;
> -    case G_LOG_LEVEL_DEBUG:
> -        syslog_priority = LOG_DEBUG;
> -        break;
> -    case G_LOG_LEVEL_INFO:
> -    default:
> -        syslog_priority = LOG_INFO;
> -        break;
> -    }
> -
>      if (logfd < 0)
> -        syslog (syslog_priority, "%s", message);
> +        syslog (glib_to_syslog_priority (level), "%s", message);
>      else {
>          ign = write (logfd, message, strlen (message));
>          if (ign) {} /* whatever; really shut up about unused result */
> 


-- 
Aleksander
https://aleksander.es


More information about the ModemManager-devel mailing list