2 * collectd - src/syslog.c
3 * Copyright (C) 2007 Florian Forster
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 * Florian Forster <octo at verplant.org>
32 static int log_level = LOG_DEBUG;
34 static int log_level = LOG_INFO;
35 #endif /* COLLECT_DEBUG */
37 static const char *config_keys[] =
41 static int config_keys_num = STATIC_ARRAY_SIZE(config_keys);
43 static int sl_config (const char *key, const char *value)
45 if (strcasecmp (key, "LogLevel") == 0)
47 if ((strcasecmp (value, "emerg") == 0)
48 || (strcasecmp (value, "alert") == 0)
49 || (strcasecmp (value, "crit") == 0)
50 || (strcasecmp (value, "err") == 0))
52 else if (strcasecmp (value, "warning") == 0)
53 log_level = LOG_WARNING;
54 else if (strcasecmp (value, "notice") == 0)
55 log_level = LOG_NOTICE;
56 else if (strcasecmp (value, "info") == 0)
59 else if (strcasecmp (value, "debug") == 0)
60 log_level = LOG_DEBUG;
71 static void sl_log (int severity, const char *msg)
73 if (severity > log_level)
76 syslog (severity, "%s", msg);
79 static int sl_shutdown (void)
86 void module_register (void)
88 openlog ("collectd", LOG_CONS | LOG_PID, LOG_DAEMON);
90 plugin_register_config ("syslog", sl_config, config_keys, config_keys_num);
91 plugin_register_log ("syslog", sl_log);
92 plugin_register_shutdown ("syslog", sl_shutdown);
93 } /* void module_register(void) */