blob: 9fa5982a32c3e86cdcc6e93f3cef89f12fb944a6 [file] [log] [blame]
David 'Digit' Turner5c734642010-01-20 12:36:51 -08001/*
2 * Copyright (C) 2010 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 Hughes18a206c2012-10-29 17:37:13 -070028
Elliott Hughes8f2a5a02013-03-15 15:30:25 -070029#ifndef _LIBC_LOGGING_H
30#define _LIBC_LOGGING_H
David 'Digit' Turner5c734642010-01-20 12:36:51 -080031
Elliott Hughes1e980b62013-01-17 18:36:06 -080032#include <sys/cdefs.h>
David 'Digit' Turner5c734642010-01-20 12:36:51 -080033#include <stdarg.h>
34#include <stddef.h>
Elliott Hughes8f2a5a02013-03-15 15:30:25 -070035#include <stdint.h>
David 'Digit' Turner5c734642010-01-20 12:36:51 -080036
Elliott Hughes1e980b62013-01-17 18:36:06 -080037__BEGIN_DECLS
38
Elliott Hughes8f2a5a02013-03-15 15:30:25 -070039enum {
40 ANDROID_LOG_UNKNOWN = 0,
41 ANDROID_LOG_DEFAULT, /* only for SetMinPriority() */
42
43 ANDROID_LOG_VERBOSE,
44 ANDROID_LOG_DEBUG,
45 ANDROID_LOG_INFO,
46 ANDROID_LOG_WARN,
47 ANDROID_LOG_ERROR,
48 ANDROID_LOG_FATAL,
49
50 ANDROID_LOG_SILENT, /* only for SetMinPriority(); must be last */
51};
52
Mark Salyzyn0336e352013-11-08 06:58:01 -080053enum {
Elliott Hughesae0a62b2014-05-07 17:12:40 -070054 LOG_ID_MIN = 0,
Mark Salyzyn0336e352013-11-08 06:58:01 -080055
Elliott Hughesae0a62b2014-05-07 17:12:40 -070056 LOG_ID_MAIN = 0,
57 LOG_ID_RADIO = 1,
58 LOG_ID_EVENTS = 2,
59 LOG_ID_SYSTEM = 3,
60 LOG_ID_CRASH = 4,
Mark Salyzyn0336e352013-11-08 06:58:01 -080061
Elliott Hughesae0a62b2014-05-07 17:12:40 -070062 LOG_ID_MAX
Mark Salyzyn0336e352013-11-08 06:58:01 -080063};
64
Elliott Hughes0d787c12013-04-04 13:46:46 -070065struct abort_msg_t {
66 size_t size;
67 char msg[0];
68};
69
Elliott Hughes0d787c12013-04-04 13:46:46 -070070// Formats a message to the log (priority 'fatal'), then aborts.
Elliott Hughes9eb3ae12016-06-30 09:12:40 -070071__noreturn void __libc_fatal(const char* _Nonnull, ...) __printflike(1, 2);
Elliott Hughes0d787c12013-04-04 13:46:46 -070072
Elliott Hughesb83d6742016-02-25 20:33:47 -080073// Formats a message to the log (priority 'fatal'), prefixed by "FORTIFY: ", then aborts.
Elliott Hughes9eb3ae12016-06-30 09:12:40 -070074__noreturn void __fortify_fatal(const char* _Nonnull, ...) __printflike(1, 2);
Elliott Hughes61e699a2013-06-12 14:05:46 -070075
76//
Elliott Hughes1e980b62013-01-17 18:36:06 -080077// Formatting routines for the C library's internal debugging.
Elliott Hughes91570ce2014-07-10 12:34:23 -070078// Unlike the usual alternatives, these don't allocate, and they don't drag in all of stdio.
Elliott Hughes8f2a5a02013-03-15 15:30:25 -070079//
Elliott Hughes1e980b62013-01-17 18:36:06 -080080
Elliott Hughes9eb3ae12016-06-30 09:12:40 -070081int __libc_format_buffer(char* _Nonnull buf, size_t size, const char* _Nonnull fmt, ...) __printflike(3, 4);
82int __libc_format_fd(int fd, const char* _Nonnull format , ...) __printflike(2, 3);
83int __libc_format_log(int pri, const char* _Nonnull tag, const char* _Nonnull fmt, ...) __printflike(3, 4);
Elliott Hughes53420fb2016-06-30 13:47:16 -070084#if defined(__arm__) || defined(__aarch64__) || defined(__x86_64__)
Elliott Hughes9eb3ae12016-06-30 09:12:40 -070085int __libc_format_log_va_list(int pri, const char* _Nonnull tag, const char* _Nonnull fmt, va_list ap);
Elliott Hughes53420fb2016-06-30 13:47:16 -070086#else // defined(__mips__) || defined(__i386__)
Elliott Hughes8ed118d2016-06-30 12:46:21 -070087int __libc_format_log_va_list(int pri, const char* _Nonnull tag, const char* _Nonnull fmt, va_list _Nonnull ap);
88#endif
Elliott Hughes9eb3ae12016-06-30 09:12:40 -070089int __libc_write_log(int pri, const char* _Nonnull tag, const char* _Nonnull msg);
Colin Cross2c759912016-02-05 16:17:39 -080090
Elliott Hughes1e980b62013-01-17 18:36:06 -080091__END_DECLS
92
Elliott Hughes8f2a5a02013-03-15 15:30:25 -070093#endif