Commit 51129099 authored by William Jon McCann's avatar William Jon McCann Committed by William Jon McCann

Add log/debugging framework.

2008-08-15  William Jon McCann  <jmccann@redhat.com>

	* gnome-session/Makefile.am:
	* gnome-session/gdm-log.c (log_level_to_priority_and_prefix),
	(gdm_log_default_handler), (gdm_log_toggle_debug),
	(gdm_log_set_debug), (gdm_log_init), (gdm_log_shutdown):
	* gnome-session/gdm-log.h:
	* gnome-session/main.c (signal_cb), (main):
	Add log/debugging framework.


svn path=/trunk/; revision=4959
parent f9f6b0ac
2008-08-15 William Jon McCann <jmccann@redhat.com>
* gnome-session/Makefile.am:
* gnome-session/gdm-log.c (log_level_to_priority_and_prefix),
(gdm_log_default_handler), (gdm_log_toggle_debug),
(gdm_log_set_debug), (gdm_log_init), (gdm_log_shutdown):
* gnome-session/gdm-log.h:
* gnome-session/main.c (signal_cb), (main):
Add log/debugging framework.
2008-08-15 William Jon McCann <jmccann@redhat.com>
* gnome-session/gdm-signal-handler.c (signal_io_watch),
......
......@@ -81,6 +81,8 @@ gnome_session_SOURCES = \
gdm.c \
gdm-signal-handler.h \
gdm-signal-handler.c \
gdm-log.h \
gdm-log.c \
main.c \
gsm-store.h \
gsm-store.c \
......
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
*
* Copyright (C) 2007 William Jon McCann <mccann@jhu.edu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* Authors: William Jon McCann <mccann@jhu.edu>
*
*/
#include "config.h"
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#include <signal.h>
#include <time.h>
#include <unistd.h>
#include <syslog.h>
#include <glib.h>
#include <glib/gstdio.h>
#include "gdm-log.h"
static gboolean initialized = FALSE;
static int syslog_levels = (G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING);
static void
log_level_to_priority_and_prefix (GLogLevelFlags log_level,
int *priorityp,
const char **prefixp)
{
int priority;
const char *prefix;
/* Process the message prefix and priority */
switch (log_level & G_LOG_LEVEL_MASK) {
case G_LOG_FLAG_FATAL:
priority = LOG_EMERG;
prefix = "FATAL";
break;
case G_LOG_LEVEL_ERROR:
priority = LOG_ERR;
prefix = "ERROR";
break;
case G_LOG_LEVEL_CRITICAL:
priority = LOG_CRIT;
prefix = "CRITICAL";
break;
case G_LOG_LEVEL_WARNING:
priority = LOG_WARNING;
prefix = "WARNING";
break;
case G_LOG_LEVEL_MESSAGE:
priority = LOG_NOTICE;
prefix = "MESSAGE";
break;
case G_LOG_LEVEL_INFO:
priority = LOG_INFO;
prefix = "INFO";
break;
case G_LOG_LEVEL_DEBUG:
/* if debug was requested then bump this up to ERROR
* to ensure it is seen in a log */
if (syslog_levels & G_LOG_LEVEL_DEBUG) {
priority = LOG_WARNING;
prefix = "DEBUG(+)";
} else {
priority = LOG_DEBUG;
prefix = "DEBUG";
}
break;
default:
priority = LOG_DEBUG;
prefix = "UNKNOWN";
break;
}
if (priorityp != NULL) {
*priorityp = priority;
}
if (prefixp != NULL) {
*prefixp = prefix;
}
}
void
gdm_log_default_handler (const gchar *log_domain,
GLogLevelFlags log_level,
const gchar *message,
gpointer unused_data)
{
GString *gstring;
int priority;
const char *level_prefix;
char *string;
gboolean do_log;
gboolean is_fatal;
is_fatal = (log_level & G_LOG_FLAG_FATAL) != 0;
do_log = (log_level & syslog_levels);
if (! do_log) {
return;
}
if (! initialized) {
gdm_log_init ();
}
log_level_to_priority_and_prefix (log_level,
&priority,
&level_prefix);
gstring = g_string_new (NULL);
if (log_domain != NULL) {
g_string_append (gstring, log_domain);
g_string_append_c (gstring, '-');
}
g_string_append (gstring, level_prefix);
g_string_append (gstring, ": ");
if (message == NULL) {
g_string_append (gstring, "(NULL) message");
} else {
g_string_append (gstring, message);
}
if (is_fatal) {
g_string_append (gstring, "\naborting...\n");
} else {
g_string_append (gstring, "\n");
}
string = g_string_free (gstring, FALSE);
syslog (priority, "%s", string);
g_free (string);
}
void
gdm_log_toggle_debug (void)
{
if (syslog_levels & G_LOG_LEVEL_DEBUG) {
g_debug ("Debugging disabled");
syslog_levels &= ~G_LOG_LEVEL_DEBUG;
} else {
syslog_levels |= G_LOG_LEVEL_DEBUG;
g_debug ("Debugging enabled");
}
}
void
gdm_log_set_debug (gboolean debug)
{
if (debug) {
syslog_levels |= G_LOG_LEVEL_DEBUG;
g_debug ("Enabling debugging");
} else {
g_debug ("Disabling debugging");
syslog_levels &= ~G_LOG_LEVEL_DEBUG;
}
}
void
gdm_log_init (void)
{
const char *prg_name;
int options;
g_log_set_default_handler (gdm_log_default_handler, NULL);
prg_name = g_get_prgname ();
options = LOG_PID;
#ifdef LOG_PERROR
options |= LOG_PERROR;
#endif
openlog (prg_name, options, LOG_DAEMON);
initialized = TRUE;
}
void
gdm_log_shutdown (void)
{
closelog ();
initialized = FALSE;
}
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
*
* Copyright (C) 2007 William Jon McCann <mccann@jhu.edu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* Authors: William Jon McCann <mccann@jhu.edu>
*
*/
#ifndef __GDM_LOG_H
#define __GDM_LOG_H
#include <stdarg.h>
#include <glib.h>
G_BEGIN_DECLS
void gdm_log_default_handler (const gchar *log_domain,
GLogLevelFlags log_level,
const gchar *message,
gpointer unused_data);
void gdm_log_set_debug (gboolean debug);
void gdm_log_toggle_debug (void);
void gdm_log_init (void);
void gdm_log_shutdown (void);
/* compatibility */
#define gdm_fail g_critical
#define gdm_error g_warning
#define gdm_info g_message
#define gdm_debug g_debug
#define gdm_assert g_assert
#define gdm_assert_not_reached g_assert_not_reached
G_END_DECLS
#endif /* __GDM_LOG_H */
......@@ -36,6 +36,7 @@
#include <dbus/dbus-glib-lowlevel.h>
#include "gdm-signal-handler.h"
#include "gdm-log.h"
#include "gsm-gconf.h"
#include "gsm-util.h"
......@@ -53,9 +54,12 @@
static gboolean failsafe = FALSE;
static gboolean show_version = FALSE;
static char **override_autostart_dirs = NULL;
/* FIXME: turn this off closer to release */
static gboolean debug = TRUE;
static GOptionEntry entries[] = {
{ "autostart", 'a', 0, G_OPTION_ARG_STRING_ARRAY, &override_autostart_dirs, N_("Override standard autostart directories"), NULL },
{ "debug", 0, 0, G_OPTION_ARG_NONE, &debug, N_("Enable debugging code"), NULL },
{ "failsafe", 'f', 0, G_OPTION_ARG_NONE, &failsafe, N_("Do not load user-specified applications"), NULL },
{ "version", 0, 0, G_OPTION_ARG_NONE, &show_version, N_("Version of this application"), NULL },
{ NULL, 0, 0, 0, NULL, NULL, NULL }
......@@ -374,7 +378,7 @@ signal_cb (int signo,
case SIGUSR1:
g_debug ("Got USR1 signal");
ret = TRUE;
/*gdm_log_toggle_debug (); */
gdm_log_toggle_debug ();
break;
default:
g_debug ("Caught unhandled signal %d", signo);
......@@ -421,6 +425,9 @@ main (int argc, char **argv)
exit (1);
}
gdm_log_init ();
gdm_log_set_debug (debug);
signal_handler = gdm_signal_handler_new ();
gdm_signal_handler_set_fatal_func (signal_handler, (GDestroyNotify)gtk_main_quit, NULL);
gdm_signal_handler_add_fatal (signal_handler);
......@@ -478,5 +485,7 @@ main (int argc, char **argv)
gsm_gconf_shutdown ();
gdm_log_shutdown ();
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment