* lib/mu-log: cleanups and some improvements
use an option enum instead of boolean args for code clarity; allow for printing an \n before logging to tty (improved mu-index output). allow for color in logging to tty
This commit is contained in:
90
lib/mu-log.h
90
lib/mu-log.h
@ -1,22 +1,22 @@
|
||||
/* -*-mode: c; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-*/
|
||||
|
||||
/*
|
||||
** Copyright (C) 2008-2011 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
||||
/* -*-mode: c; tab-width: 8; indent-tabs-mode: t; c-basic-offset:
|
||||
8 -*-*/
|
||||
/*
|
||||
** Copyright (C) 2008-2012 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
||||
**
|
||||
** 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 3 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
**
|
||||
** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
**
|
||||
*/
|
||||
|
||||
#ifndef __MU_LOG_H__
|
||||
@ -28,40 +28,49 @@
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
/**
|
||||
* write logging information to a log file
|
||||
*
|
||||
* @param full path to the log file (does not have to exist yet, but
|
||||
* it's directory must)
|
||||
* @param backup if TRUE and size of log file > MU_MAX_LOG_FILE_SIZE, move
|
||||
* the log file to <log file>.old and start a new one. The .old file will overwrite
|
||||
* existing files of that name
|
||||
* @param quiet don't log non-errors to stdout/stderr
|
||||
* @param debug include debug-level information.
|
||||
*
|
||||
* @return TRUE if initialization succeeds, FALSE otherwise
|
||||
*/
|
||||
gboolean mu_log_init (const char *logfile, gboolean backup,
|
||||
gboolean quiet, gboolean debug)
|
||||
G_GNUC_WARN_UNUSED_RESULT;
|
||||
enum _MuLogOptions {
|
||||
MU_LOG_OPTIONS_NONE = 0,
|
||||
|
||||
/* when size of log file > MU_MAX_LOG_FILE_SIZE, move the log
|
||||
* file to <log file>.old and start a new one. The .old file will
|
||||
* overwrite existing files of that name */
|
||||
MU_LOG_OPTIONS_BACKUP = 1 << 1,
|
||||
|
||||
/* quiet: don't log non-errors to stdout/stderr */
|
||||
MU_LOG_OPTIONS_QUIET = 1 << 2,
|
||||
|
||||
/* should lines be preceded by \n? useful when errors come
|
||||
* during indexing */
|
||||
MU_LOG_OPTIONS_NEWLINE = 1 << 3,
|
||||
|
||||
/* color in output (iff output is to a tty) */
|
||||
MU_LOG_OPTIONS_COLOR = 1 << 4,
|
||||
|
||||
/* log everything to stderr */
|
||||
MU_LOG_OPTIONS_STDERR = 1 << 5,
|
||||
|
||||
/* debug: debug include debug-level information */
|
||||
MU_LOG_OPTIONS_DEBUG = 1 << 6
|
||||
};
|
||||
typedef enum _MuLogOptions MuLogOptions;
|
||||
|
||||
|
||||
/**
|
||||
* write logging information to a file descriptor
|
||||
*
|
||||
* @param fd an open file descriptor
|
||||
* @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
|
||||
*
|
||||
* write logging information to a log file
|
||||
*
|
||||
* @param full path to the log file (does not have to exist yet, but
|
||||
* it's directory must)
|
||||
* @param opts logging options
|
||||
*
|
||||
* @return TRUE if initialization succeeds, FALSE otherwise
|
||||
*/
|
||||
gboolean mu_log_init_with_fd (int fd, gboolean doclose, gboolean quiet,
|
||||
gboolean debug) G_GNUC_WARN_UNUSED_RESULT;
|
||||
gboolean mu_log_init (const char *logfile, MuLogOptions opts)
|
||||
G_GNUC_WARN_UNUSED_RESULT;
|
||||
|
||||
/**
|
||||
* be silent except for runtime errors, which will be written to
|
||||
* stderr.
|
||||
*
|
||||
*
|
||||
* @return TRUE if initialization succeeds, FALSE otherwise
|
||||
*/
|
||||
gboolean mu_log_init_silence (void) G_GNUC_WARN_UNUSED_RESULT;
|
||||
@ -71,6 +80,19 @@ gboolean mu_log_init_silence (void) G_GNUC_WARN_UNUSED_RESULT;
|
||||
*/
|
||||
void mu_log_uninit (void);
|
||||
|
||||
/**
|
||||
* set logging options, a logical-OR'd value of MuLogOptions
|
||||
*
|
||||
* @param opts the options (logically OR'd)
|
||||
*/
|
||||
void mu_log_options_set (MuLogOptions opts);
|
||||
|
||||
/**
|
||||
* get logging options, a logical-OR'd value of MuLogOptions
|
||||
*
|
||||
* @param opts the options (logically OR'd)
|
||||
*/
|
||||
MuLogOptions mu_log_options_get (void);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
||||
Reference in New Issue
Block a user