First bunch of mhl_mem_free removal patches
[midnight-commander.git] / src / logging.c
blob6dc80948a5d34d37ff5dba555e159f57b4cb9f3f
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/memory.h>
30 #include <mhl/types.h>
32 #include "global.h"
33 #include "logging.h"
34 #include "setup.h"
36 /*** file scope functions **********************************************/
38 static bool
39 is_logging_enabled(void)
41 static bool logging_initialized = FALSE;
42 static bool logging_enabled = FALSE;
43 char *mc_ini;
45 if (!logging_initialized) {
46 mc_ini = g_strdup_printf("%s/%s", home_dir, PROFILE_NAME);
47 logging_enabled =
48 get_int(mc_ini, "development.enable_logging", FALSE);
49 g_free(mc_ini);
50 logging_initialized = TRUE;
52 return logging_enabled;
55 /*** public functions **************************************************/
57 void
58 mc_log(const char *fmt, ...)
60 va_list args;
61 FILE *f;
62 char *logfilename;
64 if (is_logging_enabled()) {
65 va_start(args, fmt);
66 logfilename = g_strdup_printf("%s/.mc/log", home_dir);
67 if ((f = fopen(logfilename, "a")) != NULL) {
68 (void)vfprintf(f, fmt, args);
69 (void)fclose(f);
71 g_free(logfilename);