]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/shared/log.h
hwdb: Update database of Bluetooth company identifiers
[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
bbe63281 24#include <stdbool.h>
17a94911 25#include <stdarg.h>
4daf54a8
ZJS
26#include <syslog.h>
27#include <sys/signalfd.h>
0d0f0c50 28#include <errno.h>
5899f3b7
LP
29
30#include "macro.h"
20ad4cfd 31#include "sd-id128.h"
5899f3b7 32
16801e90
LP
33typedef enum LogTarget{
34 LOG_TARGET_CONSOLE,
16801e90 35 LOG_TARGET_KMSG,
5ba081b0
LP
36 LOG_TARGET_JOURNAL,
37 LOG_TARGET_JOURNAL_OR_KMSG,
843d2643
LP
38 LOG_TARGET_SYSLOG,
39 LOG_TARGET_SYSLOG_OR_KMSG,
5ba081b0 40 LOG_TARGET_AUTO, /* console if stderr is tty, JOURNAL_OR_KMSG otherwise */
a6903061 41 LOG_TARGET_SAFE, /* console if stderr is tty, KMSG otherwise */
9fae33d2 42 LOG_TARGET_NULL,
16801e90
LP
43 _LOG_TARGET_MAX,
44 _LOG_TARGET_INVALID = -1
45} LogTarget;
46
47void log_set_target(LogTarget target);
48void log_set_max_level(int level);
3eff4208 49void log_set_facility(int facility);
16801e90 50
34f0e866
LP
51int log_set_target_from_string(const char *e);
52int log_set_max_level_from_string(const char *e);
53
bbe63281 54void log_show_color(bool b);
b1e90ec5 55bool log_get_show_color(void) _pure_;
bbe63281 56void log_show_location(bool b);
b1e90ec5 57bool log_get_show_location(void) _pure_;
bbe63281
LP
58
59int log_show_color_from_string(const char *e);
60int log_show_location_from_string(const char *e);
61
44a6b1b6
ZJS
62LogTarget log_get_target(void) _pure_;
63int log_get_max_level(void) _pure_;
1adf1049 64
843d2643 65int log_open(void);
871e5809 66void log_close(void);
4d8a7798 67void log_forget_fds(void);
843d2643 68
16801e90 69void log_close_syslog(void);
5ba081b0 70void log_close_journal(void);
843d2643
LP
71void log_close_kmsg(void);
72void log_close_console(void);
16801e90 73
34f0e866
LP
74void log_parse_environment(void);
75
843d2643 76int log_meta(
877d54e9
LP
77 int level,
78 const char*file,
79 int line,
80 const char *func,
44b601bc 81 const char *format, ...) _printf_(5,6);
5899f3b7 82
17a94911 83int log_metav(
877d54e9
LP
84 int level,
85 const char*file,
86 int line,
87 const char *func,
88 const char *format,
44b601bc 89 va_list ap) _printf_(5,0);
877d54e9 90
fdf9f9bb
ZJS
91int log_meta_object(
92 int level,
93 const char*file,
94 int line,
95 const char *func,
96 const char *object_name,
97 const char *object,
44b601bc 98 const char *format, ...) _printf_(7,8);
fdf9f9bb
ZJS
99
100int log_metav_object(
101 int level,
102 const char*file,
103 int line,
104 const char *func,
105 const char *object_name,
106 const char *object,
107 const char *format,
44b601bc 108 va_list ap) _printf_(7,0);
fdf9f9bb 109
877d54e9
LP
110int log_struct_internal(
111 int level,
112 const char *file,
113 int line,
114 const char *func,
44b601bc 115 const char *format, ...) _printf_(5,0) _sentinel_;
877d54e9
LP
116
117int log_oom_internal(
118 const char *file,
119 int line,
120 const char *func);
185986c6 121
2149e37c
LP
122/* This modifies the buffer passed! */
123int log_dump_internal(
877d54e9
LP
124 int level,
125 const char*file,
126 int line,
127 const char *func,
128 char *buffer);
129
919ce0b7 130noreturn void log_assert_failed(
877d54e9
LP
131 const char *text,
132 const char *file,
133 int line,
134 const char *func);
135
919ce0b7 136noreturn void log_assert_failed_unreachable(
877d54e9
LP
137 const char *text,
138 const char *file,
139 int line,
140 const char *func);
80514f9c
LP
141
142void log_assert_failed_return(
143 const char *text,
144 const char *file,
145 int line,
146 const char *func);
2149e37c 147
87ff6b1c
KS
148#define log_full(level, ...) \
149do { \
150 if (log_get_max_level() >= (level)) \
f24e8653 151 log_meta((level), __FILE__, __LINE__, __func__, __VA_ARGS__); \
87ff6b1c
KS
152} while (0)
153
154#define log_debug(...) log_full(LOG_DEBUG, __VA_ARGS__)
155#define log_info(...) log_full(LOG_INFO, __VA_ARGS__)
156#define log_notice(...) log_full(LOG_NOTICE, __VA_ARGS__)
157#define log_warning(...) log_full(LOG_WARNING, __VA_ARGS__)
158#define log_error(...) log_full(LOG_ERR, __VA_ARGS__)
5899f3b7 159
877d54e9
LP
160#define log_struct(level, ...) log_struct_internal(level, __FILE__, __LINE__, __func__, __VA_ARGS__)
161
162#define log_oom() log_oom_internal(__FILE__, __LINE__, __func__)
0d0f0c50 163
2149e37c
LP
164/* This modifies the buffer passed! */
165#define log_dump(level, buffer) log_dump_internal(level, __FILE__, __LINE__, __func__, buffer)
166
44a6b1b6 167bool log_on_console(void) _pure_;
81270860 168
44a6b1b6
ZJS
169const char *log_target_to_string(LogTarget target) _const_;
170LogTarget log_target_from_string(const char *s) _pure_;
706911fb
LP
171
172#define MESSAGE_ID(x) "MESSAGE_ID=" SD_ID128_FORMAT_STR, SD_ID128_FORMAT_VAL(x)
4daf54a8
ZJS
173
174void log_received_signal(int level, const struct signalfd_siginfo *si);