blob: 7a594f12535e68e5d63c4d0bb9532d69919b212f [file] [log] [blame]
The Android Open Source Project1dc9e472009-03-03 19:28:35 -08001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in
12 * the documentation and/or other materials provided with the
13 * distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
18 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
19 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
22 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 */
Elliott Hughesafb8e052023-10-23 17:45:13 -070028/*
29 * Copyright (c) 1982, 1986, 1988, 1993
30 * The Regents of the University of California. All rights reserved.
31 *
32 * Redistribution and use in source and binary forms, with or without
33 * modification, are permitted provided that the following conditions
34 * are met:
35 * 1. Redistributions of source code must retain the above copyright
36 * notice, this list of conditions and the following disclaimer.
37 * 2. Redistributions in binary form must reproduce the above copyright
38 * notice, this list of conditions and the following disclaimer in the
39 * documentation and/or other materials provided with the distribution.
40 * 3. Neither the name of the University nor the names of its contributors
41 * may be used to endorse or promote products derived from this software
42 * without specific prior written permission.
43 *
44 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
45 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
46 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
47 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
48 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
49 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
50 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
51 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
52 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
53 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
54 * SUCH DAMAGE.
55 */
Elliott Hughesa382a792014-06-09 17:16:19 -070056
Elliott Hughes462e90c2018-08-21 16:10:48 -070057#pragma once
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080058
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080059#include <sys/cdefs.h>
Elliott Hughes414dd2d2024-10-16 14:48:30 +000060
61#include <stdio.h>
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080062#include <stdarg.h>
63
64__BEGIN_DECLS
65
Elliott Hughes462e90c2018-08-21 16:10:48 -070066/** Corresponds to the Android ERROR log priority. */
67#define LOG_EMERG 0
68/** Corresponds to the Android ERROR log priority. */
69#define LOG_ALERT 1
70/** Corresponds to the Android ERROR log priority. */
71#define LOG_CRIT 2
72/** Corresponds to the Android ERROR log priority. */
73#define LOG_ERR 3
74/** Corresponds to the Android WARN log priority. */
75#define LOG_WARNING 4
76/** Corresponds to the Android INFO log priority. */
77#define LOG_NOTICE 5
78/** Corresponds to the Android INFO log priority. */
79#define LOG_INFO 6
80/** Corresponds to the Android DEBUG log priority. */
81#define LOG_DEBUG 7
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080082
Elliott Hughesafe63602014-07-23 11:38:38 -070083#define LOG_PRIMASK 7
84#define LOG_PRI(x) ((x) & LOG_PRIMASK)
Mark Salyzync4a586d2015-03-12 13:21:35 -070085#define LOG_MAKEPRI(fac, pri) ((fac) | (pri))
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080086
Elliott Hughes462e90c2018-08-21 16:10:48 -070087/** Currently ignored on Android. */
Elliott Hughesf5172882017-08-03 14:44:13 -070088#define LOG_KERN (0<<3)
Elliott Hughes462e90c2018-08-21 16:10:48 -070089/** Currently ignored on Android. */
Elliott Hughesf5172882017-08-03 14:44:13 -070090#define LOG_USER (1<<3)
Elliott Hughes462e90c2018-08-21 16:10:48 -070091/** Currently ignored on Android. */
Elliott Hughesf5172882017-08-03 14:44:13 -070092#define LOG_MAIL (2<<3)
Elliott Hughes462e90c2018-08-21 16:10:48 -070093/** Currently ignored on Android. */
Elliott Hughesf5172882017-08-03 14:44:13 -070094#define LOG_DAEMON (3<<3)
Elliott Hughes462e90c2018-08-21 16:10:48 -070095/** Currently ignored on Android. */
Elliott Hughesf5172882017-08-03 14:44:13 -070096#define LOG_AUTH (4<<3)
Elliott Hughes462e90c2018-08-21 16:10:48 -070097/** Currently ignored on Android. */
Elliott Hughesf5172882017-08-03 14:44:13 -070098#define LOG_SYSLOG (5<<3)
Elliott Hughes462e90c2018-08-21 16:10:48 -070099/** Currently ignored on Android. */
Elliott Hughesf5172882017-08-03 14:44:13 -0700100#define LOG_LPR (6<<3)
Elliott Hughes462e90c2018-08-21 16:10:48 -0700101/** Currently ignored on Android. */
Elliott Hughesf5172882017-08-03 14:44:13 -0700102#define LOG_NEWS (7<<3)
Elliott Hughes462e90c2018-08-21 16:10:48 -0700103/** Currently ignored on Android. */
Elliott Hughesf5172882017-08-03 14:44:13 -0700104#define LOG_UUCP (8<<3)
Elliott Hughes462e90c2018-08-21 16:10:48 -0700105/** Currently ignored on Android. */
Elliott Hughesf5172882017-08-03 14:44:13 -0700106#define LOG_CRON (9<<3)
Elliott Hughes462e90c2018-08-21 16:10:48 -0700107/** Currently ignored on Android. */
Elliott Hughesf5172882017-08-03 14:44:13 -0700108#define LOG_AUTHPRIV (10<<3)
Elliott Hughes462e90c2018-08-21 16:10:48 -0700109/** Currently ignored on Android. */
Elliott Hughesf5172882017-08-03 14:44:13 -0700110#define LOG_FTP (11<<3)
Elliott Hughes462e90c2018-08-21 16:10:48 -0700111/** Currently ignored on Android. */
Elliott Hughesf5172882017-08-03 14:44:13 -0700112#define LOG_LOCAL0 (16<<3)
Elliott Hughes462e90c2018-08-21 16:10:48 -0700113/** Currently ignored on Android. */
Elliott Hughesf5172882017-08-03 14:44:13 -0700114#define LOG_LOCAL1 (17<<3)
Elliott Hughes462e90c2018-08-21 16:10:48 -0700115/** Currently ignored on Android. */
Elliott Hughesf5172882017-08-03 14:44:13 -0700116#define LOG_LOCAL2 (18<<3)
Elliott Hughes462e90c2018-08-21 16:10:48 -0700117/** Currently ignored on Android. */
Elliott Hughesf5172882017-08-03 14:44:13 -0700118#define LOG_LOCAL3 (19<<3)
Elliott Hughes462e90c2018-08-21 16:10:48 -0700119/** Currently ignored on Android. */
Elliott Hughesf5172882017-08-03 14:44:13 -0700120#define LOG_LOCAL4 (20<<3)
Elliott Hughes462e90c2018-08-21 16:10:48 -0700121/** Currently ignored on Android. */
Elliott Hughesf5172882017-08-03 14:44:13 -0700122#define LOG_LOCAL5 (21<<3)
Elliott Hughes462e90c2018-08-21 16:10:48 -0700123/** Currently ignored on Android. */
Elliott Hughesf5172882017-08-03 14:44:13 -0700124#define LOG_LOCAL6 (22<<3)
Elliott Hughes462e90c2018-08-21 16:10:48 -0700125/** Currently ignored on Android. */
Elliott Hughesf5172882017-08-03 14:44:13 -0700126#define LOG_LOCAL7 (23<<3)
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800127
Elliott Hughesf5172882017-08-03 14:44:13 -0700128#define LOG_NFACILITIES 24
129#define LOG_FACMASK 0x3f8
Elliott Hughesafe63602014-07-23 11:38:38 -0700130#define LOG_FAC(x) (((x) >> 3) & (LOG_FACMASK >> 3))
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800131
Elliott Hughes462e90c2018-08-21 16:10:48 -0700132/**
133 * Converts a log priority into a mask enabling that single priority,
134 * for use with setlogmask().
135 */
Elliott Hughesa382a792014-06-09 17:16:19 -0700136#define LOG_MASK(pri) (1 << (pri))
Elliott Hughes462e90c2018-08-21 16:10:48 -0700137
138/**
139 * Converts a log priority into a mask enabling that priority and all lower
140 * priorities, for use with setlogmask().
141 */
Elliott Hughesa382a792014-06-09 17:16:19 -0700142#define LOG_UPTO(pri) ((1 << ((pri)+1)) - 1)
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800143
Elliott Hughes213d9432023-03-01 22:56:13 +0000144/** openlog() option ignored on Android. */
Elliott Hughes3ad8ecb2014-07-21 16:35:24 -0700145#define LOG_PID 0x01
Elliott Hughes213d9432023-03-01 22:56:13 +0000146/** openlog() option ignored on Android. */
Elliott Hughes3ad8ecb2014-07-21 16:35:24 -0700147#define LOG_CONS 0x02
Elliott Hughes213d9432023-03-01 22:56:13 +0000148/** openlog() option ignored on Android. */
Elliott Hughes3ad8ecb2014-07-21 16:35:24 -0700149#define LOG_ODELAY 0x04
Elliott Hughes213d9432023-03-01 22:56:13 +0000150/** openlog() option ignored on Android. */
Elliott Hughes3ad8ecb2014-07-21 16:35:24 -0700151#define LOG_NDELAY 0x08
Elliott Hughes213d9432023-03-01 22:56:13 +0000152/** openlog() option ignored on Android. */
Elliott Hughes3ad8ecb2014-07-21 16:35:24 -0700153#define LOG_NOWAIT 0x10
Elliott Hughes213d9432023-03-01 22:56:13 +0000154/**
155 * openlog() option to log to stderr as well as the system log.
156 *
157 * Available since API level 34 (ignored before then).
158 */
Elliott Hughes3ad8ecb2014-07-21 16:35:24 -0700159#define LOG_PERROR 0x20
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800160
Elliott Hughesafb8e052023-10-23 17:45:13 -0700161#if defined(SYSLOG_NAMES)
162/** A mapping from name to value, used by `facilitynames` and `prioritynames`. */
163typedef struct _code {
164 char* c_name;
165 int c_val;
166} CODE;
167/* A bogus facility value for "mark". */
168#define INTERNAL_MARK LOG_MAKEPRI((LOG_NFACILITIES<<3), 0)
169/** A table mapping facility names to values. */
170static const CODE facilitynames[] = {
171 { "auth", LOG_AUTH, },
172 { "authpriv", LOG_AUTHPRIV, },
173 { "cron", LOG_CRON, },
174 { "daemon", LOG_DAEMON, },
175 { "ftp", LOG_FTP, },
176 { "kern", LOG_KERN, },
177 { "lpr", LOG_LPR, },
178 { "mail", LOG_MAIL, },
179 { "mark", INTERNAL_MARK, },
180 { "news", LOG_NEWS, },
181 { "security", LOG_AUTH, },
182 { "syslog", LOG_SYSLOG, },
183 { "user", LOG_USER, },
184 { "uucp", LOG_UUCP, },
185 { "local0", LOG_LOCAL0, },
186 { "local1", LOG_LOCAL1, },
187 { "local2", LOG_LOCAL2, },
188 { "local3", LOG_LOCAL3, },
189 { "local4", LOG_LOCAL4, },
190 { "local5", LOG_LOCAL5, },
191 { "local6", LOG_LOCAL6, },
192 { "local7", LOG_LOCAL7, },
193 { NULL, -1, },
194};
195/* A bogus priority value for "none". */
196#define INTERNAL_NOPRI 8
197/** A table mapping priority names to values. */
198static const CODE prioritynames[] = {
199 { "alert", LOG_ALERT, },
200 { "crit", LOG_CRIT, },
201 { "debug", LOG_DEBUG, },
202 { "emerg", LOG_EMERG, },
203 { "err", LOG_ERR, },
204 { "error", LOG_ERR, },
205 { "info", LOG_INFO, },
206 { "none", INTERNAL_NOPRI, },
207 { "notice", LOG_NOTICE, },
208 { "panic", LOG_EMERG, },
209 { "warn", LOG_WARNING, },
210 { "warning", LOG_WARNING, },
211 { NULL, -1, },
212};
213#endif
214
Elliott Hughes462e90c2018-08-21 16:10:48 -0700215/**
Elliott Hughesbbd39aa2024-08-13 20:59:16 +0000216 * [closelog(3)](https://man7.org/linux/man-pages/man3/closelog.3.html) does
Elliott Hughes462e90c2018-08-21 16:10:48 -0700217 * nothing on Android.
218 */
Elliott Hughesafe63602014-07-23 11:38:38 -0700219void closelog(void);
Elliott Hughes462e90c2018-08-21 16:10:48 -0700220
221/**
Elliott Hughesbbd39aa2024-08-13 20:59:16 +0000222 * [openlog(3)](https://man7.org/linux/man-pages/man3/openlog.3.html) sets
zijunzhao979d39c2023-01-05 22:00:12 +0000223 * the log tag to `__prefix`, which can be NULL to return to the default of
224 * getprogname(). On Android, the other two arguments are ignored.
Elliott Hughes462e90c2018-08-21 16:10:48 -0700225 */
zijunzhao979d39c2023-01-05 22:00:12 +0000226void openlog(const char* _Nullable __prefix, int __option, int __facility);
Elliott Hughes462e90c2018-08-21 16:10:48 -0700227
228/**
Elliott Hughesbbd39aa2024-08-13 20:59:16 +0000229 * [setlogmask(3)](https://man7.org/linux/man-pages/man3/setlogmask.3.html)
Elliott Hughes462e90c2018-08-21 16:10:48 -0700230 * sets which log priorities will actually be logged. See `LOG_MASK` and
231 * `LOG_UPTO`.
232 */
Elliott Hughesfaa74342017-08-11 17:34:44 -0700233int setlogmask(int __mask);
Elliott Hughes462e90c2018-08-21 16:10:48 -0700234
235/**
Elliott Hughesbbd39aa2024-08-13 20:59:16 +0000236 * [syslog(3)](https://man7.org/linux/man-pages/man3/syslog.3.html) formats
Elliott Hughes462e90c2018-08-21 16:10:48 -0700237 * the printf()-like message and logs it with the given priority, unless
238 * suppressed by setlogmask(). On Android, the output goes to logcat.
239 */
zijunzhao979d39c2023-01-05 22:00:12 +0000240void syslog(int __priority, const char* _Nonnull __fmt, ...) __printflike(2, 3);
Elliott Hughes462e90c2018-08-21 16:10:48 -0700241
242/**
Elliott Hughesbbd39aa2024-08-13 20:59:16 +0000243 * [vsyslog(3)](https://man7.org/linux/man-pages/man3/vsyslog.3.html) formats
Elliott Hughes462e90c2018-08-21 16:10:48 -0700244 * the vprintf()-like message and logs it with the given priority, unless
245 * suppressed by setlogmask(). On Android, the output goes to logcat.
246 */
zijunzhao979d39c2023-01-05 22:00:12 +0000247void vsyslog(int __priority, const char* _Nonnull __fmt, va_list __args) __printflike(2, 0);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800248
249__END_DECLS