loudmouth/lm-debug.c
author Mikael Berthe <mikael@lilotux.net>
Mon, 25 Jan 2016 18:35:10 +0100
changeset 685 dfa02c1c7fda
parent 599 7207d1dbb86b
child 690 7ccf2113ec5f
permissions -rw-r--r--
Bumped version to 1.5.2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
516
4dd3aa6b83e5 Change the tab width to 4 steps in the emacs headers
Mikael Hallendal <micke@imendio.com>
parents: 515
diff changeset
     1
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
     2
/*
99
81e9d035de02 2004-10-05 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 84
diff changeset
     3
 * Copyright (C) 2003 Imendio AB
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
     4
 *
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
     6
 * modify it under the terms of the GNU Lesser General Public License as
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
     7
 * published by the Free Software Foundation; either version 2 of the
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
     8
 * License, or (at your option) any later version.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
     9
 *
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    10
 * This program is distributed in the hope that it will be useful,
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    13
 * Lesser General Public License for more details.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    14
 *
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    15
 * You should have received a copy of the GNU Lesser General Public
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    16
 * License along with this program; if not, write to the
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    17
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    18
 * Boston, MA 02111-1307, USA.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    19
 */
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    20
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    21
#include "lm-debug.h"
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    22
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    23
#ifndef LM_NO_DEBUG
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    24
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    25
static LmLogLevelFlags debug_flags = 0;
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    26
static gboolean initialized = FALSE;
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    27
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    28
static const GDebugKey debug_keys[] = {
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    29
    {"VERBOSE",      LM_LOG_LEVEL_VERBOSE},
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    30
    {"NET",          LM_LOG_LEVEL_NET},
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    31
    {"PARSER",       LM_LOG_LEVEL_PARSER},
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    32
    {"SSL",          LM_LOG_LEVEL_SSL},
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    33
    {"SASL",         LM_LOG_LEVEL_SASL},
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    34
    {"ALL",          LM_LOG_LEVEL_ALL}
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    35
};
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    36
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    37
#define NUM_DEBUG_KEYS (sizeof (debug_keys) / sizeof (GDebugKey))
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    38
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    39
static void
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    40
debug_log_handler (const gchar    *log_domain,
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    41
                   GLogLevelFlags  log_level,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    42
                   const gchar    *message,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    43
                   gpointer        user_data)
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    44
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    45
    if (debug_flags & log_level) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    46
        if (log_level & LM_LOG_LEVEL_VERBOSE) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    47
            g_print ("*** ");
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    48
        }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    49
        else if (log_level & LM_LOG_LEVEL_PARSER) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    50
            g_print ("LM-PARSER: ");
599
7207d1dbb86b Fix g_log issue when configured with --enable-debug=no.
Samuel Tesla <stesla@engineyard.com>
parents: 518
diff changeset
    51
        }
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    52
        else if (log_level & LM_LOG_LEVEL_SASL) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    53
            g_print ("LM-SASL: ");
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    54
        }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    55
        else if (log_level & LM_LOG_LEVEL_SSL) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    56
            g_print ("LM-SSL: ");
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    57
        }
599
7207d1dbb86b Fix g_log issue when configured with --enable-debug=no.
Samuel Tesla <stesla@engineyard.com>
parents: 518
diff changeset
    58
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    59
        g_print ("%s", message);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    60
    }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    61
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    62
19
bb3195f74ac7 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 7
diff changeset
    63
/**
bb3195f74ac7 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 7
diff changeset
    64
 * lm_debug_init
bb3195f74ac7 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 7
diff changeset
    65
 *
bb3195f74ac7 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 7
diff changeset
    66
 * Initialized the debug system.
bb3195f74ac7 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 7
diff changeset
    67
 **/
599
7207d1dbb86b Fix g_log issue when configured with --enable-debug=no.
Samuel Tesla <stesla@engineyard.com>
parents: 518
diff changeset
    68
void
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    69
lm_debug_init (void)
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    70
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    71
    const gchar *env_lm_debug;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    72
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    73
    if (initialized) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    74
        return;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    75
    }
599
7207d1dbb86b Fix g_log issue when configured with --enable-debug=no.
Samuel Tesla <stesla@engineyard.com>
parents: 518
diff changeset
    76
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    77
    env_lm_debug = g_getenv ("LM_DEBUG");
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    78
    if (env_lm_debug) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    79
        debug_flags = g_parse_debug_string (env_lm_debug, debug_keys,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    80
                                            NUM_DEBUG_KEYS);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    81
    }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    82
599
7207d1dbb86b Fix g_log issue when configured with --enable-debug=no.
Samuel Tesla <stesla@engineyard.com>
parents: 518
diff changeset
    83
    g_log_set_handler (LM_LOG_DOMAIN, LM_LOG_LEVEL_ALL,
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    84
                       debug_log_handler, NULL);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    85
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    86
    initialized = TRUE;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    87
}
348
48fdfa327cc7 Make the 1.3 branch build with --disable-debug again. Fixes LM-113.
Martyn Russell <martyn@imendio.com>
parents: 255
diff changeset
    88
48fdfa327cc7 Make the 1.3 branch build with --disable-debug again. Fixes LM-113.
Martyn Russell <martyn@imendio.com>
parents: 255
diff changeset
    89
#else  /* LM_NO_DEBUG */
48fdfa327cc7 Make the 1.3 branch build with --disable-debug again. Fixes LM-113.
Martyn Russell <martyn@imendio.com>
parents: 255
diff changeset
    90
599
7207d1dbb86b Fix g_log issue when configured with --enable-debug=no.
Samuel Tesla <stesla@engineyard.com>
parents: 518
diff changeset
    91
static void
7207d1dbb86b Fix g_log issue when configured with --enable-debug=no.
Samuel Tesla <stesla@engineyard.com>
parents: 518
diff changeset
    92
do_nothing_log_handler (const gchar    *log_domain,
7207d1dbb86b Fix g_log issue when configured with --enable-debug=no.
Samuel Tesla <stesla@engineyard.com>
parents: 518
diff changeset
    93
                        GLogLevelFlags  log_level,
7207d1dbb86b Fix g_log issue when configured with --enable-debug=no.
Samuel Tesla <stesla@engineyard.com>
parents: 518
diff changeset
    94
                        const gchar    *message,
7207d1dbb86b Fix g_log issue when configured with --enable-debug=no.
Samuel Tesla <stesla@engineyard.com>
parents: 518
diff changeset
    95
                        gpointer        user_data)
7207d1dbb86b Fix g_log issue when configured with --enable-debug=no.
Samuel Tesla <stesla@engineyard.com>
parents: 518
diff changeset
    96
{
7207d1dbb86b Fix g_log issue when configured with --enable-debug=no.
Samuel Tesla <stesla@engineyard.com>
parents: 518
diff changeset
    97
}
7207d1dbb86b Fix g_log issue when configured with --enable-debug=no.
Samuel Tesla <stesla@engineyard.com>
parents: 518
diff changeset
    98
7207d1dbb86b Fix g_log issue when configured with --enable-debug=no.
Samuel Tesla <stesla@engineyard.com>
parents: 518
diff changeset
    99
void
348
48fdfa327cc7 Make the 1.3 branch build with --disable-debug again. Fixes LM-113.
Martyn Russell <martyn@imendio.com>
parents: 255
diff changeset
   100
lm_debug_init (void)
48fdfa327cc7 Make the 1.3 branch build with --disable-debug again. Fixes LM-113.
Martyn Russell <martyn@imendio.com>
parents: 255
diff changeset
   101
{
599
7207d1dbb86b Fix g_log issue when configured with --enable-debug=no.
Samuel Tesla <stesla@engineyard.com>
parents: 518
diff changeset
   102
    g_log_set_handler (LM_LOG_DOMAIN, LM_LOG_LEVEL_ALL,
7207d1dbb86b Fix g_log issue when configured with --enable-debug=no.
Samuel Tesla <stesla@engineyard.com>
parents: 518
diff changeset
   103
                       do_nothing_log_handler, NULL);
348
48fdfa327cc7 Make the 1.3 branch build with --disable-debug again. Fixes LM-113.
Martyn Russell <martyn@imendio.com>
parents: 255
diff changeset
   104
}
48fdfa327cc7 Make the 1.3 branch build with --disable-debug again. Fixes LM-113.
Martyn Russell <martyn@imendio.com>
parents: 255
diff changeset
   105
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   106
#endif /* LM_NO_DEBUG */
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   107