Skip to content

Commit

Permalink
[libprofile] Add "libprofile:" prefix to diagnostic logging. Contribu…
Browse files Browse the repository at this point in the history
…tes to JB#24365

Warnings from libprofile are most likely to occur during startup
and shutdown and are thus unlikely to be seen by developers of
the applications that use libprofile. When they are spotted in
journal, they get attributed to the process using libprofile and
it can be hard to spot that the problem is related to libprofile.

Add "libprofile:" prefix for all diagnostic logging that happens
from libprofile.

In some special cases the prefix was already explicitly used, remove
those so that the prefix does not show up twice.
  • Loading branch information
spiiroin committed Mar 14, 2015
1 parent 617719c commit 9795388
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 17 deletions.
2 changes: 1 addition & 1 deletion libprofile.c
Expand Up @@ -127,7 +127,7 @@ client_exec_method_call(DBusMessage *msg)

dbus_error_free(&err);

log_debug("%s: %s -> %s\n", "libprofile",
log_debug("%s -> %s\n",
dbus_message_get_member(msg),
(rsp == 0 ) ? "NO REPLY" :
dbus_message_type_to_string(dbus_message_get_type(rsp)));
Expand Down
13 changes: 11 additions & 2 deletions logging_client.c
Expand Up @@ -37,6 +37,7 @@

#include "logging.h"
#include <stdio.h>
#include <stdlib.h>

#ifdef LOGGING_ENABLED

Expand Down Expand Up @@ -76,11 +77,19 @@ log_emit(int level, const char *fmt, ...)
level = log_level_promote;
}

char *msg = 0;

va_list va;
va_start(va, fmt);
//vsyslog(LOG_USER | level, fmt, va);
vsyslog(level, fmt, va);
if( vasprintf(&msg, fmt, va) < 0 )
{
msg = 0;
}
va_end(va);

syslog(level, "libprofile: %s", msg ?: fmt);

free(msg);
}
}

Expand Down
28 changes: 14 additions & 14 deletions tracker.c
Expand Up @@ -208,15 +208,15 @@ static inline void profile_track_profile(const char *profile)
{
if( profile_track_profile_func != 0 )
{
log_debug("%s: %s - %s\n", "libprofile", __FUNCTION__, profile);
log_debug("%s - %s\n", __FUNCTION__, profile);
profile_track_profile_func(profile, profile_track_profile_data);
}

for( size_t i = 0; i < profile_hooks; ++i )
{
profile_hook_t *h = &profile_hook[i];
profile_track_profile_fn_data cb = h->user_cb;
log_debug("%s: %s - %s @ %p %p %p\n", "libprofile", __FUNCTION__, profile,
log_debug("%s - %s @ %p %p %p\n", __FUNCTION__, profile,
h->user_cb, h->data, h->free_cb);
if( cb ) cb(profile, h->data);
}
Expand All @@ -233,7 +233,7 @@ static inline void profile_track_active(const char *profile,
{
if( profile_track_active_func != 0 )
{
log_debug("%s: %s - %s: %s = %s (%s)\n", "libprofile", __FUNCTION__,
log_debug("%s - %s: %s = %s (%s)\n", __FUNCTION__,
profile, key, val, type);

profile_track_active_func(profile, key, val, type,
Expand All @@ -245,8 +245,8 @@ static inline void profile_track_active(const char *profile,
profile_hook_t *h = &active_hook[i];
profile_track_value_fn_data cb = h->user_cb;

log_debug("%s: %s - %s: %s = %s (%s)@ %p %p %p\n",
"libprofile", __FUNCTION__,
log_debug("%s - %s: %s = %s (%s)@ %p %p %p\n",
__FUNCTION__,
profile, key, val, type,
h->user_cb, h->data, h->free_cb);

Expand All @@ -265,7 +265,7 @@ static inline void profile_track_change(const char *profile,
{
if( profile_track_change_func != 0 )
{
log_debug("%s: %s - %s: %s = %s (%s)\n", "libprofile", __FUNCTION__,
log_debug("%s - %s: %s = %s (%s)\n", __FUNCTION__,
profile, key, val, type);

profile_track_change_func(profile, key, val, type,
Expand All @@ -277,8 +277,8 @@ static inline void profile_track_change(const char *profile,
profile_hook_t *h = &change_hook[i];
profile_track_value_fn_data cb = h->user_cb;

log_debug("%s: %s - %s: %s = %s (%s)@ %p %p %p\n",
"libprofile", __FUNCTION__,
log_debug("%s - %s: %s = %s (%s)@ %p %p %p\n",
__FUNCTION__,
profile, key, val, type,
h->user_cb, h->data, h->free_cb);

Expand Down Expand Up @@ -390,8 +390,8 @@ profile_tracker_disconnect(void)

if( dbus_error_is_set(&err) )
{
log_err("%s: %s: %s: %s\n", "libprofile", "dbus_bus_remove_match",
err.name, err.message);
log_err("%s: %s: %s\n", "dbus_bus_remove_match",
err.name, err.message);
dbus_error_free(&err);
}

Expand Down Expand Up @@ -439,7 +439,7 @@ profile_tracker_connect(void)
/* Register message filter */
if( !dbus_connection_add_filter(profile_tracker_con, profile_tracker_filter, 0, 0) )
{
log_err("%s: %s: %s: %s\n", "libprofile", "dbus_connection_add_filter",
log_err("%s: %s: %s\n", "dbus_connection_add_filter",
err.name, err.message);
goto cleanup;
}
Expand All @@ -449,7 +449,7 @@ profile_tracker_connect(void)

if( dbus_error_is_set(&err) )
{
log_err("%s: %s: %s: %s\n", "libprofile", "dbus_bus_add_match",
log_err("%s: %s: %s\n", "dbus_bus_add_match",
err.name, err.message);
goto cleanup;
}
Expand Down Expand Up @@ -601,7 +601,7 @@ profile_tracker_init(void)
profileval_t *val = 0;
#endif

log_debug("%s: init tracker ...\n", "libprofile");
log_debug("init tracker ...\n");

/* Establish dbus connection */
if( profile_tracker_connect() == -1 )
Expand Down Expand Up @@ -641,7 +641,7 @@ profile_tracker_init(void)
free(cur);
#endif

log_debug("%s: init tracker -> %s\n", "libprofile",
log_debug("init tracker -> %s\n",
(res == 0) ? "OK" : "FAILED");

/* Flag: client wants to use tracker */
Expand Down

0 comments on commit 9795388

Please sign in to comment.