[PATCH] add log category

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi all,

This is more like a RFC patch, it can't even compile well... However, I'd
like to gather some information here on the mailing list to make sure that
I'm on the right track and my work would be liked by others.

This 'category' model is mainly after the design of gstreamer. So we have a
'pa_log_category_t' type to show what kind of category it's, and in its
category, we can specify a threshold and the color to display.  (look at
the changes in these two files src/pulsecore/log.h and src/pulsecore/log.c
for more details.)

Now the main problem to me is that the usage is not so developer-friendly.
Any place where we use pa_log related functions, I have to specify the
macro PA_LOG_CATEGORY_DEFAULT. That's almost everywhere... But yes, it
should only be written for only and after that other developers should be
OK with that.

Any comments are welcome!
2012/5/24 Deng Zhengrong <dzrongg at gmail.com>

> ---
>  src/modules/module-loopback.c  |    5 ++
>  src/pulse/channelmap.c         |    2 +
>  src/pulse/client-conf.c        |    2 +
>  src/pulse/context.c            |    2 +
>  src/pulse/ext-device-manager.c |    2 +
>  src/pulse/ext-device-restore.c |    2 +
>  src/pulse/ext-stream-restore.c |    2 +
>  src/pulse/format.c             |    2 +
>  src/pulse/introspect.c         |    2 +
>  src/pulse/mainloop-api.c       |    2 +
>  src/pulse/mainloop-signal.c    |    2 +
>  src/pulse/mainloop.c           |    2 +
>  src/pulse/operation.c          |    2 +
>  src/pulse/proplist.c           |    2 +
>  src/pulse/sample.c             |    2 +
>  src/pulse/scache.c             |    2 +
>  src/pulse/stream.c             |    2 +
>  src/pulse/subscribe.c          |    2 +
>  src/pulse/thread-mainloop.c    |    2 +
>  src/pulse/timeval.c            |    2 +
>  src/pulse/utf8.c               |    2 +
>  src/pulse/util.c               |    2 +
>  src/pulse/volume.c             |    2 +
>  src/pulse/xmalloc.c            |    2 +
>  src/pulsecore/authkey.c        |    2 +
>  src/pulsecore/conf-parser.c    |    2 +
>  src/pulsecore/core-error.c     |    2 +
>  src/pulsecore/core-rtclock.c   |    2 +
>  src/pulsecore/core-util.c      |    2 +
>  src/pulsecore/dynarray.c       |    2 +
>  src/pulsecore/flist.c          |    2 +
>  src/pulsecore/iochannel.c      |    2 +
>  src/pulsecore/ioline.c         |    2 +
>  src/pulsecore/ipacl.c          |    2 +
>  src/pulsecore/lock-autospawn.c |    2 +
>  src/pulsecore/log.c            |  104
> ++++++++++++++++++++++++++++++++++++++--
>  src/pulsecore/log.h            |   39 +++++++++++----
>  src/pulsecore/macro.h          |    2 +-
>  src/pulsecore/ratelimit.c      |    2 +
>  39 files changed, 205 insertions(+), 15 deletions(-)
>
> diff --git a/src/modules/module-loopback.c b/src/modules/module-loopback.c
> index 1a69445..3b9bb90 100644
> --- a/src/modules/module-loopback.c
> +++ b/src/modules/module-loopback.c
> @@ -59,6 +59,9 @@ PA_MODULE_USAGE(
>         "sink_dont_move=<boolean> "
>         "remix=<remix channels?> ");
>
> +PA_LOG_CATEGORY_STATIC(module_loopback_category);
> +#define PA_LOG_CATEGORY_DEFAULT module_loopback_category
> +
>  #define DEFAULT_LATENCY_MSEC 200
>
>  #define MEMBLOCKQ_MAXLENGTH (1024*1024*16)
> @@ -663,6 +666,8 @@ int pa__init(pa_module *m) {
>
>     pa_assert(m);
>
> +    PA_LOG_CATEGORY_INIT(module_loopback_category, "loopback", 0);
> +
>     if (!(ma = pa_modargs_new(m->argument, valid_modargs))) {
>         pa_log("Failed to parse module arguments");
>         goto fail;
> diff --git a/src/pulse/channelmap.c b/src/pulse/channelmap.c
> index 0d199f3..f375cbf 100644
> --- a/src/pulse/channelmap.c
> +++ b/src/pulse/channelmap.c
> @@ -38,6 +38,8 @@
>
>  #include "channelmap.h"
>
> +#define PA_LOG_CATEGORY_DEFAULT PA_LOG_CAT_CHANNELMAP
> +
>  const char *const table[PA_CHANNEL_POSITION_MAX] = {
>     [PA_CHANNEL_POSITION_MONO] = "mono",
>
> diff --git a/src/pulse/client-conf.c b/src/pulse/client-conf.c
> index e2c2aae..1801062 100644
> --- a/src/pulse/client-conf.c
> +++ b/src/pulse/client-conf.c
> @@ -40,6 +40,8 @@
>
>  #include "client-conf.h"
>
> +#define PA_LOG_CATEGORY_DEFAULT PA_LOG_CAT_CORE
> +
>  #define DEFAULT_CLIENT_CONFIG_FILE PA_DEFAULT_CONFIG_DIR PA_PATH_SEP
> "client.conf"
>  #define DEFAULT_CLIENT_CONFIG_FILE_USER "client.conf"
>
> diff --git a/src/pulse/context.c b/src/pulse/context.c
> index 5bd3448..14520e5 100644
> --- a/src/pulse/context.c
> +++ b/src/pulse/context.c
> @@ -71,6 +71,8 @@
>  #include "internal.h"
>  #include "context.h"
>
> +#define PA_LOG_CATEGORY_DEFAULT PA_LOG_CAT_CONTEXT
> +
>  void pa_command_extension(pa_pdispatch *pd, uint32_t command, uint32_t
> tag, pa_tagstruct *t, void *userdata);
>
>  static const pa_pdispatch_cb_t command_table[PA_COMMAND_MAX] = {
> diff --git a/src/pulse/ext-device-manager.c
> b/src/pulse/ext-device-manager.c
> index f2ea63a..2dca36c 100644
> --- a/src/pulse/ext-device-manager.c
> +++ b/src/pulse/ext-device-manager.c
> @@ -35,6 +35,8 @@
>  #include "internal.h"
>  #include "ext-device-manager.h"
>
> +#define PA_LOG_CATEGORY_DEFAULT PA_LOG_CAT_CORE
> +
>  enum {
>     SUBCOMMAND_TEST,
>     SUBCOMMAND_READ,
> diff --git a/src/pulse/ext-device-restore.c
> b/src/pulse/ext-device-restore.c
> index 25d33d1..2174d82 100644
> --- a/src/pulse/ext-device-restore.c
> +++ b/src/pulse/ext-device-restore.c
> @@ -37,6 +37,8 @@
>  #include "internal.h"
>  #include "ext-device-restore.h"
>
> +#define PA_LOG_CATEGORY_DEFAULT PA_LOG_CAT_CORE
> +
>  /* Protocol extension commands */
>  enum {
>     SUBCOMMAND_TEST,
> diff --git a/src/pulse/ext-stream-restore.c
> b/src/pulse/ext-stream-restore.c
> index 1f72c1c..569bcb0 100644
> --- a/src/pulse/ext-stream-restore.c
> +++ b/src/pulse/ext-stream-restore.c
> @@ -33,6 +33,8 @@
>  #include "internal.h"
>  #include "ext-stream-restore.h"
>
> +#define PA_LOG_CATEGORY_DEFAULT PA_LOG_CAT_CORE
> +
>  enum {
>     SUBCOMMAND_TEST,
>     SUBCOMMAND_READ,
> diff --git a/src/pulse/format.c b/src/pulse/format.c
> index 542d119..972a6d0 100644
> --- a/src/pulse/format.c
> +++ b/src/pulse/format.c
> @@ -36,6 +36,8 @@
>
>  #include "format.h"
>
> +#define PA_LOG_CATEGORY_DEFAULT PA_LOG_CAT_CORE
> +
>  #define PA_JSON_MIN_KEY "min"
>  #define PA_JSON_MAX_KEY "max"
>
> diff --git a/src/pulse/introspect.c b/src/pulse/introspect.c
> index 38a9d1c..1ec638f 100644
> --- a/src/pulse/introspect.c
> +++ b/src/pulse/introspect.c
> @@ -35,6 +35,8 @@
>  #include "internal.h"
>  #include "introspect.h"
>
> +#define PA_LOG_CATEGORY_DEFAULT PA_LOG_CAT_CORE
> +
>  /*** Statistics ***/
>
>  static void context_stat_callback(pa_pdispatch *pd, uint32_t command,
> uint32_t tag, pa_tagstruct *t, void *userdata) {
> diff --git a/src/pulse/mainloop-api.c b/src/pulse/mainloop-api.c
> index 45539cc..be76c27 100644
> --- a/src/pulse/mainloop-api.c
> +++ b/src/pulse/mainloop-api.c
> @@ -32,6 +32,8 @@
>
>  #include "mainloop-api.h"
>
> +#define PA_LOG_CATEGORY_DEFAULT PA_LOG_CAT_CORE
> +
>  struct once_info {
>     void (*callback)(pa_mainloop_api*m, void *userdata);
>     void *userdata;
> diff --git a/src/pulse/mainloop-signal.c b/src/pulse/mainloop-signal.c
> index 9482fe3..b0a9453 100644
> --- a/src/pulse/mainloop-signal.c
> +++ b/src/pulse/mainloop-signal.c
> @@ -45,6 +45,8 @@
>
>  #include "mainloop-signal.h"
>
> +#define PA_LOG_CATEGORY_DEFAULT PA_LOG_CAT_CORE
> +
>  struct pa_signal_event {
>     int sig;
>  #ifdef HAVE_SIGACTION
> diff --git a/src/pulse/mainloop.c b/src/pulse/mainloop.c
> index 5c0345e..7031f8f 100644
> --- a/src/pulse/mainloop.c
> +++ b/src/pulse/mainloop.c
> @@ -51,6 +51,8 @@
>  #include "mainloop.h"
>  #include "internal.h"
>
> +#define PA_LOG_CATEGORY_DEFAULT PA_LOG_CAT_CORE
> +
>  struct pa_io_event {
>     pa_mainloop *mainloop;
>     pa_bool_t dead:1;
> diff --git a/src/pulse/operation.c b/src/pulse/operation.c
> index fe160a3..f14466d 100644
> --- a/src/pulse/operation.c
> +++ b/src/pulse/operation.c
> @@ -30,6 +30,8 @@
>  #include "internal.h"
>  #include "operation.h"
>
> +#define PA_LOG_CATEGORY_DEFAULT PA_LOG_CAT_CORE
> +
>  PA_STATIC_FLIST_DECLARE(operations, 0, pa_xfree);
>
>  pa_operation *pa_operation_new(pa_context *c, pa_stream *s,
> pa_operation_cb_t cb, void *userdata) {
> diff --git a/src/pulse/proplist.c b/src/pulse/proplist.c
> index 649138c..1296bc8 100644
> --- a/src/pulse/proplist.c
> +++ b/src/pulse/proplist.c
> @@ -35,6 +35,8 @@
>
>  #include "proplist.h"
>
> +#define PA_LOG_CATEGORY_DEFAULT PA_LOG_CAT_CORE
> +
>  struct property {
>     char *key;
>     void *value;
> diff --git a/src/pulse/sample.c b/src/pulse/sample.c
> index b613612..5731736 100644
> --- a/src/pulse/sample.c
> +++ b/src/pulse/sample.c
> @@ -35,6 +35,8 @@
>
>  #include "sample.h"
>
> +#define PA_LOG_CATEGORY_DEFAULT PA_LOG_CAT_CORE
> +
>  static const size_t size_table[] = {
>     [PA_SAMPLE_U8] = 1,
>     [PA_SAMPLE_ULAW] = 1,
> diff --git a/src/pulse/scache.c b/src/pulse/scache.c
> index 3fad82a..60bc803 100644
> --- a/src/pulse/scache.c
> +++ b/src/pulse/scache.c
> @@ -36,6 +36,8 @@
>  #include "internal.h"
>  #include "scache.h"
>
> +#define PA_LOG_CATEGORY_DEFAULT PA_LOG_CAT_CORE
> +
>  int pa_stream_connect_upload(pa_stream *s, size_t length) {
>     pa_tagstruct *t;
>     uint32_t tag;
> diff --git a/src/pulse/stream.c b/src/pulse/stream.c
> index 39338c1..52c9ae4 100644
> --- a/src/pulse/stream.c
> +++ b/src/pulse/stream.c
> @@ -44,6 +44,8 @@
>  #include "internal.h"
>  #include "stream.h"
>
> +#define PA_LOG_CATEGORY_DEFAULT PA_LOG_CAT_CORE
> +
>  #define AUTO_TIMING_INTERVAL_START_USEC (10*PA_USEC_PER_MSEC)
>  #define AUTO_TIMING_INTERVAL_END_USEC (1500*PA_USEC_PER_MSEC)
>
> diff --git a/src/pulse/subscribe.c b/src/pulse/subscribe.c
> index a6ad238..4cf002a 100644
> --- a/src/pulse/subscribe.c
> +++ b/src/pulse/subscribe.c
> @@ -31,6 +31,8 @@
>  #include "internal.h"
>  #include "subscribe.h"
>
> +#define PA_LOG_CATEGORY_DEFAULT PA_LOG_CAT_CORE
> +
>  void pa_command_subscribe_event(pa_pdispatch *pd, uint32_t command,
> uint32_t tag, pa_tagstruct *t, void *userdata) {
>     pa_context *c = userdata;
>     pa_subscription_event_type_t e;
> diff --git a/src/pulse/thread-mainloop.c b/src/pulse/thread-mainloop.c
> index aa56a92..8e822b8 100644
> --- a/src/pulse/thread-mainloop.c
> +++ b/src/pulse/thread-mainloop.c
> @@ -43,6 +43,8 @@
>
>  #include "thread-mainloop.h"
>
> +#define PA_LOG_CATEGORY_DEFAULT PA_LOG_CAT_CORE
> +
>  struct pa_threaded_mainloop {
>     pa_mainloop *real_mainloop;
>     volatile int n_waiting, n_waiting_for_accept;
> diff --git a/src/pulse/timeval.c b/src/pulse/timeval.c
> index a394dbe..a993b2b 100644
> --- a/src/pulse/timeval.c
> +++ b/src/pulse/timeval.c
> @@ -36,6 +36,8 @@
>
>  #include "timeval.h"
>
> +#define PA_LOG_CATEGORY_DEFAULT PA_LOG_CAT_CORE
> +
>  struct timeval *pa_gettimeofday(struct timeval *tv) {
>     pa_assert(tv);
>
> diff --git a/src/pulse/utf8.c b/src/pulse/utf8.c
> index 773a1f8..0962515 100644
> --- a/src/pulse/utf8.c
> +++ b/src/pulse/utf8.c
> @@ -62,6 +62,8 @@
>
>  #include "utf8.h"
>
> +#define PA_LOG_CATEGORY_DEFAULT PA_LOG_CAT_CORE
> +
>  #define FILTER_CHAR '_'
>
>  static inline pa_bool_t is_unicode_valid(uint32_t ch) {
> diff --git a/src/pulse/util.c b/src/pulse/util.c
> index 6656bc3..75bef42 100644
> --- a/src/pulse/util.c
> +++ b/src/pulse/util.c
> @@ -64,6 +64,8 @@
>
>  #include "util.h"
>
> +#define PA_LOG_CATEGORY_DEFAULT PA_LOG_CAT_CORE
> +
>  char *pa_get_user_name(char *s, size_t l) {
>     const char *p;
>     char *name = NULL;
> diff --git a/src/pulse/volume.c b/src/pulse/volume.c
> index cf0a226..3478893 100644
> --- a/src/pulse/volume.c
> +++ b/src/pulse/volume.c
> @@ -34,6 +34,8 @@
>
>  #include "volume.h"
>
> +#define PA_LOG_CATEGORY_DEFAULT PA_LOG_CAT_CORE
> +
>  int pa_cvolume_equal(const pa_cvolume *a, const pa_cvolume *b) {
>     int i;
>     pa_assert(a);
> diff --git a/src/pulse/xmalloc.c b/src/pulse/xmalloc.c
> index e17a354..840c9df 100644
> --- a/src/pulse/xmalloc.c
> +++ b/src/pulse/xmalloc.c
> @@ -35,6 +35,8 @@
>
>  #include "xmalloc.h"
>
> +#define PA_LOG_CATEGORY_DEFAULT PA_LOG_CAT_CORE
> +
>  /* Make sure not to allocate more than this much memory. */
>  #define MAX_ALLOC_SIZE (1024*1024*96) /* 96MB */
>
> diff --git a/src/pulsecore/authkey.c b/src/pulsecore/authkey.c
> index ac81513..6ad4574 100644
> --- a/src/pulsecore/authkey.c
> +++ b/src/pulsecore/authkey.c
> @@ -42,6 +42,8 @@
>
>  #include "authkey.h"
>
> +#define PA_LOG_CATEGORY_DEFAULT PA_LOG_CAT_CORE
> +
>  /* Generate a new authorization key, store it in file fd and return it in
> *data  */
>  static int generate(int fd, void *ret_data, size_t length) {
>     ssize_t r;
> diff --git a/src/pulsecore/conf-parser.c b/src/pulsecore/conf-parser.c
> index 7152955..8098e70 100644
> --- a/src/pulsecore/conf-parser.c
> +++ b/src/pulsecore/conf-parser.c
> @@ -36,6 +36,8 @@
>
>  #include "conf-parser.h"
>
> +#define PA_LOG_CATEGORY_DEFAULT PA_LOG_CAT_CORE
> +
>  #define WHITESPACE " \t\n"
>  #define COMMENTS "#;\n"
>
> diff --git a/src/pulsecore/core-error.c b/src/pulsecore/core-error.c
> index 4d930a0..f731be5 100644
> --- a/src/pulsecore/core-error.c
> +++ b/src/pulsecore/core-error.c
> @@ -38,6 +38,8 @@
>
>  #include "core-error.h"
>
> +#define PA_LOG_CATEGORY_DEFAULT PA_LOG_CAT_CORE
> +
>  PA_STATIC_TLS_DECLARE(cstrerror, pa_xfree);
>
>  const char* pa_cstrerror(int errnum) {
> diff --git a/src/pulsecore/core-rtclock.c b/src/pulsecore/core-rtclock.c
> index 6632cc6..537cfb1 100644
> --- a/src/pulsecore/core-rtclock.c
> +++ b/src/pulsecore/core-rtclock.c
> @@ -54,6 +54,8 @@
>
>  #include "core-rtclock.h"
>
> +#define PA_LOG_CATEGORY_DEFAULT PA_LOG_CAT_CORE
> +
>  #ifdef OS_IS_WIN32
>  static int64_t counter_freq = 0;
>  #endif
> diff --git a/src/pulsecore/core-util.c b/src/pulsecore/core-util.c
> index 61f980e..1044dad 100644
> --- a/src/pulsecore/core-util.c
> +++ b/src/pulsecore/core-util.c
> @@ -138,6 +138,8 @@
>
>  #include "core-util.h"
>
> +#define PA_LOG_CATEGORY_DEFAULT PA_LOG_CAT_CORE
> +
>  /* Not all platforms have this */
>  #ifndef MSG_NOSIGNAL
>  #define MSG_NOSIGNAL 0
> diff --git a/src/pulsecore/dynarray.c b/src/pulsecore/dynarray.c
> index 78b2eb9..62c58c1 100644
> --- a/src/pulsecore/dynarray.c
> +++ b/src/pulsecore/dynarray.c
> @@ -31,6 +31,8 @@
>
>  #include "dynarray.h"
>
> +#define PA_LOG_CATEGORY_DEFAULT PA_LOG_CAT_CORE
> +
>  /* If the array becomes to small, increase its size by 25 entries */
>  #define INCREASE_BY 25
>
> diff --git a/src/pulsecore/flist.c b/src/pulsecore/flist.c
> index 0aa95c7..03475e2 100644
> --- a/src/pulsecore/flist.c
> +++ b/src/pulsecore/flist.c
> @@ -37,6 +37,8 @@
>
>  #include "flist.h"
>
> +#define PA_LOG_CATEGORY_DEFAULT PA_LOG_CAT_CORE
> +
>  #define FLIST_SIZE 128
>
>  /* Atomic table indices contain
> diff --git a/src/pulsecore/iochannel.c b/src/pulsecore/iochannel.c
> index fa3d767..f020535 100644
> --- a/src/pulsecore/iochannel.c
> +++ b/src/pulsecore/iochannel.c
> @@ -43,6 +43,8 @@
>
>  #include "iochannel.h"
>
> +#define PA_LOG_CATEGORY_DEFAULT PA_LOG_CAT_CORE
> +
>  struct pa_iochannel {
>     int ifd, ofd;
>     int ifd_type, ofd_type;
> diff --git a/src/pulsecore/ioline.c b/src/pulsecore/ioline.c
> index a18188d..5781d91 100644
> --- a/src/pulsecore/ioline.c
> +++ b/src/pulsecore/ioline.c
> @@ -39,6 +39,8 @@
>
>  #include "ioline.h"
>
> +#define PA_LOG_CATEGORY_DEFAULT PA_LOG_CAT_CORE
> +
>  #define BUFFER_LIMIT (64*1024)
>  #define READ_SIZE (1024)
>
> diff --git a/src/pulsecore/ipacl.c b/src/pulsecore/ipacl.c
> index 5455d0e..39beaa2 100644
> --- a/src/pulsecore/ipacl.c
> +++ b/src/pulsecore/ipacl.c
> @@ -49,6 +49,8 @@
>
>  #include "ipacl.h"
>
> +#define PA_LOG_CATEGORY_DEFAULT PA_LOG_CAT_CORE
> +
>  struct acl_entry {
>     PA_LLIST_FIELDS(struct acl_entry);
>     int family;
> diff --git a/src/pulsecore/lock-autospawn.c
> b/src/pulsecore/lock-autospawn.c
> index b1d414b..a936a86 100644
> --- a/src/pulsecore/lock-autospawn.c
> +++ b/src/pulsecore/lock-autospawn.c
> @@ -42,6 +42,8 @@
>
>  #include "lock-autospawn.h"
>
> +#define PA_LOG_CATEGORY_DEFAULT PA_LOG_CAT_CORE
> +
>  /* So, why do we have this complex code here with threads and pipes
>  * and stuff? For two reasons: POSIX file locks are per-process, not
>  * per-file descriptor. That means that two contexts within the same
> diff --git a/src/pulsecore/log.c b/src/pulsecore/log.c
> index 8eaef54..628aa59 100644
> --- a/src/pulsecore/log.c
> +++ b/src/pulsecore/log.c
> @@ -50,6 +50,8 @@
>  #include <pulsecore/once.h>
>  #include <pulsecore/ratelimit.h>
>  #include <pulsecore/thread.h>
> +#include <pulsecore/llist.h>
> +#include <pulsecore/mutex.h>
>
>  #include "log.h"
>
> @@ -63,6 +65,20 @@
>  #define ENV_LOG_BACKTRACE "PULSE_LOG_BACKTRACE"
>  #define ENV_LOG_BACKTRACE_SKIP "PULSE_LOG_BACKTRACE_SKIP"
>  #define ENV_LOG_NO_RATELIMIT "PULSE_LOG_NO_RATE_LIMIT"
> +#define ENV_LOG_DEBUG "PULSE_LOG_DEBUG"
> +
> +#define PA_LOG_CATEGORY_DEFAULT PA_LOG_CAT_CORE
> +
> +struct pa_log_category {
> +    PA_LLIST_FIELDS(pa_log_category_t);
> +    int threshold;
> +    int color;
> +    const char *name;
> +    const char *description;
> +};
> +
> +static pa_static_mutex categories_mutex = PA_STATIC_MUTEX_INIT;
> +static pa_log_category_t *categories = NULL;
>
>  static char *ident = NULL; /* in local charset format */
>  static pa_log_target_t target = PA_LOG_STDERR, target_override;
> @@ -207,11 +223,21 @@ static char* get_backtrace(unsigned show_nframes) {
>
>  #endif
>
> +pa_log_category_t *PA_LOG_CAT_CORE = NULL;
> +pa_log_category_t *PA_LOG_CAT_CHANNELMAP = NULL;
> +pa_log_category_t *PA_LOG_CAT_CONTEXT = NULL;
> +static void init_log_categories(void) {
> +    PA_LOG_CAT_CORE = pa_log_category_new("core", 0, "pulsecore");
> +    PA_LOG_CAT_CONTEXT = pa_log_category_new("channelmap", 0,
> "channelmap");
> +}
> +
>  static void init_defaults(void) {
>     PA_ONCE_BEGIN {
>
>         const char *e;
>
> +        init_log_categories();
> +
>         if (!ident) {
>             char binary[256];
>             if (pa_get_binary_name(binary, sizeof(binary)))
> @@ -262,10 +288,37 @@ static void init_defaults(void) {
>         if (getenv(ENV_LOG_NO_RATELIMIT))
>             no_rate_limit = TRUE;
>
> +        if ((e = getenv(ENV_LOG_DEBUG)))
> +            parse_log_debug(e);
> +
>     } PA_ONCE_END;
>  }
>
> +void parse_log_debug(const char *debug)
> +{
> +    const char *state = NULL;
> +    const char *p;
> +
> +    /*
> +    while ((p = pa_split(debug, ",", &state))) {
> +        if (strchr(p, ':')) {
> +        } else {
> +        }
> +    }
> +    */
> +    pa_mutex *mutex = NULL;
> +    pa_log_category_t *iter;
> +
> +    mutex = pa_static_mutex_get(&categories_mutex, TRUE, TRUE);
> +    pa_mutex_lock(mutex);
> +    PA_LLIST_FOREACH(iter, categories) {
> +        iter->threshold = 0;
> +    }
> +    pa_mutex_unlock(mutex);
> +}
> +
>  void pa_log_levelv_meta(
> +        pa_log_category_t *category,
>         pa_log_level_t level,
>         const char*file,
>         int line,
> @@ -290,6 +343,11 @@ void pa_log_levelv_meta(
>
>     init_defaults();
>
> +    if (category == NULL)
> +        return;
> +    if (level < category->threshold)
> +        return;
> +
>     _target = target_override_set ? target_override : target;
>     _maximum_level = PA_MAX(maximum_level, maximum_level_override);
>     _show_backtrace = PA_MAX(show_backtrace, show_backtrace_override);
> @@ -438,6 +496,7 @@ void pa_log_levelv_meta(
>  }
>
>  void pa_log_level_meta(
> +        pa_log_category_t *category,
>         pa_log_level_t level,
>         const char*file,
>         int line,
> @@ -446,19 +505,19 @@ void pa_log_level_meta(
>
>     va_list ap;
>     va_start(ap, format);
> -    pa_log_levelv_meta(level, file, line, func, format, ap);
> +    pa_log_levelv_meta(category, level, file, line, func, format, ap);
>     va_end(ap);
>  }
>
> -void pa_log_levelv(pa_log_level_t level, const char *format, va_list ap) {
> -    pa_log_levelv_meta(level, NULL, 0, NULL, format, ap);
> +void pa_log_levelv(pa_log_category_t *category, pa_log_level_t level,
> const char *format, va_list ap) {
> +    pa_log_levelv_meta(category, level, NULL, 0, NULL, format, ap);
>  }
>
> -void pa_log_level(pa_log_level_t level, const char *format, ...) {
> +void pa_log_level(pa_log_category_t *category, pa_log_level_t level,
> const char *format, ...) {
>     va_list ap;
>
>     va_start(ap, format);
> -    pa_log_levelv_meta(level, NULL, 0, NULL, format, ap);
> +    pa_log_levelv_meta(category, level, NULL, 0, NULL, format, ap);
>     va_end(ap);
>  }
>
> @@ -473,3 +532,38 @@ pa_bool_t pa_log_ratelimit(pa_log_level_t level) {
>
>     return pa_ratelimit_test(&ratelimit, level);
>  }
> +
> +pa_log_category_t *pa_log_category_new(const char *name, int color, const
> char *description)
> +{
> +    pa_mutex *mutex = NULL;
> +    pa_log_category_t *cat = pa_xnew0(pa_log_category_t, 1);
> +
> +    cat->threshold = 0;
> +    cat->color = color;
> +    cat->name = pa_xstrdup(name);
> +    cat->description = pa_xstrdup(description);
> +
> +    mutex = pa_static_mutex_get(&categories_mutex, TRUE, TRUE);
> +    pa_mutex_lock(mutex);
> +    PA_LLIST_PREPEND(pa_log_category_t, categories, cat);
> +    pa_mutex_unlock(mutex);
> +
> +    return cat;
> +}
> +
> +static pa_log_category_t *pa_log_category_get(const char *name)
> +{
> +    pa_mutex *mutex = NULL;
> +    pa_log_category_t *iter;
> +
> +    mutex = pa_static_mutex_get(&categories_mutex, TRUE, TRUE);
> +    pa_mutex_lock(mutex);
> +    PA_LLIST_FOREACH(iter, categories) {
> +        if (pa_streq(iter->name, name)) {
> +                pa_mutex_unlock(mutex);
> +                return iter;
> +        }
> +    }
> +    pa_mutex_unlock(mutex);
> +    return NULL;
> +}
> diff --git a/src/pulsecore/log.h b/src/pulsecore/log.h
> index 8dd056b..c10d0cc 100644
> --- a/src/pulsecore/log.h
> +++ b/src/pulsecore/log.h
> @@ -31,6 +31,23 @@
>
>  /* A simple logging subsystem */
>
> +typedef struct pa_log_category pa_log_category_t;
> +
> +pa_log_category_t *pa_log_category_new(const char *name,
> +                                       int color,
> +                                       const char *description);
> +
> +extern pa_log_category_t *PA_LOG_CAT_CORE;
> +extern pa_log_category_t *PA_LOG_CAT_CHANNELMAP;
> +extern pa_log_category_t *PA_LOG_CAT_CONTEXT;
> +
> +#define PA_LOG_CATEGORY_STATIC(category) \
> +    static pa_log_category_t *category = NULL;
> +#define PA_LOG_CATEGORY_INIT(category,name,color) do {
>    \
> +    if (category == NULL)
>   \
> +        category = pa_log_category_new(name, color,
> pa__get_description()); \
> +} while (0)
> +
>  /* Where to log to */
>  typedef enum pa_log_target {
>     PA_LOG_STDERR,  /* default */
> @@ -86,13 +103,15 @@ void pa_log_set_show_backtrace(unsigned nlevels);
>  void pa_log_set_skip_backtrace(unsigned nlevels);
>
>  void pa_log_level_meta(
> +        pa_log_category_t *category,
>         pa_log_level_t level,
>         const char*file,
>         int line,
>         const char *func,
> -        const char *format, ...) PA_GCC_PRINTF_ATTR(5,6);
> +        const char *format, ...) PA_GCC_PRINTF_ATTR(6,7);
>
>  void pa_log_levelv_meta(
> +        pa_log_category_t *category,
>         pa_log_level_t level,
>         const char*file,
>         int line,
> @@ -101,10 +120,12 @@ void pa_log_levelv_meta(
>         va_list ap);
>
>  void pa_log_level(
> +        pa_log_category_t *category,
>         pa_log_level_t level,
> -        const char *format, ...) PA_GCC_PRINTF_ATTR(2,3);
> +        const char *format, ...) PA_GCC_PRINTF_ATTR(3,4);
>
>  void pa_log_levelv(
> +        pa_log_category_t *category,
>         pa_log_level_t level,
>         const char *format,
>         va_list ap);
> @@ -113,12 +134,12 @@ void pa_log_levelv(
>
>  /* ISO varargs available */
>
> -#define pa_log_debug(...)  pa_log_level_meta(PA_LOG_DEBUG,  __FILE__,
> __LINE__, __func__, __VA_ARGS__)
> -#define pa_log_info(...)   pa_log_level_meta(PA_LOG_INFO,   __FILE__,
> __LINE__, __func__, __VA_ARGS__)
> -#define pa_log_notice(...) pa_log_level_meta(PA_LOG_NOTICE, __FILE__,
> __LINE__, __func__, __VA_ARGS__)
> -#define pa_log_warn(...)   pa_log_level_meta(PA_LOG_WARN,   __FILE__,
> __LINE__, __func__, __VA_ARGS__)
> -#define pa_log_error(...)  pa_log_level_meta(PA_LOG_ERROR,  __FILE__,
> __LINE__, __func__, __VA_ARGS__)
> -#define pa_logl(level, ...)  pa_log_level_meta(level,  __FILE__,
> __LINE__, __func__, __VA_ARGS__)
> +#define pa_log_debug(...)  pa_log_level_meta(PA_LOG_CATEGORY_DEFAULT,
> PA_LOG_DEBUG,  __FILE__, __LINE__, __func__, __VA_ARGS__)
> +#define pa_log_info(...)   pa_log_level_meta(PA_LOG_CATEGORY_DEFAULT,
> PA_LOG_INFO,   __FILE__, __LINE__, __func__, __VA_ARGS__)
> +#define pa_log_notice(...) pa_log_level_meta(PA_LOG_CATEGORY_DEFAULT,
> PA_LOG_NOTICE, __FILE__, __LINE__, __func__, __VA_ARGS__)
> +#define pa_log_warn(...)   pa_log_level_meta(PA_LOG_CATEGORY_DEFAULT,
> PA_LOG_WARN,   __FILE__, __LINE__, __func__, __VA_ARGS__)
> +#define pa_log_error(...)  pa_log_level_meta(PA_LOG_CATEGORY_DEFAULT,
> PA_LOG_ERROR,  __FILE__, __LINE__, __func__, __VA_ARGS__)
> +#define pa_logl(level, ...)  pa_log_level_meta(PA_LOG_CATEGORY_DEFAULT,
> level,  __FILE__, __LINE__, __func__, __VA_ARGS__)
>
>  #else
>
> @@ -126,7 +147,7 @@ void pa_log_levelv(
>  PA_GCC_UNUSED static void pa_log_##suffix(const char *format, ...) { \
>     va_list ap; \
>     va_start(ap, format); \
> -    pa_log_levelv_meta(level, NULL, 0, NULL, format, ap); \
> +    pa_log_levelv_meta(PA_LOG_CATEGORY_DEFAULT, level, NULL, 0, NULL,
> format, ap); \
>     va_end(ap); \
>  }
>
> diff --git a/src/pulsecore/macro.h b/src/pulsecore/macro.h
> index c6d7d56..3cfa0ce 100644
> --- a/src/pulsecore/macro.h
> +++ b/src/pulsecore/macro.h
> @@ -221,11 +221,11 @@ typedef int pa_bool_t;
>  #define pa_assert_se(expr)                                              \
>     do {                                                                \
>         if (PA_UNLIKELY(!(expr))) {                                     \
> -            pa_log_error("Assertion '%s' failed at %s:%u, function %s().
> Aborting.", #expr , __FILE__, __LINE__, PA_PRETTY_FUNCTION); \
>             abort();                                                    \
>         }                                                               \
>     } while (FALSE)
>
> +//pa_log_error("Assertion '%s' failed at %s:%u, function %s().
> Aborting.", #expr , __FILE__, __LINE__, PA_PRETTY_FUNCTION);
>  /* Does exactly nothing */
>  #define pa_nop() do {} while (FALSE)
>
> diff --git a/src/pulsecore/ratelimit.c b/src/pulsecore/ratelimit.c
> index a274d2c..c5c03ee 100644
> --- a/src/pulsecore/ratelimit.c
> +++ b/src/pulsecore/ratelimit.c
> @@ -30,6 +30,8 @@
>
>  #include "ratelimit.h"
>
> +#define PA_LOG_CATEGORY_DEFAULT PA_LOG_CAT_CORE
> +
>  static pa_static_mutex mutex = PA_STATIC_MUTEX_INIT;
>
>  /* Modelled after Linux' lib/ratelimit.c by Dave Young
> --
> 1.7.6.5
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/pulseaudio-discuss/attachments/20120524/4c5495e1/attachment-0001.htm>


[Index of Archives]     [Linux Audio Users]     [AMD Graphics]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux