2006-01-28 02:48:49 +03:00
|
|
|
/*
|
|
|
|
Provides a log file to ease tracing the program.
|
|
|
|
|
2009-05-20 16:34:33 +04:00
|
|
|
Copyright (C) 2006, 2009 Free Software Foundation, Inc.
|
|
|
|
|
|
|
|
Written: 2006 Roland Illig <roland.illig@gmx.de>.
|
2006-01-28 02:48:49 +03:00
|
|
|
|
|
|
|
This file is part of the Midnight Commander.
|
|
|
|
|
|
|
|
The Midnight Commander 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.
|
|
|
|
|
|
|
|
The Midnight Commander 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.
|
|
|
|
*/
|
|
|
|
|
2009-02-05 21:28:18 +03:00
|
|
|
/** \file logging.c
|
|
|
|
* \brief Source: provides a log file to ease tracing the program
|
|
|
|
*/
|
|
|
|
|
2006-01-28 02:48:49 +03:00
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2010-01-20 18:11:52 +03:00
|
|
|
#include "lib/global.h"
|
2006-01-28 02:48:49 +03:00
|
|
|
#include "logging.h"
|
2010-01-21 16:06:15 +03:00
|
|
|
#include "lib/mcconfig.h"
|
2010-01-21 13:30:08 +03:00
|
|
|
#include "lib/fileloc.h"
|
2006-01-28 02:48:49 +03:00
|
|
|
|
2010-01-21 16:48:43 +03:00
|
|
|
#include "src/setup.h"
|
|
|
|
|
2006-01-28 02:48:49 +03:00
|
|
|
/*** file scope functions **********************************************/
|
|
|
|
|
2009-02-06 01:46:07 +03:00
|
|
|
static gboolean
|
2006-01-28 03:23:55 +03:00
|
|
|
is_logging_enabled(void)
|
2006-01-28 02:48:49 +03:00
|
|
|
{
|
2009-02-06 01:46:07 +03:00
|
|
|
static gboolean logging_initialized = FALSE;
|
|
|
|
static gboolean logging_enabled = FALSE;
|
2006-01-28 02:48:49 +03:00
|
|
|
|
2006-01-28 03:23:55 +03:00
|
|
|
if (!logging_initialized) {
|
2009-05-20 16:34:33 +04:00
|
|
|
logging_enabled = mc_config_get_int (mc_main_config,
|
|
|
|
CONFIG_APP_SECTION, "development.enable_logging", FALSE);
|
2006-01-28 03:23:55 +03:00
|
|
|
logging_initialized = TRUE;
|
|
|
|
}
|
|
|
|
return logging_enabled;
|
2006-01-28 02:48:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*** public functions **************************************************/
|
|
|
|
|
|
|
|
void
|
|
|
|
mc_log(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
FILE *f;
|
|
|
|
char *logfilename;
|
|
|
|
|
2006-01-28 03:23:55 +03:00
|
|
|
if (is_logging_enabled()) {
|
2006-01-28 02:48:49 +03:00
|
|
|
va_start(args, fmt);
|
2009-10-05 18:32:46 +04:00
|
|
|
logfilename = g_strdup_printf("%s/%s/log", home_dir, MC_USERCONF_DIR);
|
2006-01-28 02:48:49 +03:00
|
|
|
if ((f = fopen(logfilename, "a")) != NULL) {
|
|
|
|
(void)vfprintf(f, fmt, args);
|
|
|
|
(void)fclose(f);
|
|
|
|
}
|
2009-02-06 01:27:37 +03:00
|
|
|
g_free(logfilename);
|
2009-12-07 12:17:34 +03:00
|
|
|
va_end(args);
|
2006-01-28 02:48:49 +03:00
|
|
|
}
|
|
|
|
}
|