comparison extensions/dbg_loglevel/dbg_loglevel.c @ 1345:51a0521cd065

dbg_loglevel: new extension that allows changing the log level at runtime
author Thomas Klausner <tk@giga.or.at>
date Sun, 12 May 2019 10:35:46 +0200
parents
children
comparison
equal deleted inserted replaced
1344:a5c072798f1a 1345:51a0521cd065
1 /*********************************************************************************************************
2 * Software License Agreement (BSD License) *
3 * Author: Thomas Klausner <tk@giga.or.at> *
4 * *
5 * Copyright (c) 2019, Thomas Klausner *
6 * All rights reserved. *
7 * *
8 * Written under contract by Effortel Technologies SA, http://effortel.com/ *
9 * *
10 * Redistribution and use of this software in source and binary forms, with or without modification, are *
11 * permitted provided that the following conditions are met: *
12 * *
13 * * Redistributions of source code must retain the above *
14 * copyright notice, this list of conditions and the *
15 * following disclaimer. *
16 * *
17 * * Redistributions in binary form must reproduce the above *
18 * copyright notice, this list of conditions and the *
19 * following disclaimer in the documentation and/or other *
20 * materials provided with the distribution. *
21 * *
22 * * Neither the name of the WIDE Project or NICT nor the *
23 * names of its contributors may be used to endorse or *
24 * promote products derived from this software without *
25 * specific prior written permission of WIDE Project and *
26 * NICT. *
27 * *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED *
29 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
30 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR *
31 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT *
32 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS *
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR *
34 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF *
35 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
36 *********************************************************************************************************/
37
38 #include <signal.h>
39
40 /* See doc/dbg_loglevel.conf.sample for more details about the features of this extension */
41 #include "dbg_loglevel.h"
42
43 static char *config_file = NULL;
44 #define MODULE_NAME "dbg_loglevel"
45
46 static void sig_hdlr(void)
47 {
48 int old_log_level;
49
50 old_log_level = fd_g_debug_lvl;
51 if (dbg_loglevel_conf_handle(config_file) != 0) {
52 fd_log_error("%s: error during config file reload, restoring previous value", MODULE_NAME);
53 fd_g_debug_lvl = old_log_level;
54 }
55 fd_log_notice("%s: reloaded configuration, log level now %d", MODULE_NAME, fd_g_debug_lvl);
56 }
57
58 /* entry point */
59 static int dbg_loglevel_entry(char * conffile)
60 {
61 TRACE_ENTRY("%p", conffile);
62
63 config_file = conffile;
64
65 /* default set by main program */
66 /* fd_g_debug_lvl = FD_LOG_NOTICE; */
67
68 /* Parse the configuration file */
69 CHECK_FCT(dbg_loglevel_conf_handle(config_file));
70
71 /* Register reload callback */
72 CHECK_FCT(fd_event_trig_regcb(SIGUSR1, MODULE_NAME, sig_hdlr));
73
74 fd_log_notice("Extension 'Loglevel' initialized with log level %d", fd_g_debug_lvl);
75
76 /* We're done */
77 return 0;
78 }
79
80 /* Unload */
81 void fd_ext_fini(void)
82 {
83 TRACE_ENTRY();
84
85 /* Nothing to do */
86 return ;
87 }
88
89 EXTENSION_ENTRY(MODULE_NAME, dbg_loglevel_entry);
"Welcome to our mercurial repository"