loudmouth/lm-debug.c
author Mikael Berthe <mikael@lilotux.net>
Mon, 13 Jun 2022 18:01:27 +0200
changeset 745 7785b42dd7bc
parent 690 7ccf2113ec5f
permissions -rw-r--r--
Merge pull request #46 from nekopsykose/fix-asyncns-addrinfo fix macro define for freeaddrinfo with asyncns committer: GitHub <noreply@github.com>
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
690
7ccf2113ec5f Update the postal address of the FSF
Frank Zschockelt <lm@freakysoft.de>
parents: 599
diff changeset
    16
 * License along with this program; if not, see <https://www.gnu.org/licenses>
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    17
 */
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    18
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    19
#include "lm-debug.h"
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    20
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    21
#ifndef LM_NO_DEBUG
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    22
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    23
static LmLogLevelFlags debug_flags = 0;
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    24
static gboolean initialized = FALSE;
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    25
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    26
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
    27
    {"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
    28
    {"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
    29
    {"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
    30
    {"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
    31
    {"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
    32
    {"ALL",          LM_LOG_LEVEL_ALL}
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    33
};
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    34
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    35
#define NUM_DEBUG_KEYS (sizeof (debug_keys) / sizeof (GDebugKey))
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    36
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    37
static void
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    38
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
    39
                   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
    40
                   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
    41
                   gpointer        user_data)
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    42
{
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
    43
    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
    44
        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
    45
            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
    46
        }
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
        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
    48
            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
    49
        }
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
    50
        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
    51
            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
    52
        }
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
        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
    54
            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
    55
        }
599
7207d1dbb86b Fix g_log issue when configured with --enable-debug=no.
Samuel Tesla <stesla@engineyard.com>
parents: 518
diff changeset
    56
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
    57
        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
    58
    }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    59
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    60
19
bb3195f74ac7 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 7
diff changeset
    61
/**
bb3195f74ac7 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 7
diff changeset
    62
 * lm_debug_init
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
 * Initialized the debug system.
bb3195f74ac7 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 7
diff changeset
    65
 **/
599
7207d1dbb86b Fix g_log issue when configured with --enable-debug=no.
Samuel Tesla <stesla@engineyard.com>
parents: 518
diff changeset
    66
void
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    67
lm_debug_init (void)
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    68
{
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
    69
    const gchar *env_lm_debug;
1
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
    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
    72
        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
    73
    }
599
7207d1dbb86b Fix g_log issue when configured with --enable-debug=no.
Samuel Tesla <stesla@engineyard.com>
parents: 518
diff changeset
    74
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
    75
    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
    76
    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
    77
        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
    78
                                            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
    79
    }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    80
599
7207d1dbb86b Fix g_log issue when configured with --enable-debug=no.
Samuel Tesla <stesla@engineyard.com>
parents: 518
diff changeset
    81
    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
    82
                       debug_log_handler, NULL);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    83
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
    initialized = TRUE;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    85
}
348
48fdfa327cc7 Make the 1.3 branch build with --disable-debug again. Fixes LM-113.
Martyn Russell <martyn@imendio.com>
parents: 255
diff changeset
    86
48fdfa327cc7 Make the 1.3 branch build with --disable-debug again. Fixes LM-113.
Martyn Russell <martyn@imendio.com>
parents: 255
diff changeset
    87
#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
    88
599
7207d1dbb86b Fix g_log issue when configured with --enable-debug=no.
Samuel Tesla <stesla@engineyard.com>
parents: 518
diff changeset
    89
static void
7207d1dbb86b Fix g_log issue when configured with --enable-debug=no.
Samuel Tesla <stesla@engineyard.com>
parents: 518
diff changeset
    90
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
    91
                        GLogLevelFlags  log_level,
7207d1dbb86b Fix g_log issue when configured with --enable-debug=no.
Samuel Tesla <stesla@engineyard.com>
parents: 518
diff changeset
    92
                        const gchar    *message,
7207d1dbb86b Fix g_log issue when configured with --enable-debug=no.
Samuel Tesla <stesla@engineyard.com>
parents: 518
diff changeset
    93
                        gpointer        user_data)
7207d1dbb86b Fix g_log issue when configured with --enable-debug=no.
Samuel Tesla <stesla@engineyard.com>
parents: 518
diff changeset
    94
{
7207d1dbb86b Fix g_log issue when configured with --enable-debug=no.
Samuel Tesla <stesla@engineyard.com>
parents: 518
diff changeset
    95
}
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
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
    98
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
    99
{
599
7207d1dbb86b Fix g_log issue when configured with --enable-debug=no.
Samuel Tesla <stesla@engineyard.com>
parents: 518
diff changeset
   100
    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
   101
                       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
   102
}
48fdfa327cc7 Make the 1.3 branch build with --disable-debug again. Fixes LM-113.
Martyn Russell <martyn@imendio.com>
parents: 255
diff changeset
   103
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   104
#endif /* LM_NO_DEBUG */
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   105