]>
Commit | Line | Data |
---|---|---|
03467c88 | 1 | /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ |
5899f3b7 | 2 | |
c2f1db8f | 3 | #pragma once |
5899f3b7 | 4 | |
a7334b09 LP |
5 | /*** |
6 | This file is part of systemd. | |
7 | ||
8 | Copyright 2010 Lennart Poettering | |
9 | ||
10 | systemd is free software; you can redistribute it and/or modify it | |
5430f7f2 LP |
11 | under the terms of the GNU Lesser General Public License as published by |
12 | the Free Software Foundation; either version 2.1 of the License, or | |
a7334b09 LP |
13 | (at your option) any later version. |
14 | ||
15 | systemd is distributed in the hope that it will be useful, but | |
16 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
5430f7f2 | 18 | Lesser General Public License for more details. |
a7334b09 | 19 | |
5430f7f2 | 20 | You should have received a copy of the GNU Lesser General Public License |
a7334b09 LP |
21 | along with systemd; If not, see <http://www.gnu.org/licenses/>. |
22 | ***/ | |
23 | ||
5899f3b7 | 24 | #include <syslog.h> |
bbe63281 | 25 | #include <stdbool.h> |
17a94911 | 26 | #include <stdarg.h> |
0d0f0c50 | 27 | #include <errno.h> |
5899f3b7 LP |
28 | |
29 | #include "macro.h" | |
20ad4cfd | 30 | #include "sd-id128.h" |
5899f3b7 | 31 | |
16801e90 LP |
32 | typedef enum LogTarget{ |
33 | LOG_TARGET_CONSOLE, | |
16801e90 | 34 | LOG_TARGET_KMSG, |
5ba081b0 LP |
35 | LOG_TARGET_JOURNAL, |
36 | LOG_TARGET_JOURNAL_OR_KMSG, | |
843d2643 LP |
37 | LOG_TARGET_SYSLOG, |
38 | LOG_TARGET_SYSLOG_OR_KMSG, | |
5ba081b0 | 39 | LOG_TARGET_AUTO, /* console if stderr is tty, JOURNAL_OR_KMSG otherwise */ |
a6903061 | 40 | LOG_TARGET_SAFE, /* console if stderr is tty, KMSG otherwise */ |
9fae33d2 | 41 | LOG_TARGET_NULL, |
16801e90 LP |
42 | _LOG_TARGET_MAX, |
43 | _LOG_TARGET_INVALID = -1 | |
44 | } LogTarget; | |
45 | ||
46 | void log_set_target(LogTarget target); | |
47 | void log_set_max_level(int level); | |
3eff4208 | 48 | void log_set_facility(int facility); |
16801e90 | 49 | |
34f0e866 LP |
50 | int log_set_target_from_string(const char *e); |
51 | int log_set_max_level_from_string(const char *e); | |
52 | ||
bbe63281 LP |
53 | void log_show_color(bool b); |
54 | void log_show_location(bool b); | |
55 | ||
56 | int log_show_color_from_string(const char *e); | |
57 | int log_show_location_from_string(const char *e); | |
58 | ||
44a6b1b6 ZJS |
59 | LogTarget log_get_target(void) _pure_; |
60 | int log_get_max_level(void) _pure_; | |
1adf1049 | 61 | |
843d2643 | 62 | int log_open(void); |
871e5809 | 63 | void log_close(void); |
4d8a7798 | 64 | void log_forget_fds(void); |
843d2643 | 65 | |
16801e90 | 66 | void log_close_syslog(void); |
5ba081b0 | 67 | void log_close_journal(void); |
843d2643 LP |
68 | void log_close_kmsg(void); |
69 | void log_close_console(void); | |
16801e90 | 70 | |
34f0e866 LP |
71 | void log_parse_environment(void); |
72 | ||
843d2643 | 73 | int log_meta( |
877d54e9 LP |
74 | int level, |
75 | const char*file, | |
76 | int line, | |
77 | const char *func, | |
78 | const char *format, ...) _printf_attr_(5,6); | |
5899f3b7 | 79 | |
17a94911 | 80 | int log_metav( |
877d54e9 LP |
81 | int level, |
82 | const char*file, | |
83 | int line, | |
84 | const char *func, | |
85 | const char *format, | |
b1e2b33c | 86 | va_list ap) _printf_attr_(5,0); |
877d54e9 | 87 | |
fdf9f9bb ZJS |
88 | int log_meta_object( |
89 | int level, | |
90 | const char*file, | |
91 | int line, | |
92 | const char *func, | |
93 | const char *object_name, | |
94 | const char *object, | |
95 | const char *format, ...) _printf_attr_(7,8); | |
96 | ||
97 | int log_metav_object( | |
98 | int level, | |
99 | const char*file, | |
100 | int line, | |
101 | const char *func, | |
102 | const char *object_name, | |
103 | const char *object, | |
104 | const char *format, | |
b1e2b33c | 105 | va_list ap) _printf_attr_(7,0); |
fdf9f9bb | 106 | |
877d54e9 LP |
107 | int log_struct_internal( |
108 | int level, | |
109 | const char *file, | |
110 | int line, | |
111 | const char *func, | |
b1e2b33c | 112 | const char *format, ...) _printf_attr_(5,0) _sentinel_; |
877d54e9 LP |
113 | |
114 | int log_oom_internal( | |
115 | const char *file, | |
116 | int line, | |
117 | const char *func); | |
185986c6 | 118 | |
2149e37c LP |
119 | /* This modifies the buffer passed! */ |
120 | int log_dump_internal( | |
877d54e9 LP |
121 | int level, |
122 | const char*file, | |
123 | int line, | |
124 | const char *func, | |
125 | char *buffer); | |
126 | ||
127 | _noreturn_ void log_assert_failed( | |
128 | const char *text, | |
129 | const char *file, | |
130 | int line, | |
131 | const char *func); | |
132 | ||
133 | _noreturn_ void log_assert_failed_unreachable( | |
134 | const char *text, | |
135 | const char *file, | |
136 | int line, | |
137 | const char *func); | |
2149e37c | 138 | |
b070e7f3 | 139 | #define log_full(level, ...) log_meta(level, __FILE__, __LINE__, __func__, __VA_ARGS__) |
92abbefb | 140 | |
5899f3b7 LP |
141 | #define log_debug(...) log_meta(LOG_DEBUG, __FILE__, __LINE__, __func__, __VA_ARGS__) |
142 | #define log_info(...) log_meta(LOG_INFO, __FILE__, __LINE__, __func__, __VA_ARGS__) | |
143 | #define log_notice(...) log_meta(LOG_NOTICE, __FILE__, __LINE__, __func__, __VA_ARGS__) | |
144 | #define log_warning(...) log_meta(LOG_WARNING, __FILE__, __LINE__, __func__, __VA_ARGS__) | |
145 | #define log_error(...) log_meta(LOG_ERR, __FILE__, __LINE__, __func__, __VA_ARGS__) | |
146 | ||
877d54e9 LP |
147 | #define log_struct(level, ...) log_struct_internal(level, __FILE__, __LINE__, __func__, __VA_ARGS__) |
148 | ||
149 | #define log_oom() log_oom_internal(__FILE__, __LINE__, __func__) | |
0d0f0c50 | 150 | |
2149e37c LP |
151 | /* This modifies the buffer passed! */ |
152 | #define log_dump(level, buffer) log_dump_internal(level, __FILE__, __LINE__, __func__, buffer) | |
153 | ||
44a6b1b6 | 154 | bool log_on_console(void) _pure_; |
81270860 | 155 | |
44a6b1b6 ZJS |
156 | const char *log_target_to_string(LogTarget target) _const_; |
157 | LogTarget log_target_from_string(const char *s) _pure_; | |
706911fb LP |
158 | |
159 | #define MESSAGE_ID(x) "MESSAGE_ID=" SD_ID128_FORMAT_STR, SD_ID128_FORMAT_VAL(x) |