1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
3
* Copyright (C) 2007 William Jon McCann <mccann@jhu.edu>
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 2 of the License, or
8
* (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19
* Authors: William Jon McCann <mccann@jhu.edu>
35
#include <glib/gstdio.h>
39
static gboolean initialized = FALSE;
40
static int syslog_levels = (G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING);
43
log_level_to_priority_and_prefix (GLogLevelFlags log_level,
50
/* Process the message prefix and priority */
51
switch (log_level & G_LOG_LEVEL_MASK) {
52
case G_LOG_FLAG_FATAL:
56
case G_LOG_LEVEL_ERROR:
60
case G_LOG_LEVEL_CRITICAL:
64
case G_LOG_LEVEL_WARNING:
65
priority = LOG_WARNING;
68
case G_LOG_LEVEL_MESSAGE:
69
priority = LOG_NOTICE;
72
case G_LOG_LEVEL_INFO:
76
case G_LOG_LEVEL_DEBUG:
77
/* if debug was requested then bump this up to ERROR
78
* to ensure it is seen in a log */
79
if (syslog_levels & G_LOG_LEVEL_DEBUG) {
80
priority = LOG_WARNING;
93
if (priorityp != NULL) {
94
*priorityp = priority;
96
if (prefixp != NULL) {
102
gdm_log_default_handler (const gchar *log_domain,
103
GLogLevelFlags log_level,
104
const gchar *message,
105
gpointer unused_data)
109
const char *level_prefix;
114
is_fatal = (log_level & G_LOG_FLAG_FATAL) != 0;
116
do_log = (log_level & syslog_levels);
125
log_level_to_priority_and_prefix (log_level,
129
gstring = g_string_new (NULL);
131
if (log_domain != NULL) {
132
g_string_append (gstring, log_domain);
133
g_string_append_c (gstring, '-');
135
g_string_append (gstring, level_prefix);
137
g_string_append (gstring, ": ");
138
if (message == NULL) {
139
g_string_append (gstring, "(NULL) message");
141
g_string_append (gstring, message);
144
g_string_append (gstring, "\naborting...\n");
146
g_string_append (gstring, "\n");
149
string = g_string_free (gstring, FALSE);
151
syslog (priority, "%s", string);
157
gdm_log_toggle_debug (void)
159
if (syslog_levels & G_LOG_LEVEL_DEBUG) {
160
g_debug ("Debugging disabled");
161
syslog_levels &= ~G_LOG_LEVEL_DEBUG;
163
syslog_levels |= G_LOG_LEVEL_DEBUG;
164
g_debug ("Debugging enabled");
169
gdm_log_set_debug (gboolean debug)
172
syslog_levels |= G_LOG_LEVEL_DEBUG;
173
g_debug ("Enabling debugging");
175
g_debug ("Disabling debugging");
176
syslog_levels &= ~G_LOG_LEVEL_DEBUG;
183
const char *prg_name;
186
g_log_set_default_handler (gdm_log_default_handler, NULL);
188
prg_name = g_get_prgname ();
192
options |= LOG_PERROR;
195
openlog (prg_name, options, LOG_DAEMON);
201
gdm_log_shutdown (void)