blob: 1e2fcc4b3fb3ece7eb390a8048e18bd916c5a233 [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
59#include <stdio.h>
60#include <sys/cdefs.h>
61#include <stdarg.h>
62
63__BEGIN_DECLS
64
Elliott Hughes462e90c2018-08-21 16:10:48 -070065/** Corresponds to the Android ERROR log priority. */
66#define LOG_EMERG 0
67/** Corresponds to the Android ERROR log priority. */
68#define LOG_ALERT 1
69/** Corresponds to the Android ERROR log priority. */
70#define LOG_CRIT 2
71/** Corresponds to the Android ERROR log priority. */
72#define LOG_ERR 3
73/** Corresponds to the Android WARN log priority. */
74#define LOG_WARNING 4
75/** Corresponds to the Android INFO log priority. */
76#define LOG_NOTICE 5
77/** Corresponds to the Android INFO log priority. */
78#define LOG_INFO 6
79/** Corresponds to the Android DEBUG log priority. */
80#define LOG_DEBUG 7
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080081
Elliott Hughesafe63602014-07-23 11:38:38 -070082#define LOG_PRIMASK 7
83#define LOG_PRI(x) ((x) & LOG_PRIMASK)
Mark Salyzync4a586d2015-03-12 13:21:35 -070084#define LOG_MAKEPRI(fac, pri) ((fac) | (pri))
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080085
Elliott Hughes462e90c2018-08-21 16:10:48 -070086/** Currently ignored on Android. */
Elliott Hughesf5172882017-08-03 14:44:13 -070087#define LOG_KERN (0<<3)
Elliott Hughes462e90c2018-08-21 16:10:48 -070088/** Currently ignored on Android. */
Elliott Hughesf5172882017-08-03 14:44:13 -070089#define LOG_USER (1<<3)
Elliott Hughes462e90c2018-08-21 16:10:48 -070090/** Currently ignored on Android. */
Elliott Hughesf5172882017-08-03 14:44:13 -070091#define LOG_MAIL (2<<3)
Elliott Hughes462e90c2018-08-21 16:10:48 -070092/** Currently ignored on Android. */
Elliott Hughesf5172882017-08-03 14:44:13 -070093#define LOG_DAEMON (3<<3)
Elliott Hughes462e90c2018-08-21 16:10:48 -070094/** Currently ignored on Android. */
Elliott Hughesf5172882017-08-03 14:44:13 -070095#define LOG_AUTH (4<<3)
Elliott Hughes462e90c2018-08-21 16:10:48 -070096/** Currently ignored on Android. */
Elliott Hughesf5172882017-08-03 14:44:13 -070097#define LOG_SYSLOG (5<<3)
Elliott Hughes462e90c2018-08-21 16:10:48 -070098/** Currently ignored on Android. */
Elliott Hughesf5172882017-08-03 14:44:13 -070099#define LOG_LPR (6<<3)
Elliott Hughes462e90c2018-08-21 16:10:48 -0700100/** Currently ignored on Android. */
Elliott Hughesf5172882017-08-03 14:44:13 -0700101#define LOG_NEWS (7<<3)
Elliott Hughes462e90c2018-08-21 16:10:48 -0700102/** Currently ignored on Android. */
Elliott Hughesf5172882017-08-03 14:44:13 -0700103#define LOG_UUCP (8<<3)
Elliott Hughes462e90c2018-08-21 16:10:48 -0700104/** Currently ignored on Android. */
Elliott Hughesf5172882017-08-03 14:44:13 -0700105#define LOG_CRON (9<<3)
Elliott Hughes462e90c2018-08-21 16:10:48 -0700106/** Currently ignored on Android. */
Elliott Hughesf5172882017-08-03 14:44:13 -0700107#define LOG_AUTHPRIV (10<<3)
Elliott Hughes462e90c2018-08-21 16:10:48 -0700108/** Currently ignored on Android. */
Elliott Hughesf5172882017-08-03 14:44:13 -0700109#define LOG_FTP (11<<3)
Elliott Hughes462e90c2018-08-21 16:10:48 -0700110/** Currently ignored on Android. */
Elliott Hughesf5172882017-08-03 14:44:13 -0700111#define LOG_LOCAL0 (16<<3)
Elliott Hughes462e90c2018-08-21 16:10:48 -0700112/** Currently ignored on Android. */
Elliott Hughesf5172882017-08-03 14:44:13 -0700113#define LOG_LOCAL1 (17<<3)
Elliott Hughes462e90c2018-08-21 16:10:48 -0700114/** Currently ignored on Android. */
Elliott Hughesf5172882017-08-03 14:44:13 -0700115#define LOG_LOCAL2 (18<<3)
Elliott Hughes462e90c2018-08-21 16:10:48 -0700116/** Currently ignored on Android. */
Elliott Hughesf5172882017-08-03 14:44:13 -0700117#define LOG_LOCAL3 (19<<3)
Elliott Hughes462e90c2018-08-21 16:10:48 -0700118/** Currently ignored on Android. */
Elliott Hughesf5172882017-08-03 14:44:13 -0700119#define LOG_LOCAL4 (20<<3)
Elliott Hughes462e90c2018-08-21 16:10:48 -0700120/** Currently ignored on Android. */
Elliott Hughesf5172882017-08-03 14:44:13 -0700121#define LOG_LOCAL5 (21<<3)
Elliott Hughes462e90c2018-08-21 16:10:48 -0700122/** Currently ignored on Android. */
Elliott Hughesf5172882017-08-03 14:44:13 -0700123#define LOG_LOCAL6 (22<<3)
Elliott Hughes462e90c2018-08-21 16:10:48 -0700124/** Currently ignored on Android. */
Elliott Hughesf5172882017-08-03 14:44:13 -0700125#define LOG_LOCAL7 (23<<3)
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800126
Elliott Hughesf5172882017-08-03 14:44:13 -0700127#define LOG_NFACILITIES 24
128#define LOG_FACMASK 0x3f8
Elliott Hughesafe63602014-07-23 11:38:38 -0700129#define LOG_FAC(x) (((x) >> 3) & (LOG_FACMASK >> 3))
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800130
Elliott Hughes462e90c2018-08-21 16:10:48 -0700131/**
132 * Converts a log priority into a mask enabling that single priority,
133 * for use with setlogmask().
134 */
Elliott Hughesa382a792014-06-09 17:16:19 -0700135#define LOG_MASK(pri) (1 << (pri))
Elliott Hughes462e90c2018-08-21 16:10:48 -0700136
137/**
138 * Converts a log priority into a mask enabling that priority and all lower
139 * priorities, for use with setlogmask().
140 */
Elliott Hughesa382a792014-06-09 17:16:19 -0700141#define LOG_UPTO(pri) ((1 << ((pri)+1)) - 1)
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800142
Elliott Hughes213d9432023-03-01 22:56:13 +0000143/** openlog() option ignored on Android. */
Elliott Hughes3ad8ecb2014-07-21 16:35:24 -0700144#define LOG_PID 0x01
Elliott Hughes213d9432023-03-01 22:56:13 +0000145/** openlog() option ignored on Android. */
Elliott Hughes3ad8ecb2014-07-21 16:35:24 -0700146#define LOG_CONS 0x02
Elliott Hughes213d9432023-03-01 22:56:13 +0000147/** openlog() option ignored on Android. */
Elliott Hughes3ad8ecb2014-07-21 16:35:24 -0700148#define LOG_ODELAY 0x04
Elliott Hughes213d9432023-03-01 22:56:13 +0000149/** openlog() option ignored on Android. */
Elliott Hughes3ad8ecb2014-07-21 16:35:24 -0700150#define LOG_NDELAY 0x08
Elliott Hughes213d9432023-03-01 22:56:13 +0000151/** openlog() option ignored on Android. */
Elliott Hughes3ad8ecb2014-07-21 16:35:24 -0700152#define LOG_NOWAIT 0x10
Elliott Hughes213d9432023-03-01 22:56:13 +0000153/**
154 * openlog() option to log to stderr as well as the system log.
155 *
156 * Available since API level 34 (ignored before then).
157 */
Elliott Hughes3ad8ecb2014-07-21 16:35:24 -0700158#define LOG_PERROR 0x20
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800159
Elliott Hughesafb8e052023-10-23 17:45:13 -0700160#if defined(SYSLOG_NAMES)
161/** A mapping from name to value, used by `facilitynames` and `prioritynames`. */
162typedef struct _code {
163 char* c_name;
164 int c_val;
165} CODE;
166/* A bogus facility value for "mark". */
167#define INTERNAL_MARK LOG_MAKEPRI((LOG_NFACILITIES<<3), 0)
168/** A table mapping facility names to values. */
169static const CODE facilitynames[] = {
170 { "auth", LOG_AUTH, },
171 { "authpriv", LOG_AUTHPRIV, },
172 { "cron", LOG_CRON, },
173 { "daemon", LOG_DAEMON, },
174 { "ftp", LOG_FTP, },
175 { "kern", LOG_KERN, },
176 { "lpr", LOG_LPR, },
177 { "mail", LOG_MAIL, },
178 { "mark", INTERNAL_MARK, },
179 { "news", LOG_NEWS, },
180 { "security", LOG_AUTH, },
181 { "syslog", LOG_SYSLOG, },
182 { "user", LOG_USER, },
183 { "uucp", LOG_UUCP, },
184 { "local0", LOG_LOCAL0, },
185 { "local1", LOG_LOCAL1, },
186 { "local2", LOG_LOCAL2, },
187 { "local3", LOG_LOCAL3, },
188 { "local4", LOG_LOCAL4, },
189 { "local5", LOG_LOCAL5, },
190 { "local6", LOG_LOCAL6, },
191 { "local7", LOG_LOCAL7, },
192 { NULL, -1, },
193};
194/* A bogus priority value for "none". */
195#define INTERNAL_NOPRI 8
196/** A table mapping priority names to values. */
197static const CODE prioritynames[] = {
198 { "alert", LOG_ALERT, },
199 { "crit", LOG_CRIT, },
200 { "debug", LOG_DEBUG, },
201 { "emerg", LOG_EMERG, },
202 { "err", LOG_ERR, },
203 { "error", LOG_ERR, },
204 { "info", LOG_INFO, },
205 { "none", INTERNAL_NOPRI, },
206 { "notice", LOG_NOTICE, },
207 { "panic", LOG_EMERG, },
208 { "warn", LOG_WARNING, },
209 { "warning", LOG_WARNING, },
210 { NULL, -1, },
211};
212#endif
213
Elliott Hughes462e90c2018-08-21 16:10:48 -0700214/**
215 * [closelog(3)](http://man7.org/linux/man-pages/man3/closelog.3.html) does
216 * nothing on Android.
217 */
Elliott Hughesafe63602014-07-23 11:38:38 -0700218void closelog(void);
Elliott Hughes462e90c2018-08-21 16:10:48 -0700219
220/**
221 * [openlog(3)](http://man7.org/linux/man-pages/man3/openlog.3.html) sets
zijunzhao979d39c2023-01-05 22:00:12 +0000222 * the log tag to `__prefix`, which can be NULL to return to the default of
223 * getprogname(). On Android, the other two arguments are ignored.
Elliott Hughes462e90c2018-08-21 16:10:48 -0700224 */
zijunzhao979d39c2023-01-05 22:00:12 +0000225void openlog(const char* _Nullable __prefix, int __option, int __facility);
Elliott Hughes462e90c2018-08-21 16:10:48 -0700226
227/**
228 * [setlogmask(3)](http://man7.org/linux/man-pages/man3/setlogmask.3.html)
229 * sets which log priorities will actually be logged. See `LOG_MASK` and
230 * `LOG_UPTO`.
231 */
Elliott Hughesfaa74342017-08-11 17:34:44 -0700232int setlogmask(int __mask);
Elliott Hughes462e90c2018-08-21 16:10:48 -0700233
234/**
235 * [syslog(3)](http://man7.org/linux/man-pages/man3/syslog.3.html) formats
236 * the printf()-like message and logs it with the given priority, unless
237 * suppressed by setlogmask(). On Android, the output goes to logcat.
238 */
zijunzhao979d39c2023-01-05 22:00:12 +0000239void syslog(int __priority, const char* _Nonnull __fmt, ...) __printflike(2, 3);
Elliott Hughes462e90c2018-08-21 16:10:48 -0700240
241/**
242 * [vsyslog(3)](http://man7.org/linux/man-pages/man3/vsyslog.3.html) formats
243 * the vprintf()-like message and logs it with the given priority, unless
244 * suppressed by setlogmask(). On Android, the output goes to logcat.
245 */
zijunzhao979d39c2023-01-05 22:00:12 +0000246void vsyslog(int __priority, const char* _Nonnull __fmt, va_list __args) __printflike(2, 0);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800247
248__END_DECLS