]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/shared/log.h
fstab-generator: modernize style
[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
1adf1049
LP
59LogTarget log_get_target(void);
60int log_get_max_level(void);
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,
78 const char *format, ...) _printf_attr_(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,
86 va_list ap);
87
88int log_struct_internal(
89 int level,
90 const char *file,
91 int line,
92 const char *func,
93 const char *format, ...) _sentinel_;
94
95int log_oom_internal(
96 const char *file,
97 int line,
98 const char *func);
185986c6 99
2149e37c
LP
100/* This modifies the buffer passed! */
101int log_dump_internal(
877d54e9
LP
102 int level,
103 const char*file,
104 int line,
105 const char *func,
106 char *buffer);
107
108_noreturn_ void log_assert_failed(
109 const char *text,
110 const char *file,
111 int line,
112 const char *func);
113
114_noreturn_ void log_assert_failed_unreachable(
115 const char *text,
116 const char *file,
117 int line,
118 const char *func);
2149e37c 119
b070e7f3 120#define log_full(level, ...) log_meta(level, __FILE__, __LINE__, __func__, __VA_ARGS__)
92abbefb 121
5899f3b7
LP
122#define log_debug(...) log_meta(LOG_DEBUG, __FILE__, __LINE__, __func__, __VA_ARGS__)
123#define log_info(...) log_meta(LOG_INFO, __FILE__, __LINE__, __func__, __VA_ARGS__)
124#define log_notice(...) log_meta(LOG_NOTICE, __FILE__, __LINE__, __func__, __VA_ARGS__)
125#define log_warning(...) log_meta(LOG_WARNING, __FILE__, __LINE__, __func__, __VA_ARGS__)
126#define log_error(...) log_meta(LOG_ERR, __FILE__, __LINE__, __func__, __VA_ARGS__)
127
877d54e9
LP
128#define log_struct(level, ...) log_struct_internal(level, __FILE__, __LINE__, __func__, __VA_ARGS__)
129
130#define log_oom() log_oom_internal(__FILE__, __LINE__, __func__)
0d0f0c50 131
2149e37c
LP
132/* This modifies the buffer passed! */
133#define log_dump(level, buffer) log_dump_internal(level, __FILE__, __LINE__, __func__, buffer)
134
81270860
LP
135bool log_on_console(void);
136
34f0e866
LP
137const char *log_target_to_string(LogTarget target);
138LogTarget log_target_from_string(const char *s);
706911fb
LP
139
140#define MESSAGE_ID(x) "MESSAGE_ID=" SD_ID128_FORMAT_STR, SD_ID128_FORMAT_VAL(x)