* mu-log.[ch]: still log to the log file with --quiet
This commit is contained in:
16
src/mu-log.c
16
src/mu-log.c
@ -35,8 +35,10 @@
|
|||||||
|
|
||||||
struct _MuLog {
|
struct _MuLog {
|
||||||
int _fd; /* log file descriptor */
|
int _fd; /* log file descriptor */
|
||||||
int _own; /* close _fd with log_destroy? */
|
|
||||||
int _debug; /* add debug-level stuff? */
|
gboolean _own; /* close _fd with log_destroy? */
|
||||||
|
gboolean _debug; /* add debug-level stuff? */
|
||||||
|
gboolean _quiet; /* don't write non-error to stdout/stderr */
|
||||||
|
|
||||||
GLogFunc _old_log_func;
|
GLogFunc _old_log_func;
|
||||||
};
|
};
|
||||||
@ -94,13 +96,14 @@ log_handler (const gchar* log_domain, GLogLevelFlags log_level,
|
|||||||
|
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
mu_log_init_with_fd (int fd, gboolean doclose, gboolean debug)
|
mu_log_init_with_fd (int fd, gboolean doclose, gboolean quiet, gboolean debug)
|
||||||
{
|
{
|
||||||
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 = fd;
|
MU_LOG->_fd = fd;
|
||||||
|
MU_LOG->_quiet = quiet;
|
||||||
MU_LOG->_debug = debug;
|
MU_LOG->_debug = debug;
|
||||||
MU_LOG->_own = doclose; /* if we now own the fd, close it
|
MU_LOG->_own = doclose; /* if we now own the fd, close it
|
||||||
* in _destroy */
|
* in _destroy */
|
||||||
@ -111,7 +114,8 @@ mu_log_init_with_fd (int fd, gboolean doclose, gboolean debug)
|
|||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
mu_log_init (const char* muhome, gboolean append, gboolean debug)
|
mu_log_init (const char* muhome, gboolean append,
|
||||||
|
gboolean quiet, gboolean debug)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
gchar *logfile;
|
gchar *logfile;
|
||||||
@ -134,7 +138,7 @@ mu_log_init (const char* muhome, gboolean append, gboolean debug)
|
|||||||
logfile, strerror(errno));
|
logfile, strerror(errno));
|
||||||
g_free (logfile);
|
g_free (logfile);
|
||||||
|
|
||||||
if (fd < 0 || !mu_log_init_with_fd (fd, FALSE, debug)) {
|
if (fd < 0 || !mu_log_init_with_fd (fd, FALSE, quiet, debug)) {
|
||||||
_try_close (fd);
|
_try_close (fd);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
@ -197,7 +201,7 @@ log_write (const char* domain, GLogLevelFlags level,
|
|||||||
fprintf (stderr, "%s: failed to write to log: %s\n",
|
fprintf (stderr, "%s: failed to write to log: %s\n",
|
||||||
__FUNCTION__, strerror(errno));
|
__FUNCTION__, strerror(errno));
|
||||||
|
|
||||||
if (level & G_LOG_LEVEL_MESSAGE)
|
if (!(MU_LOG->_quiet) && level & G_LOG_LEVEL_MESSAGE)
|
||||||
g_print ("mu: %s\n", msg);
|
g_print ("mu: %s\n", msg);
|
||||||
|
|
||||||
/* for serious errors, log them to stderr as well */
|
/* for serious errors, log them to stderr as well */
|
||||||
|
|||||||
@ -29,25 +29,26 @@
|
|||||||
*
|
*
|
||||||
* @param muhome the mu home directory
|
* @param muhome the mu home directory
|
||||||
* @param append append to logfile, instead of overwriting
|
* @param append append to logfile, instead of overwriting
|
||||||
|
* @param quiet don't log non-errors to stdout/stderr
|
||||||
* @param debug include debug-level information.
|
* @param debug include debug-level information.
|
||||||
*
|
*
|
||||||
* @return TRUE if initialization succeeds, FALSE otherwise
|
* @return TRUE if initialization succeeds, FALSE otherwise
|
||||||
*/
|
*/
|
||||||
gboolean mu_log_init (const char* muhome, gboolean append,
|
gboolean mu_log_init (const char* muhome, gboolean append,
|
||||||
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
|
||||||
* @param doclose if true, mu-log will close it upon mu_log_uninit
|
* @param doclose if true, mu-log will close it upon mu_log_uninit
|
||||||
|
* @param quiet don't log non-errors to stdout/stderr
|
||||||
* @param debug include debug-level info
|
* @param debug include debug-level info
|
||||||
*
|
*
|
||||||
* @return TRUE if initialization succeeds, FALSE otherwise
|
* @return TRUE if initialization succeeds, FALSE otherwise
|
||||||
*/
|
*/
|
||||||
gboolean mu_log_init_with_fd (int fd, gboolean doclose, gboolean debug);
|
gboolean mu_log_init_with_fd (int fd, gboolean doclose, gboolean quiet,
|
||||||
|
gboolean debug);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* be absolutely silent, except for runtime errors, which will be
|
* be absolutely silent, except for runtime errors, which will be
|
||||||
|
|||||||
Reference in New Issue
Block a user