mirror of https://github.com/djcb/mu.git
* implement automatic log file cleanup, document it
This commit is contained in:
parent
a87c514965
commit
a2d1692dda
4
TODO
4
TODO
|
@ -2,7 +2,7 @@
|
|||
|
||||
* Future release
|
||||
|
||||
** release 0.7 [66%]
|
||||
** release 0.7 [81%]
|
||||
|
||||
- [X] signal handler for indexing
|
||||
- [X] fix max 10000 matches limit
|
||||
|
@ -13,7 +13,7 @@
|
|||
- [X] fix the batch stuff
|
||||
- [ ] mu view <path>
|
||||
- [X] basic test suite
|
||||
- [ ] auto clean log file
|
||||
- [X] auto clean log file
|
||||
- [X] configure error for missing ->dt_dtype
|
||||
|
||||
** release 0.8 [%]
|
||||
|
|
|
@ -27,7 +27,7 @@ AM_INIT_AUTOMAKE([dist-bzip2])
|
|||
# versioning, as we hopefully don't have updates for each version;
|
||||
# also, this has nothing to do with the version of the Xapian library
|
||||
#
|
||||
AC_DEFINE(MU_XAPIAN_DB_VERSION,["6.999"], [Schema version of the database])
|
||||
AC_DEFINE(MU_XAPIAN_DB_VERSION,["6.9999"], [Schema version of the database])
|
||||
|
||||
LT_INIT # don't use AC_PROG_LIBTOOL anymore
|
||||
|
||||
|
@ -66,7 +66,7 @@ AC_STRUCT_DIRENT_D_INO
|
|||
|
||||
|
||||
# glib2?
|
||||
PKG_CHECK_MODULES(GLIB,glib-2.0)
|
||||
PKG_CHECK_MODULES(GLIB, glib-2.0 gio-2.0)
|
||||
AC_SUBST(GLIB_CFLAGS)
|
||||
AC_SUBST(GLIB_LIBS)
|
||||
|
||||
|
|
30
man/mu.1
30
man/mu.1
|
@ -63,7 +63,8 @@ store and read its database and logs. By default, \fI~/.mu\fR is used.
|
|||
makes \fBmu\fR generate extra debug information,
|
||||
useful for debugging the program itself. By default, debug information goes to
|
||||
the log file, \fI~/.mu/mu.log\fR. It can safely be deleted when \fBmu\fR is
|
||||
not running. Note, with the debug option, the log file can grow rather quickly.
|
||||
not running. Note, with the debug option, the log file can grow rather
|
||||
quickly. See the note on logging below.
|
||||
|
||||
.TP
|
||||
\fB\-q\fR, \fB\-\-quiet\fR
|
||||
|
@ -485,19 +486,26 @@ If the creation somehow fails, for safety reasons, \fBno\fR attempt is made to
|
|||
remove any parts that were created.
|
||||
|
||||
.SH FILES
|
||||
By default, \fBmu index\fR stores its message database in
|
||||
\fI~/.mu/xapian-<version>\fR, where \fI<version>\fR is the version of the
|
||||
database layout, which is not necessarily the same as the \fBmu\fR version
|
||||
number.
|
||||
By default, \fBmu index\fR stores its message database in \fI~/.mu/xapian\fR;
|
||||
the database has an embedded version number, and \fBmu\fR will automatically
|
||||
update it when it notices a different version. This allows for automatic
|
||||
updating of \fBmu\fR-versions, without the need to clear out any old
|
||||
databases.
|
||||
|
||||
\fBmu\fR stores logs of its operations in \fI~/.mu/mu.log\fR. These can grow
|
||||
quite big when using the \fI\-\-debug\fR option, but they can be safely
|
||||
delete when \fBmu\fR is not running.
|
||||
However, note that versions of \fBmu\fR before 0.7 used a different scheme,
|
||||
which put the database in \fI~/.mu/xapian\-<version>\fR. These older databases
|
||||
can safely be deleted. Starting from version 0.7, this manual cleanup should
|
||||
no longer be needed.
|
||||
|
||||
To store various \fBmu\fR-files elsewhere from their default location, one can
|
||||
use the \fI\-\-muhome\fR option, as discussed in the \fBGENERAL OPTIONS\fR
|
||||
section.
|
||||
By default, \fBmu\fR stores logs of its operations and queries in \fI~/.mu/mu.log\fR.
|
||||
Upon startup, \fBmu\fR checks the size of this log file. If it exceeds 1 MB,
|
||||
it will be moved to \fI~/.mu/mu.log.old\fR, overwriting any existing file of
|
||||
that name, and start with an empty \fI~/.mu/mu.log\fR. This scheme allows for
|
||||
continued use of \fBmu\fR without the need for any manual maintenance of log
|
||||
files.
|
||||
|
||||
To store these files elsewhere from their default location, one can use the
|
||||
\fI\-\-muhome\fR option, as discussed in the \fBGENERAL OPTIONS\fR section.
|
||||
|
||||
.SH ENVIRONMENT
|
||||
|
||||
|
|
63
src/mu-log.c
63
src/mu-log.c
|
@ -27,6 +27,7 @@
|
|||
#include <time.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <gio/gio.h>
|
||||
|
||||
#include "mu-log.h"
|
||||
#include "mu-util.h"
|
||||
|
@ -113,9 +114,58 @@ mu_log_init_with_fd (int fd, gboolean doclose,
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
log_file_backup_maybe (const char *logfile)
|
||||
{
|
||||
struct stat statbuf;
|
||||
|
||||
if (stat (logfile, &statbuf) != 0) {
|
||||
if (errno == ENOENT)
|
||||
return TRUE; /* it did not exist yet, no problem */
|
||||
else {
|
||||
g_warning ("Failed to stat(2) %s", logfile);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/* log file is still below the max size? */
|
||||
if (statbuf.st_size <= MU_MAX_LOG_FILE_SIZE)
|
||||
return TRUE;
|
||||
|
||||
/* log file is too big!; we move it to <logfile>.old, overwriting */
|
||||
{
|
||||
GFile *src, *dst;
|
||||
gchar *tmp;
|
||||
GError *err;
|
||||
gboolean rv;
|
||||
|
||||
src = g_file_new_for_path (logfile);
|
||||
tmp = g_strdup_printf ("%s.old", logfile);
|
||||
dst = g_file_new_for_path (tmp);
|
||||
g_free (tmp);
|
||||
|
||||
err = NULL;
|
||||
rv = g_file_move (src, dst, G_FILE_COPY_OVERWRITE, NULL, NULL, NULL, &err);
|
||||
|
||||
if (!rv) {
|
||||
g_warning ("Failed to move %s to %s.old: %s", logfile, logfile,
|
||||
err ? err->message : "?");
|
||||
if (err)
|
||||
g_error_free (err);
|
||||
}
|
||||
|
||||
g_object_unref (G_OBJECT(src));
|
||||
g_object_unref (G_OBJECT(dst));
|
||||
|
||||
return rv;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
gboolean
|
||||
mu_log_init (const char* muhome, gboolean append,
|
||||
gboolean quiet, gboolean debug)
|
||||
mu_log_init (const char* muhome,
|
||||
gboolean backup, gboolean quiet, gboolean debug)
|
||||
{
|
||||
int fd;
|
||||
gchar *logfile;
|
||||
|
@ -131,8 +181,13 @@ mu_log_init (const char* muhome, gboolean append,
|
|||
|
||||
logfile = g_strdup_printf ("%s%c%s", muhome,
|
||||
G_DIR_SEPARATOR, MU_LOG_FILE);
|
||||
fd = open (logfile, O_WRONLY|O_CREAT|(append ? O_APPEND : O_TRUNC),
|
||||
00600);
|
||||
|
||||
if (backup && !log_file_backup_maybe(logfile)) {
|
||||
g_warning ("Failed to backup log file");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
fd = open (logfile, O_WRONLY|O_CREAT|O_APPEND, 00600);
|
||||
if (fd < 0)
|
||||
g_warning ("%s: open() of '%s' failed: %s\n", __FUNCTION__,
|
||||
logfile, strerror(errno));
|
||||
|
|
|
@ -26,17 +26,21 @@
|
|||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define MU_MAX_LOG_FILE_SIZE 1000 * 1000 /* 1 MB (SI units) */
|
||||
|
||||
/**
|
||||
* write logging information to a log file
|
||||
*
|
||||
* @param muhome the mu home directory
|
||||
* @param append append to logfile, instead of overwriting
|
||||
* @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* muhome, gboolean append,
|
||||
gboolean mu_log_init (const char* muhome, gboolean backup,
|
||||
gboolean quiet, gboolean debug);
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue