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>
31 static int log_level = LOG_DEBUG;
33 static const char *config_keys[] =
37 static int config_keys_num = STATIC_ARRAY_SIZE(config_keys);
39 static int sl_config (const char *key, const char *value)
41 if (strcasecmp (key, "LogLevel") == 0)
43 if ((strcasecmp (value, "emerg") == 0)
44 || (strcasecmp (value, "alert") == 0)
45 || (strcasecmp (value, "crit") == 0)
46 || (strcasecmp (value, "err") == 0))
48 else if (strcasecmp (value, "warning") == 0)
49 log_level = LOG_WARNING;
50 else if (strcasecmp (value, "notice") == 0)
51 log_level = LOG_NOTICE;
52 else if (strcasecmp (value, "info") == 0)
55 else if (strcasecmp (value, "debug") == 0)
56 log_level = LOG_DEBUG;
67 static int sl_init (void)
69 openlog ("collectd", LOG_CONS | LOG_PID, LOG_DAEMON);
74 static void sl_log (int severity, const char *msg)
76 if (severity > log_level)
79 syslog (severity, "%s", msg);
82 static int sl_shutdown (void)
89 void module_register (modreg_e load)
91 plugin_register_config ("syslog", sl_config, config_keys, config_keys_num);
92 plugin_register_init ("syslog", sl_init);
93 plugin_register_log ("syslog", sl_log);
94 plugin_register_shutdown ("syslog", sl_shutdown);
95 } /* void module_register(void) */