]> git.ipfire.org Git - people/ms/network.git/blame - src/libnetwork/network/logging.h
libnetwork: Add logging infrastructure
[people/ms/network.git] / src / libnetwork / network / logging.h
CommitLineData
6f4814db
MT
1/*#############################################################################
2# #
3# IPFire.org - A linux based firewall #
4# Copyright (C) 2018 IPFire Network Development Team #
5# #
6# This program is free software: you can redistribute it and/or modify #
7# it under the terms of the GNU General Public License as published by #
8# the Free Software Foundation, either version 3 of the License, or #
9# (at your option) any later version. #
10# #
11# This program is distributed in the hope that it will be useful, #
12# but WITHOUT ANY WARRANTY; without even the implied warranty of #
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
14# GNU General Public License for more details. #
15# #
16# You should have received a copy of the GNU General Public License #
17# along with this program. If not, see <http://www.gnu.org/licenses/>. #
18# #
19#############################################################################*/
20
21#ifndef NETWORK_LOGGING_H
22#define NETWORK_LOGGING_H
23
24#ifdef NETWORK_PRIVATE
25
26#include <stdlib.h>
27#include <syslog.h>
28
29static inline void __attribute__((always_inline, format(printf, 2, 3)))
30 network_log_null(struct network_ctx* ctx, const char* format, ...) {}
31
32#define network_log_cond(ctx, prio, arg...) \
33 do { \
34 if (network_get_log_priority(ctx) >= prio) \
35 network_log(ctx, prio, __FILE__, __LINE__, __FUNCTION__, ## arg); \
36 } while (0)
37
38#ifdef ENABLE_DEBUG
39# define DEBUG(ctx, arg...) network_log_cond(ctx, LOG_DEBUG, ## arg)
40#else
41# define DEBUG(ctx, arg...) network_log_null(ctx, ## arg)
42#endif
43
44#define INFO(ctx, arg...) network_log_cond(ctx, LOG_INFO, ## arg)
45#define ERROR(ctx, arg...) network_log_cond(ctx, LOG_ERR, ## arg)
46
47#ifndef HAVE_SECURE_GETENV
48# ifdef HAVE___SECURE_GETENV
49# define secure_getenv __secure_getenv
50# else
51# error neither secure_getenv nor __secure_getenv is available
52# endif
53#endif
54
55#endif
56
57#endif /* NETWORK_LOGGING_H */