]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/shared/log.h
_noreturn_ --> noreturn for C11 compat
[thirdparty/systemd.git] / src / shared / log.h
CommitLineData
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
32typedef 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
46void log_set_target(LogTarget target);
47void log_set_max_level(int level);
3eff4208 48void log_set_facility(int facility);
16801e90 49
34f0e866
LP
50int log_set_target_from_string(const char *e);
51int log_set_max_level_from_string(const char *e);
52
bbe63281
LP
53void log_show_color(bool b);
54void log_show_location(bool b);
55
56int log_show_color_from_string(const char *e);
57int log_show_location_from_string(const char *e);
58
44a6b1b6
ZJS
59LogTarget log_get_target(void) _pure_;
60int log_get_max_level(void) _pure_;
1adf1049 61
843d2643 62int log_open(void);
871e5809 63void log_close(void);
4d8a7798 64void log_forget_fds(void);
843d2643 65
16801e90 66void log_close_syslog(void);
5ba081b0 67void log_close_journal(void);
843d2643
LP
68void log_close_kmsg(void);
69void log_close_console(void);
16801e90 70
34f0e866
LP
71void log_parse_environment(void);
72
843d2643 73int log_meta(
877d54e9
LP
74 int level,
75 const char*file,
76 int line,
77 const char *func,
44b601bc 78 const char *format, ...) _printf_(5,6);
5899f3b7 79
17a94911 80int log_metav(
877d54e9
LP
81 int level,
82 const char*file,
83 int line,
84 const char *func,
85 const char *format,
44b601bc 86 va_list ap) _printf_(5,0);
877d54e9 87
fdf9f9bb
ZJS
88int 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,
44b601bc 95 const char *format, ...) _printf_(7,8);
fdf9f9bb
ZJS
96
97int 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,
44b601bc 105 va_list ap) _printf_(7,0);
fdf9f9bb 106
877d54e9
LP
107int log_struct_internal(
108 int level,
109 const char *file,
110 int line,
111 const char *func,
44b601bc 112 const char *format, ...) _printf_(5,0) _sentinel_;
877d54e9
LP
113
114int log_oom_internal(
115 const char *file,
116 int line,
117 const char *func);
185986c6 118
2149e37c
LP
119/* This modifies the buffer passed! */
120int log_dump_internal(
877d54e9
LP
121 int level,
122 const char*file,
123 int line,
124 const char *func,
125 char *buffer);
126
919ce0b7 127noreturn void log_assert_failed(
877d54e9
LP
128 const char *text,
129 const char *file,
130 int line,
131 const char *func);
132
919ce0b7 133noreturn void log_assert_failed_unreachable(
877d54e9
LP
134 const char *text,
135 const char *file,
136 int line,
137 const char *func);
80514f9c
LP
138
139void log_assert_failed_return(
140 const char *text,
141 const char *file,
142 int line,
143 const char *func);
2149e37c 144
87ff6b1c
KS
145#define log_full(level, ...) \
146do { \
147 if (log_get_max_level() >= (level)) \
f24e8653 148 log_meta((level), __FILE__, __LINE__, __func__, __VA_ARGS__); \
87ff6b1c
KS
149} while (0)
150
151#define log_debug(...) log_full(LOG_DEBUG, __VA_ARGS__)
152#define log_info(...) log_full(LOG_INFO, __VA_ARGS__)
153#define log_notice(...) log_full(LOG_NOTICE, __VA_ARGS__)
154#define log_warning(...) log_full(LOG_WARNING, __VA_ARGS__)
155#define log_error(...) log_full(LOG_ERR, __VA_ARGS__)
5899f3b7 156
877d54e9
LP
157#define log_struct(level, ...) log_struct_internal(level, __FILE__, __LINE__, __func__, __VA_ARGS__)
158
159#define log_oom() log_oom_internal(__FILE__, __LINE__, __func__)
0d0f0c50 160
2149e37c
LP
161/* This modifies the buffer passed! */
162#define log_dump(level, buffer) log_dump_internal(level, __FILE__, __LINE__, __func__, buffer)
163
44a6b1b6 164bool log_on_console(void) _pure_;
81270860 165
44a6b1b6
ZJS
166const char *log_target_to_string(LogTarget target) _const_;
167LogTarget log_target_from_string(const char *s) _pure_;
706911fb
LP
168
169#define MESSAGE_ID(x) "MESSAGE_ID=" SD_ID128_FORMAT_STR, SD_ID128_FORMAT_VAL(x)