Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[logging] Log human readable state names instead of enumeration values
There are still some state changes that are logged in numeric form
and these make log reading more difficult than it needs to be.

Use human readable representations where applicable.

Signed-off-by: Simo Piiroinen <simo.piiroinen@jollamobile.com>
  • Loading branch information
spiiroin committed Mar 1, 2018
1 parent 4e3a251 commit 196c63e
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 9 deletions.
21 changes: 21 additions & 0 deletions datapipe.c
Expand Up @@ -1253,6 +1253,27 @@ const char *tklock_request_repr(tklock_request_t state)
return res;
}

/** Conver tklock status code from system ui to human readable string
*
* @param status TKLOCK_xxx value defined in mode-names.h from mce-dev.
*
* @return human readable representation of status
*/
const char *tklock_status_repr(int status)
{
const char *repr = "TKLOCK_UNKNOWN";

switch( status ) {
case TKLOCK_UNLOCK: repr = "TKLOCK_UNLOCK"; break;
case TKLOCK_RETRY: repr = "TKLOCK_RETRY"; break;
case TKLOCK_TIMEOUT: repr = "TKLOCK_TIMEOUT"; break;
case TKLOCK_CLOSED: repr = "TKLOCK_CLOSED"; break;
default: break;
}

return repr;
}

/** Convert battery_status_t enum to human readable string
*
* @param state battery_status_t enumeration value
Expand Down
5 changes: 4 additions & 1 deletion mce.h
Expand Up @@ -292,6 +292,8 @@ typedef enum {

const char *tklock_request_repr(tklock_request_t state);

const char *tklock_status_repr(int status);

/** Assumed initial battery level */
#define BATTERY_LEVEL_INITIAL 100

Expand Down Expand Up @@ -427,7 +429,8 @@ void mce_signal_handlers_remove(void);

#define display_state_get() ({\
gint res = GPOINTER_TO_INT(display_state_curr_pipe.cached_data);\
mce_log(LL_DEBUG, "display_state_curr=%d", res);\
mce_log(LL_DEBUG, "display_state_curr=%s",\
display_state_repr(res));\
res;\
})

Expand Down
6 changes: 4 additions & 2 deletions modules/display.c
Expand Up @@ -1284,7 +1284,8 @@ static void mdy_datapipe_submode_cb(gconstpointer data)
if( submode == prev )
goto EXIT;

mce_log(LL_DEBUG, "submode = %d", submode);
mce_log(LL_DEBUG, "submode = %s",
submode_change_repr(prev, submode));

/* Rethink dim/blank timers if tklock state changed */
if( (prev ^ submode) & MCE_SUBMODE_TKLOCK )
Expand Down Expand Up @@ -1687,7 +1688,8 @@ static void mdy_datapipe_uiexception_type_cb(gconstpointer data)
if( uiexception_type == prev )
goto EXIT;

mce_log(LL_DEBUG, "uiexception_type = %d", uiexception_type);
mce_log(LL_DEBUG, "uiexception_type = %s",
uiexception_type_repr(uiexception_type));

// normal on->dim->blank might not be applicable
mdy_blanking_rethink_timers(false);
Expand Down
3 changes: 2 additions & 1 deletion modules/inactivity.c
Expand Up @@ -492,7 +492,8 @@ static void mia_datapipe_submode_cb(gconstpointer data)
if( submode == prev )
goto EXIT;

mce_log(LL_DEBUG, "submode = %d", submode);
mce_log(LL_DEBUG, "submode = %s",
submode_change_repr(prev, submode));

EXIT:
return;
Expand Down
4 changes: 3 additions & 1 deletion powerkey.c
Expand Up @@ -2744,7 +2744,9 @@ static void pwrkey_datapipe_system_state_cb(gconstpointer data)
if( prev == system_state )
goto EXIT;

mce_log(LL_DEBUG, "system_state: %d -> %d", prev, system_state);
mce_log(LL_DEBUG, "system_state: %s -> %s",
system_state_repr(prev),
system_state_repr(system_state));

EXIT:
return;
Expand Down
13 changes: 9 additions & 4 deletions tklock.c
Expand Up @@ -610,7 +610,9 @@ static void tklock_datapipe_system_state_cb(gconstpointer data)
if( prev == system_state )
goto EXIT;

mce_log(LL_DEBUG, "system_state: %d -> %d", prev, system_state);
mce_log(LL_DEBUG, "system_state: %s -> %s",
system_state_repr(prev),
system_state_repr(system_state));

tklock_ui_set(false);

Expand Down Expand Up @@ -5543,7 +5545,8 @@ static void tklock_ui_get_devicelock_cb(DBusPendingCall *pc, void *aptr)
goto EXIT;
}

mce_log(LL_INFO, "device lock status reply: state=%d", val);
mce_log(LL_INFO, "device lock status reply: state=%s",
devicelock_state_repr(val));
tklock_datapipe_set_devicelock_state(val);

EXIT:
Expand Down Expand Up @@ -6052,7 +6055,8 @@ static gboolean tklock_dbus_systemui_callback_cb(DBusMessage *const msg)
goto EXIT;
}

mce_log(LL_DEVEL, "tklock callback value: %d, from %s", result,
mce_log(LL_DEVEL, "tklock callback value: %s, from %s",
tklock_status_repr(result),
mce_dbus_get_message_sender_ident(msg));

tklock_request_t state = TKLOCK_REQUEST_OFF;
Expand Down Expand Up @@ -6177,7 +6181,8 @@ static gboolean tklock_dbus_devicelock_changed_cb(DBusMessage *const msg)
goto EXIT;
}

mce_log(LL_DEBUG, "received device lock signal: state=%d", val);
mce_log(LL_DEBUG, "received device lock signal: state=%s",
devicelock_state_repr(val));
tklock_datapipe_set_devicelock_state(val);

EXIT:
Expand Down

0 comments on commit 196c63e

Please sign in to comment.