Fixed incorrect showing name of search library in summary screen
[midnight-commander.git] / src / logging.c
blobf8ed3de41c4bc9505d0a1e5d18e8e5e7acf7de25
1 /*
2 Provides a log file to ease tracing the program.
4 Copyright (C) 2006, 2009 Free Software Foundation, Inc.
6 Written: 2006 Roland Illig <roland.illig@gmx.de>.
8 This file is part of the Midnight Commander.
10 The Midnight Commander is free software; you can redistribute it
11 and/or modify it under the terms of the GNU General Public License as
12 published by the Free Software Foundation; either version 2 of the
13 License, or (at your option) any later version.
15 The Midnight Commander is distributed in the hope that it will be
16 useful, but WITHOUT ANY WARRANTY; without even the implied warranty
17 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
23 MA 02110-1301, USA.
26 /** \file logging.c
27 * \brief Source: provides a log file to ease tracing the program
30 #include <config.h>
32 #include <stdarg.h>
33 #include <stdio.h>
35 #include "global.h"
36 #include "logging.h"
37 #include "setup.h"
38 #include "../src/mcconfig/mcconfig.h"
39 #include "fileloc.h"
41 /*** file scope functions **********************************************/
43 static gboolean
44 is_logging_enabled(void)
46 static gboolean logging_initialized = FALSE;
47 static gboolean logging_enabled = FALSE;
49 if (!logging_initialized) {
50 logging_enabled = mc_config_get_int (mc_main_config,
51 CONFIG_APP_SECTION, "development.enable_logging", FALSE);
52 logging_initialized = TRUE;
54 return logging_enabled;
57 /*** public functions **************************************************/
59 void
60 mc_log(const char *fmt, ...)
62 va_list args;
63 FILE *f;
64 char *logfilename;
66 if (is_logging_enabled()) {
67 va_start(args, fmt);
68 logfilename = g_strdup_printf("%s/%s/log", home_dir, MC_USERCONF_DIR);
69 if ((f = fopen(logfilename, "a")) != NULL) {
70 (void)vfprintf(f, fmt, args);
71 (void)fclose(f);
73 g_free(logfilename);
74 va_end(args);