]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/shared/log.h
core: add new "scope" unit type for making a unit of pre-existing processes
[thirdparty/systemd.git] / src / shared / log.h
1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
3 #pragma once
4
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
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
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
18 Lesser General Public License for more details.
19
20 You should have received a copy of the GNU Lesser General Public License
21 along with systemd; If not, see <http://www.gnu.org/licenses/>.
22 ***/
23
24 #include <syslog.h>
25 #include <stdbool.h>
26 #include <stdarg.h>
27 #include <errno.h>
28
29 #include "macro.h"
30 #include "sd-id128.h"
31
32 typedef enum LogTarget{
33 LOG_TARGET_CONSOLE,
34 LOG_TARGET_KMSG,
35 LOG_TARGET_JOURNAL,
36 LOG_TARGET_JOURNAL_OR_KMSG,
37 LOG_TARGET_SYSLOG,
38 LOG_TARGET_SYSLOG_OR_KMSG,
39 LOG_TARGET_AUTO, /* console if stderr is tty, JOURNAL_OR_KMSG otherwise */
40 LOG_TARGET_SAFE, /* console if stderr is tty, KMSG otherwise */
41 LOG_TARGET_NULL,
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);
48 void log_set_facility(int facility);
49
50 int log_set_target_from_string(const char *e);
51 int log_set_max_level_from_string(const char *e);
52
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
59 LogTarget log_get_target(void) _pure_;
60 int log_get_max_level(void) _pure_;
61
62 int log_open(void);
63 void log_close(void);
64 void log_forget_fds(void);
65
66 void log_close_syslog(void);
67 void log_close_journal(void);
68 void log_close_kmsg(void);
69 void log_close_console(void);
70
71 void log_parse_environment(void);
72
73 int log_meta(
74 int level,
75 const char*file,
76 int line,
77 const char *func,
78 const char *format, ...) _printf_attr_(5,6);
79
80 int log_metav(
81 int level,
82 const char*file,
83 int line,
84 const char *func,
85 const char *format,
86 va_list ap) _printf_attr_(5,0);
87
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,
105 va_list ap) _printf_attr_(7,0);
106
107 int log_struct_internal(
108 int level,
109 const char *file,
110 int line,
111 const char *func,
112 const char *format, ...) _printf_attr_(5,0) _sentinel_;
113
114 int log_oom_internal(
115 const char *file,
116 int line,
117 const char *func);
118
119 /* This modifies the buffer passed! */
120 int log_dump_internal(
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);
138
139 #define log_full(level, ...) log_meta(level, __FILE__, __LINE__, __func__, __VA_ARGS__)
140
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
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__)
150
151 /* This modifies the buffer passed! */
152 #define log_dump(level, buffer) log_dump_internal(level, __FILE__, __LINE__, __func__, buffer)
153
154 bool log_on_console(void) _pure_;
155
156 const char *log_target_to_string(LogTarget target) _const_;
157 LogTarget log_target_from_string(const char *s) _pure_;
158
159 #define MESSAGE_ID(x) "MESSAGE_ID=" SD_ID128_FORMAT_STR, SD_ID128_FORMAT_VAL(x)