The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 1 | /* |
| 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 Hughes | afb8e05 | 2023-10-23 17:45:13 -0700 | [diff] [blame] | 28 | /* |
| 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 Hughes | a382a79 | 2014-06-09 17:16:19 -0700 | [diff] [blame] | 56 | |
Elliott Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame] | 57 | #pragma once |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 58 | |
| 59 | #include <stdio.h> |
| 60 | #include <sys/cdefs.h> |
| 61 | #include <stdarg.h> |
| 62 | |
| 63 | __BEGIN_DECLS |
| 64 | |
Elliott Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame] | 65 | /** 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 Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 81 | |
Elliott Hughes | afe6360 | 2014-07-23 11:38:38 -0700 | [diff] [blame] | 82 | #define LOG_PRIMASK 7 |
| 83 | #define LOG_PRI(x) ((x) & LOG_PRIMASK) |
Mark Salyzyn | c4a586d | 2015-03-12 13:21:35 -0700 | [diff] [blame] | 84 | #define LOG_MAKEPRI(fac, pri) ((fac) | (pri)) |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 85 | |
Elliott Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame] | 86 | /** Currently ignored on Android. */ |
Elliott Hughes | f517288 | 2017-08-03 14:44:13 -0700 | [diff] [blame] | 87 | #define LOG_KERN (0<<3) |
Elliott Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame] | 88 | /** Currently ignored on Android. */ |
Elliott Hughes | f517288 | 2017-08-03 14:44:13 -0700 | [diff] [blame] | 89 | #define LOG_USER (1<<3) |
Elliott Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame] | 90 | /** Currently ignored on Android. */ |
Elliott Hughes | f517288 | 2017-08-03 14:44:13 -0700 | [diff] [blame] | 91 | #define LOG_MAIL (2<<3) |
Elliott Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame] | 92 | /** Currently ignored on Android. */ |
Elliott Hughes | f517288 | 2017-08-03 14:44:13 -0700 | [diff] [blame] | 93 | #define LOG_DAEMON (3<<3) |
Elliott Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame] | 94 | /** Currently ignored on Android. */ |
Elliott Hughes | f517288 | 2017-08-03 14:44:13 -0700 | [diff] [blame] | 95 | #define LOG_AUTH (4<<3) |
Elliott Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame] | 96 | /** Currently ignored on Android. */ |
Elliott Hughes | f517288 | 2017-08-03 14:44:13 -0700 | [diff] [blame] | 97 | #define LOG_SYSLOG (5<<3) |
Elliott Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame] | 98 | /** Currently ignored on Android. */ |
Elliott Hughes | f517288 | 2017-08-03 14:44:13 -0700 | [diff] [blame] | 99 | #define LOG_LPR (6<<3) |
Elliott Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame] | 100 | /** Currently ignored on Android. */ |
Elliott Hughes | f517288 | 2017-08-03 14:44:13 -0700 | [diff] [blame] | 101 | #define LOG_NEWS (7<<3) |
Elliott Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame] | 102 | /** Currently ignored on Android. */ |
Elliott Hughes | f517288 | 2017-08-03 14:44:13 -0700 | [diff] [blame] | 103 | #define LOG_UUCP (8<<3) |
Elliott Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame] | 104 | /** Currently ignored on Android. */ |
Elliott Hughes | f517288 | 2017-08-03 14:44:13 -0700 | [diff] [blame] | 105 | #define LOG_CRON (9<<3) |
Elliott Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame] | 106 | /** Currently ignored on Android. */ |
Elliott Hughes | f517288 | 2017-08-03 14:44:13 -0700 | [diff] [blame] | 107 | #define LOG_AUTHPRIV (10<<3) |
Elliott Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame] | 108 | /** Currently ignored on Android. */ |
Elliott Hughes | f517288 | 2017-08-03 14:44:13 -0700 | [diff] [blame] | 109 | #define LOG_FTP (11<<3) |
Elliott Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame] | 110 | /** Currently ignored on Android. */ |
Elliott Hughes | f517288 | 2017-08-03 14:44:13 -0700 | [diff] [blame] | 111 | #define LOG_LOCAL0 (16<<3) |
Elliott Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame] | 112 | /** Currently ignored on Android. */ |
Elliott Hughes | f517288 | 2017-08-03 14:44:13 -0700 | [diff] [blame] | 113 | #define LOG_LOCAL1 (17<<3) |
Elliott Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame] | 114 | /** Currently ignored on Android. */ |
Elliott Hughes | f517288 | 2017-08-03 14:44:13 -0700 | [diff] [blame] | 115 | #define LOG_LOCAL2 (18<<3) |
Elliott Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame] | 116 | /** Currently ignored on Android. */ |
Elliott Hughes | f517288 | 2017-08-03 14:44:13 -0700 | [diff] [blame] | 117 | #define LOG_LOCAL3 (19<<3) |
Elliott Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame] | 118 | /** Currently ignored on Android. */ |
Elliott Hughes | f517288 | 2017-08-03 14:44:13 -0700 | [diff] [blame] | 119 | #define LOG_LOCAL4 (20<<3) |
Elliott Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame] | 120 | /** Currently ignored on Android. */ |
Elliott Hughes | f517288 | 2017-08-03 14:44:13 -0700 | [diff] [blame] | 121 | #define LOG_LOCAL5 (21<<3) |
Elliott Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame] | 122 | /** Currently ignored on Android. */ |
Elliott Hughes | f517288 | 2017-08-03 14:44:13 -0700 | [diff] [blame] | 123 | #define LOG_LOCAL6 (22<<3) |
Elliott Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame] | 124 | /** Currently ignored on Android. */ |
Elliott Hughes | f517288 | 2017-08-03 14:44:13 -0700 | [diff] [blame] | 125 | #define LOG_LOCAL7 (23<<3) |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 126 | |
Elliott Hughes | f517288 | 2017-08-03 14:44:13 -0700 | [diff] [blame] | 127 | #define LOG_NFACILITIES 24 |
| 128 | #define LOG_FACMASK 0x3f8 |
Elliott Hughes | afe6360 | 2014-07-23 11:38:38 -0700 | [diff] [blame] | 129 | #define LOG_FAC(x) (((x) >> 3) & (LOG_FACMASK >> 3)) |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 130 | |
Elliott Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame] | 131 | /** |
| 132 | * Converts a log priority into a mask enabling that single priority, |
| 133 | * for use with setlogmask(). |
| 134 | */ |
Elliott Hughes | a382a79 | 2014-06-09 17:16:19 -0700 | [diff] [blame] | 135 | #define LOG_MASK(pri) (1 << (pri)) |
Elliott Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame] | 136 | |
| 137 | /** |
| 138 | * Converts a log priority into a mask enabling that priority and all lower |
| 139 | * priorities, for use with setlogmask(). |
| 140 | */ |
Elliott Hughes | a382a79 | 2014-06-09 17:16:19 -0700 | [diff] [blame] | 141 | #define LOG_UPTO(pri) ((1 << ((pri)+1)) - 1) |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 142 | |
Elliott Hughes | 213d943 | 2023-03-01 22:56:13 +0000 | [diff] [blame] | 143 | /** openlog() option ignored on Android. */ |
Elliott Hughes | 3ad8ecb | 2014-07-21 16:35:24 -0700 | [diff] [blame] | 144 | #define LOG_PID 0x01 |
Elliott Hughes | 213d943 | 2023-03-01 22:56:13 +0000 | [diff] [blame] | 145 | /** openlog() option ignored on Android. */ |
Elliott Hughes | 3ad8ecb | 2014-07-21 16:35:24 -0700 | [diff] [blame] | 146 | #define LOG_CONS 0x02 |
Elliott Hughes | 213d943 | 2023-03-01 22:56:13 +0000 | [diff] [blame] | 147 | /** openlog() option ignored on Android. */ |
Elliott Hughes | 3ad8ecb | 2014-07-21 16:35:24 -0700 | [diff] [blame] | 148 | #define LOG_ODELAY 0x04 |
Elliott Hughes | 213d943 | 2023-03-01 22:56:13 +0000 | [diff] [blame] | 149 | /** openlog() option ignored on Android. */ |
Elliott Hughes | 3ad8ecb | 2014-07-21 16:35:24 -0700 | [diff] [blame] | 150 | #define LOG_NDELAY 0x08 |
Elliott Hughes | 213d943 | 2023-03-01 22:56:13 +0000 | [diff] [blame] | 151 | /** openlog() option ignored on Android. */ |
Elliott Hughes | 3ad8ecb | 2014-07-21 16:35:24 -0700 | [diff] [blame] | 152 | #define LOG_NOWAIT 0x10 |
Elliott Hughes | 213d943 | 2023-03-01 22:56:13 +0000 | [diff] [blame] | 153 | /** |
| 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 Hughes | 3ad8ecb | 2014-07-21 16:35:24 -0700 | [diff] [blame] | 158 | #define LOG_PERROR 0x20 |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 159 | |
Elliott Hughes | afb8e05 | 2023-10-23 17:45:13 -0700 | [diff] [blame] | 160 | #if defined(SYSLOG_NAMES) |
| 161 | /** A mapping from name to value, used by `facilitynames` and `prioritynames`. */ |
| 162 | typedef 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. */ |
| 169 | static 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. */ |
| 197 | static 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 Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame] | 214 | /** |
| 215 | * [closelog(3)](http://man7.org/linux/man-pages/man3/closelog.3.html) does |
| 216 | * nothing on Android. |
| 217 | */ |
Elliott Hughes | afe6360 | 2014-07-23 11:38:38 -0700 | [diff] [blame] | 218 | void closelog(void); |
Elliott Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame] | 219 | |
| 220 | /** |
| 221 | * [openlog(3)](http://man7.org/linux/man-pages/man3/openlog.3.html) sets |
zijunzhao | 979d39c | 2023-01-05 22:00:12 +0000 | [diff] [blame] | 222 | * 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 Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame] | 224 | */ |
zijunzhao | 979d39c | 2023-01-05 22:00:12 +0000 | [diff] [blame] | 225 | void openlog(const char* _Nullable __prefix, int __option, int __facility); |
Elliott Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame] | 226 | |
| 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 Hughes | faa7434 | 2017-08-11 17:34:44 -0700 | [diff] [blame] | 232 | int setlogmask(int __mask); |
Elliott Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame] | 233 | |
| 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 | */ |
zijunzhao | 979d39c | 2023-01-05 22:00:12 +0000 | [diff] [blame] | 239 | void syslog(int __priority, const char* _Nonnull __fmt, ...) __printflike(2, 3); |
Elliott Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame] | 240 | |
| 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 | */ |
zijunzhao | 979d39c | 2023-01-05 22:00:12 +0000 | [diff] [blame] | 246 | void vsyslog(int __priority, const char* _Nonnull __fmt, va_list __args) __printflike(2, 0); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 247 | |
| 248 | __END_DECLS |