* small logging cleanups, don't g_debug before we initialized logging

This commit is contained in:
Dirk-Jan C. Binnema 2010-10-09 12:44:48 +03:00
parent 7de56f9399
commit 89b65df13b
3 changed files with 29 additions and 20 deletions

View File

@ -1,5 +1,5 @@
/* /*
** Copyright (C) 2010 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl> ** Copyright (C) 2008-2010 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
** **
** This program is free software; you can redistribute it and/or modify ** 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 ** it under the terms of the GNU General Public License as published by
@ -17,7 +17,11 @@
** **
*/ */
#ifdef HAVE_CONFIG_H
#include <config.h> #include <config.h>
#endif /*HAVE_CONFIG_H*/
#include "mu-log.h"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@ -29,7 +33,6 @@
#include <errno.h> #include <errno.h>
#include <string.h> #include <string.h>
#include "mu-log.h"
#include "mu-util.h" #include "mu-util.h"
#define MU_LOG_FILE "mu.log" #define MU_LOG_FILE "mu.log"
@ -72,9 +75,9 @@ mu_log_init_silence (void)
{ {
g_return_val_if_fail (!MU_LOG, FALSE); g_return_val_if_fail (!MU_LOG, FALSE);
MU_LOG = g_new(MuLog, 1); MU_LOG = g_new(MuLog, 1);
MU_LOG->_fd = -1; MU_LOG->_fd = -1;
MU_LOG->_own = FALSE; /* nobody owns silence */ MU_LOG->_own = FALSE; /* nobody owns silence */
MU_LOG->_old_log_func = MU_LOG->_old_log_func =
g_log_set_default_handler ((GLogFunc)silence, NULL); g_log_set_default_handler ((GLogFunc)silence, NULL);
@ -142,7 +145,7 @@ log_file_backup_maybe (const char *logfile)
if (errno == ENOENT) if (errno == ENOENT)
return TRUE; /* it did not exist yet, no problem */ return TRUE; /* it did not exist yet, no problem */
else { else {
g_warning ("Failed to stat(2) %s", logfile); g_warning ("failed to stat(2) %s", logfile);
return FALSE; return FALSE;
} }
} }
@ -168,7 +171,7 @@ mu_log_init (const char* muhome,
g_return_val_if_fail (muhome, FALSE); g_return_val_if_fail (muhome, FALSE);
if (!mu_util_create_dir_maybe(muhome)) { if (!mu_util_create_dir_maybe(muhome)) {
g_warning ("Failed to init log in %s", muhome); g_warning ("failed to init log in %s", muhome);
return FALSE; return FALSE;
} }
@ -176,7 +179,7 @@ mu_log_init (const char* muhome,
G_DIR_SEPARATOR, MU_LOG_FILE); G_DIR_SEPARATOR, MU_LOG_FILE);
if (backup && !log_file_backup_maybe(logfile)) { if (backup && !log_file_backup_maybe(logfile)) {
g_warning ("Failed to backup log file"); g_warning ("failed to backup log file");
return FALSE; return FALSE;
} }

View File

@ -1,5 +1,5 @@
/* /*
** Copyright (C) 2010 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl> ** Copyright (C) 2008-2010 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
** **
** This program is free software; you can redistribute it and/or modify ** 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 ** it under the terms of the GNU General Public License as published by
@ -28,7 +28,7 @@ G_BEGIN_DECLS
#define MU_MAX_LOG_FILE_SIZE 1000 * 1000 /* 1 MB (SI units) */ #define MU_MAX_LOG_FILE_SIZE 1000 * 1000 /* 1 MB (SI units) */
/** /**
* write logging information to a log file * write logging information to a log file
* *
* @param muhome the mu home directory * @param muhome the mu home directory
@ -43,7 +43,7 @@ G_BEGIN_DECLS
gboolean mu_log_init (const char* muhome, gboolean backup, gboolean mu_log_init (const char* muhome, gboolean backup,
gboolean quiet, gboolean debug); gboolean quiet, gboolean debug);
/** /**
* write logging information to a file descriptor * write logging information to a file descriptor
* *
* @param fd an open file descriptor * @param fd an open file descriptor
@ -56,7 +56,7 @@ gboolean mu_log_init (const char* muhome, gboolean backup,
gboolean mu_log_init_with_fd (int fd, gboolean doclose, gboolean quiet, gboolean mu_log_init_with_fd (int fd, gboolean doclose, gboolean quiet,
gboolean debug); gboolean debug);
/** /**
* be absolutely silent, except for runtime errors, which will be * be absolutely silent, except for runtime errors, which will be
* written to stderr. * written to stderr.
* *
@ -65,7 +65,7 @@ gboolean mu_log_init_with_fd (int fd, gboolean doclose, gboolean quiet,
gboolean mu_log_init_silence (void); gboolean mu_log_init_silence (void);
/** /**
* unitialize the logging system, and free all resources * unitialize the logging system, and free all resources
*/ */
void mu_log_uninit (void); void mu_log_uninit (void);

View File

@ -17,6 +17,12 @@
** **
*/ */
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif /*HAVE_CONFIG_H*/
#include "mu-util.h"
#define _XOPEN_SOURCE 500 #define _XOPEN_SOURCE 500
#include <wordexp.h> /* for shell-style globbing */ #include <wordexp.h> /* for shell-style globbing */
#include <stdlib.h> #include <stdlib.h>
@ -43,8 +49,6 @@
#include <glib/gstdio.h> #include <glib/gstdio.h>
#include <errno.h> #include <errno.h>
#include "mu-util.h"
static char* static char*
do_wordexp (const char *path) do_wordexp (const char *path)
{ {
@ -57,12 +61,12 @@ do_wordexp (const char *path)
} }
if (wordexp (path, &wexp, 0) != 0) { if (wordexp (path, &wexp, 0) != 0) {
g_debug ("%s: expansion failed for %s", __FUNCTION__, path); /* g_debug ("%s: expansion failed for %s", __FUNCTION__, path); */
return NULL; return NULL;
} }
if (wexp.we_wordc != 1) /* not an *error*, we just take the first one */ /* if (wexp.we_wordc != 1) /\* not an *error*, we just take the first one *\/ */
g_debug ("%s: expansion ambiguous for '%s'", __FUNCTION__, path); /* g_debug ("%s: expansion ambiguous for '%s'", __FUNCTION__, path); */
dir = g_strdup (wexp.we_wordv[0]); dir = g_strdup (wexp.we_wordv[0]);
@ -78,6 +82,8 @@ do_wordexp (const char *path)
} }
/* note, the g_debugs are commented out because this function may be
* called before the log handler is installed. */
char* char*
mu_util_dir_expand (const char *path) mu_util_dir_expand (const char *path)
{ {
@ -92,8 +98,8 @@ mu_util_dir_expand (const char *path)
/* now, resolve any symlinks, .. etc. */ /* now, resolve any symlinks, .. etc. */
if (!realpath (dir, resolved)) { if (!realpath (dir, resolved)) {
g_debug ("%s: could not get realpath for '%s': %s", /* g_debug ("%s: could not get realpath for '%s': %s", */
__FUNCTION__, dir, strerror(errno)); /* __FUNCTION__, dir, strerror(errno)); */
g_free (dir); g_free (dir);
return NULL; return NULL;
} else } else