]>
Commit | Line | Data |
---|---|---|
f06095f1 MT |
1 | /*############################################################################# |
2 | # # | |
3 | # Pakfire - The IPFire package management system # | |
4 | # Copyright (C) 2017 Pakfire 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 PAKFIRE_LOGGING_H | |
22 | #define PAKFIRE_LOGGING_H | |
23 | ||
6641e780 | 24 | #include <stdarg.h> |
5ac0f067 | 25 | |
6641e780 MT |
26 | typedef void (*pakfire_log_callback)(void* data, int priority, const char* file, |
27 | int line, const char* fn, const char* format, va_list args); | |
28 | ||
72ec3762 | 29 | void pakfire_log_stderr(void* data, int priority, const char* file, |
c348901e | 30 | int line, const char* fn, const char* format, va_list args); |
72ec3762 | 31 | void pakfire_log_syslog(void* data, int priority, const char* file, |
c348901e MT |
32 | int line, const char* fn, const char* format, va_list args); |
33 | ||
f06095f1 MT |
34 | #ifdef PAKFIRE_PRIVATE |
35 | ||
b1a49fcc MT |
36 | #include <syslog.h> |
37 | ||
67550e47 | 38 | #include <pakfire/ctx.h> |
b1a49fcc | 39 | #include <pakfire/pakfire.h> |
67550e47 | 40 | |
05804c86 | 41 | #define pakfire_ctx_log_condition(ctx, level, arg...) \ |
67550e47 | 42 | do { \ |
05804c86 MT |
43 | if (pakfire_ctx_get_log_level(ctx) >= level) \ |
44 | pakfire_ctx_log(ctx, level, __FILE__, __LINE__, __FUNCTION__, ## arg); \ | |
67550e47 MT |
45 | } while (0) |
46 | ||
47 | // This function does absolutely nothing | |
48 | static inline void __attribute__((always_inline, format(printf, 2, 3))) | |
49 | pakfire_ctx_log_null(struct pakfire_ctx* ctx, const char *format, ...) {} | |
50 | ||
05804c86 MT |
51 | #define CTX_INFO(ctx, arg...) pakfire_ctx_log_condition(ctx, LOG_INFO, ## arg) |
52 | #define CTX_ERROR(ctx, arg...) pakfire_ctx_log_condition(ctx, LOG_ERR, ## arg) | |
67550e47 MT |
53 | |
54 | #ifdef ENABLE_DEBUG | |
05804c86 | 55 | # define CTX_DEBUG(ctx, arg...) pakfire_ctx_log_condition(ctx, LOG_DEBUG, ## arg) |
67550e47 MT |
56 | #else |
57 | # define CTX_DEBUG pakfire_ctx_log_null | |
58 | #endif | |
59 | ||
60 | // Below is the legacy logging mechanism | |
61 | ||
517708c8 MT |
62 | #ifdef PAKFIRE_LEGACY_LOGGING |
63 | ||
f06095f1 | 64 | // This function does absolutely nothing |
12656820 | 65 | static inline void __attribute__((always_inline, format(printf, 2, 3))) |
ac4c607b | 66 | pakfire_log_null(struct pakfire* pakfire, const char *format, ...) {} |
f06095f1 | 67 | |
13062e6c | 68 | #define pakfire_log_condition(pakfire, prio, r, arg...) \ |
79388676 | 69 | pakfire_log(pakfire, prio, r, __FILE__, __LINE__, __FUNCTION__, ## arg) |
f06095f1 | 70 | |
13062e6c MT |
71 | #define INFO(pakfire, arg...) pakfire_log_condition(pakfire, LOG_INFO, 0, ## arg) |
72 | #define ERROR(pakfire, arg...) pakfire_log_condition(pakfire, LOG_ERR, 0, ## arg) | |
73 | ||
74 | #define INFO_ERRNO(pakfire, r, arg...) pakfire_log_condition(pakfire, LOG_INFO, r, ## arg) | |
75 | #define ERROR_ERRNO(pakfire, r, arg...) pakfire_log_condition(pakfire, LOG_ERR, r, ## arg) | |
f06095f1 MT |
76 | |
77 | #ifdef ENABLE_DEBUG | |
13062e6c MT |
78 | # define DEBUG(pakfire, arg...) pakfire_log_condition(pakfire, LOG_DEBUG, 0, ## arg) |
79 | # define DEBUG_ERRNO(pakfire, r, arg...) pakfire_log_condition(pakfire, LOG_DEBUG, r, ## arg) | |
f06095f1 | 80 | #else |
5ac0f067 | 81 | # define DEBUG pakfire_log_null |
13062e6c | 82 | # define DEBUG_ERRNO pakfire_log_null |
f06095f1 MT |
83 | #endif |
84 | ||
517708c8 MT |
85 | #endif /* PAKFIRE_LEGACY_LOGGING */ |
86 | ||
f06095f1 MT |
87 | #endif /* PAKFIRE_PRIVATE */ |
88 | #endif /* PAKFIRE_LOGGING_H */ |