Optimization of mcview_hexedit_save_changes() function.
[kaloumi3.git] / lib / logging.c
blobc9de5d3580d2fbf60f3bdbd3f9385a8213ae5feb
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 "lib/global.h"
36 #include "logging.h"
37 #include "lib/mcconfig.h"
38 #include "lib/fileloc.h"
40 #include "src/setup.h"
42 /*** file scope functions **********************************************/
44 static gboolean
45 is_logging_enabled(void)
47 static gboolean logging_initialized = FALSE;
48 static gboolean logging_enabled = FALSE;
50 if (!logging_initialized) {
51 logging_enabled = mc_config_get_int (mc_main_config,
52 CONFIG_APP_SECTION, "development.enable_logging", FALSE);
53 logging_initialized = TRUE;
55 return logging_enabled;
58 /*** public functions **************************************************/
60 void
61 mc_log(const char *fmt, ...)
63 va_list args;
64 FILE *f;
65 char *logfilename;
67 if (is_logging_enabled()) {
68 va_start(args, fmt);
69 logfilename = g_strdup_printf("%s/%s/log", home_dir, MC_USERCONF_DIR);
70 if ((f = fopen(logfilename, "a")) != NULL) {
71 (void)vfprintf(f, fmt, args);
72 (void)fclose(f);
74 g_free(logfilename);
75 va_end(args);