replaced gboolean by bool (from mhl/types.h)
[midnight-commander.git] / src / logging.c
blob9fa8605e97ec839244e3f5a7afa6a2e46f07ccd7
1 /*
2 Provides a log file to ease tracing the program.
4 Copyright (C) 2006 Roland Illig <roland.illig@gmx.de>.
6 This file is part of the Midnight Commander.
8 The Midnight Commander is free software; you can redistribute it
9 and/or modify it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2 of the
11 License, or (at your option) any later version.
13 The Midnight Commander is distributed in the hope that it will be
14 useful, but WITHOUT ANY WARRANTY; without even the implied warranty
15 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21 MA 02110-1301, USA.
24 #include <config.h>
26 #include <stdarg.h>
27 #include <stdio.h>
29 #include <mhl/types.h>
31 #include "global.h"
32 #include "logging.h"
33 #include "setup.h"
35 /*** file scope functions **********************************************/
37 static bool
38 is_logging_enabled(void)
40 static bool logging_initialized = FALSE;
41 static bool logging_enabled = FALSE;
42 char *mc_ini;
44 if (!logging_initialized) {
45 mc_ini = g_strdup_printf("%s/%s", home_dir, PROFILE_NAME);
46 logging_enabled =
47 get_int(mc_ini, "development.enable_logging", FALSE);
48 g_free(mc_ini);
49 logging_initialized = TRUE;
51 return logging_enabled;
54 /*** public functions **************************************************/
56 void
57 mc_log(const char *fmt, ...)
59 va_list args;
60 FILE *f;
61 char *logfilename;
63 if (is_logging_enabled()) {
64 va_start(args, fmt);
65 logfilename = g_strdup_printf("%s/.mc/log", home_dir);
66 if ((f = fopen(logfilename, "a")) != NULL) {
67 (void)vfprintf(f, fmt, args);
68 (void)fclose(f);
70 g_free(logfilename);