]> git.ipfire.org Git - thirdparty/systemd.git/blame_incremental - src/shared/log.h
_noreturn_ --> noreturn for C11 compat
[thirdparty/systemd.git] / src / shared / log.h
... / ...
CommitLineData
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
32typedef 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
46void log_set_target(LogTarget target);
47void log_set_max_level(int level);
48void log_set_facility(int facility);
49
50int log_set_target_from_string(const char *e);
51int log_set_max_level_from_string(const char *e);
52
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
59LogTarget log_get_target(void) _pure_;
60int log_get_max_level(void) _pure_;
61
62int log_open(void);
63void log_close(void);
64void log_forget_fds(void);
65
66void log_close_syslog(void);
67void log_close_journal(void);
68void log_close_kmsg(void);
69void log_close_console(void);
70
71void log_parse_environment(void);
72
73int log_meta(
74 int level,
75 const char*file,
76 int line,
77 const char *func,
78 const char *format, ...) _printf_(5,6);
79
80int 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_(5,0);
87
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,
95 const char *format, ...) _printf_(7,8);
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,
105 va_list ap) _printf_(7,0);
106
107int log_struct_internal(
108 int level,
109 const char *file,
110 int line,
111 const char *func,
112 const char *format, ...) _printf_(5,0) _sentinel_;
113
114int log_oom_internal(
115 const char *file,
116 int line,
117 const char *func);
118
119/* This modifies the buffer passed! */
120int log_dump_internal(
121 int level,
122 const char*file,
123 int line,
124 const char *func,
125 char *buffer);
126
127noreturn void log_assert_failed(
128 const char *text,
129 const char *file,
130 int line,
131 const char *func);
132
133noreturn void log_assert_failed_unreachable(
134 const char *text,
135 const char *file,
136 int line,
137 const char *func);
138
139void log_assert_failed_return(
140 const char *text,
141 const char *file,
142 int line,
143 const char *func);
144
145#define log_full(level, ...) \
146do { \
147 if (log_get_max_level() >= (level)) \
148 log_meta((level), __FILE__, __LINE__, __func__, __VA_ARGS__); \
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__)
156
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__)
160
161/* This modifies the buffer passed! */
162#define log_dump(level, buffer) log_dump_internal(level, __FILE__, __LINE__, __func__, buffer)
163
164bool log_on_console(void) _pure_;
165
166const char *log_target_to_string(LogTarget target) _const_;
167LogTarget log_target_from_string(const char *s) _pure_;
168
169#define MESSAGE_ID(x) "MESSAGE_ID=" SD_ID128_FORMAT_STR, SD_ID128_FORMAT_VAL(x)