Path: blob/21.2-virgl/include/android_stub/android/log.h
4547 views
/*1* Copyright (C) 2009 The Android Open Source Project2*3* Licensed under the Apache License, Version 2.0 (the "License");4* you may not use this file except in compliance with the License.5* You may obtain a copy of the License at6*7* http://www.apache.org/licenses/LICENSE-2.08*9* Unless required by applicable law or agreed to in writing, software10* distributed under the License is distributed on an "AS IS" BASIS,11* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12* See the License for the specific language governing permissions and13* limitations under the License.14*/1516#pragma once1718/**19* @addtogroup Logging20* @{21*/2223/**24* \file25*26* Support routines to send messages to the Android log buffer,27* which can later be accessed through the `logcat` utility.28*29* Each log message must have30* - a priority31* - a log tag32* - some text33*34* The tag normally corresponds to the component that emits the log message,35* and should be reasonably small.36*37* Log message text may be truncated to less than an implementation-specific38* limit (1023 bytes).39*40* Note that a newline character ("\n") will be appended automatically to your41* log message, if not already there. It is not possible to send several42* messages and have them appear on a single line in logcat.43*44* Please use logging in moderation:45*46* - Sending log messages eats CPU and slow down your application and the47* system.48*49* - The circular log buffer is pretty small, so sending many messages50* will hide other important log messages.51*52* - In release builds, only send log messages to account for exceptional53* conditions.54*/5556#include <stdarg.h>57#include <stddef.h>58#include <stdint.h>59#include <sys/cdefs.h>6061#if !defined(__BIONIC__) && !defined(__INTRODUCED_IN)62#define __INTRODUCED_IN(x)63#endif6465#ifdef __cplusplus66extern "C" {67#endif6869/**70* Android log priority values, in increasing order of priority.71*/72typedef enum android_LogPriority {73/** For internal use only. */74ANDROID_LOG_UNKNOWN = 0,75/** The default priority, for internal use only. */76ANDROID_LOG_DEFAULT, /* only for SetMinPriority() */77/** Verbose logging. Should typically be disabled for a release apk. */78ANDROID_LOG_VERBOSE,79/** Debug logging. Should typically be disabled for a release apk. */80ANDROID_LOG_DEBUG,81/** Informational logging. Should typically be disabled for a release apk. */82ANDROID_LOG_INFO,83/** Warning logging. For use with recoverable failures. */84ANDROID_LOG_WARN,85/** Error logging. For use with unrecoverable failures. */86ANDROID_LOG_ERROR,87/** Fatal logging. For use when aborting. */88ANDROID_LOG_FATAL,89/** For internal use only. */90ANDROID_LOG_SILENT, /* only for SetMinPriority(); must be last */91} android_LogPriority;9293/**94* Writes the constant string `text` to the log, with priority `prio` and tag95* `tag`.96*/97int __android_log_write(int prio, const char* tag, const char* text);9899/**100* Writes a formatted string to the log, with priority `prio` and tag `tag`.101* The details of formatting are the same as for102* [printf(3)](http://man7.org/linux/man-pages/man3/printf.3.html).103*/104int __android_log_print(int prio, const char* tag, const char* fmt, ...)105__attribute__((__format__(printf, 3, 4)));106107/**108* Equivalent to `__android_log_print`, but taking a `va_list`.109* (If `__android_log_print` is like `printf`, this is like `vprintf`.)110*/111int __android_log_vprint(int prio, const char* tag, const char* fmt, va_list ap)112__attribute__((__format__(printf, 3, 0)));113114/**115* Writes an assertion failure to the log (as `ANDROID_LOG_FATAL`) and to116* stderr, before calling117* [abort(3)](http://man7.org/linux/man-pages/man3/abort.3.html).118*119* If `fmt` is non-null, `cond` is unused. If `fmt` is null, the string120* `Assertion failed: %s` is used with `cond` as the string argument.121* If both `fmt` and `cond` are null, a default string is provided.122*123* Most callers should use124* [assert(3)](http://man7.org/linux/man-pages/man3/assert.3.html) from125* `<assert.h>` instead, or the `__assert` and `__assert2` functions126* provided by bionic if more control is needed. They support automatically127* including the source filename and line number more conveniently than this128* function.129*/130void __android_log_assert(const char* cond, const char* tag, const char* fmt, ...)131__attribute__((__noreturn__)) __attribute__((__format__(printf, 3, 4)));132133/**134* Identifies a specific log buffer for __android_log_buf_write()135* and __android_log_buf_print().136*/137typedef enum log_id {138LOG_ID_MIN = 0,139140/** The main log buffer. This is the only log buffer available to apps. */141LOG_ID_MAIN = 0,142/** The radio log buffer. */143LOG_ID_RADIO = 1,144/** The event log buffer. */145LOG_ID_EVENTS = 2,146/** The system log buffer. */147LOG_ID_SYSTEM = 3,148/** The crash log buffer. */149LOG_ID_CRASH = 4,150/** The statistics log buffer. */151LOG_ID_STATS = 5,152/** The security log buffer. */153LOG_ID_SECURITY = 6,154/** The kernel log buffer. */155LOG_ID_KERNEL = 7,156157LOG_ID_MAX,158159/** Let the logging function choose the best log target. */160LOG_ID_DEFAULT = 0x7FFFFFFF161} log_id_t;162163/**164* Writes the constant string `text` to the log buffer `id`,165* with priority `prio` and tag `tag`.166*167* Apps should use __android_log_write() instead.168*/169int __android_log_buf_write(int bufID, int prio, const char* tag, const char* text);170171/**172* Writes a formatted string to log buffer `id`,173* with priority `prio` and tag `tag`.174* The details of formatting are the same as for175* [printf(3)](http://man7.org/linux/man-pages/man3/printf.3.html).176*177* Apps should use __android_log_print() instead.178*/179int __android_log_buf_print(int bufID, int prio, const char* tag, const char* fmt, ...)180__attribute__((__format__(printf, 4, 5)));181182/**183* Logger data struct used for writing log messages to liblog via __android_log_write_logger_data()184* and sending log messages to user defined loggers specified in __android_log_set_logger().185*/186struct __android_log_message {187/** Must be set to sizeof(__android_log_message) and is used for versioning. */188size_t struct_size;189190/** {@link log_id_t} values. */191int32_t buffer_id;192193/** {@link android_LogPriority} values. */194int32_t priority;195196/** The tag for the log message. */197const char* tag;198199/** Optional file name, may be set to nullptr. */200const char* file;201202/** Optional line number, ignore if file is nullptr. */203uint32_t line;204205/** The log message itself. */206const char* message;207};208209/**210* Prototype for the 'logger' function that is called for every log message.211*/212typedef void (*__android_logger_function)(const struct __android_log_message* log_message);213/**214* Prototype for the 'abort' function that is called when liblog will abort due to215* __android_log_assert() failures.216*/217typedef void (*__android_aborter_function)(const char* abort_message);218219#if !defined(__ANDROID__) || __ANDROID_API__ >= 30220/**221* Writes the log message specified by log_message. log_message includes additional file name and222* line number information that a logger may use. log_message is versioned for backwards223* compatibility.224* This assumes that loggability has already been checked through __android_log_is_loggable().225* Higher level logging libraries, such as libbase, first check loggability, then format their226* buffers, then pass the message to liblog via this function, and therefore we do not want to227* duplicate the loggability check here.228*229* @param log_message the log message itself, see __android_log_message.230*231* Available since API level 30.232*/233void __android_log_write_log_message(struct __android_log_message* log_message) __INTRODUCED_IN(30);234235/**236* Sets a user defined logger function. All log messages sent to liblog will be set to the237* function pointer specified by logger for processing. It is not expected that log messages are238* already terminated with a new line. This function should add new lines if required for line239* separation.240*241* @param logger the new function that will handle log messages.242*243* Available since API level 30.244*/245void __android_log_set_logger(__android_logger_function logger) __INTRODUCED_IN(30);246247/**248* Writes the log message to logd. This is an __android_logger_function and can be provided to249* __android_log_set_logger(). It is the default logger when running liblog on a device.250*251* @param log_message the log message to write, see __android_log_message.252*253* Available since API level 30.254*/255void __android_log_logd_logger(const struct __android_log_message* log_message) __INTRODUCED_IN(30);256257/**258* Writes the log message to stderr. This is an __android_logger_function and can be provided to259* __android_log_set_logger(). It is the default logger when running liblog on host.260*261* @param log_message the log message to write, see __android_log_message.262*263* Available since API level 30.264*/265void __android_log_stderr_logger(const struct __android_log_message* log_message)266__INTRODUCED_IN(30);267268/**269* Sets a user defined aborter function that is called for __android_log_assert() failures. This270* user defined aborter function is highly recommended to abort and be noreturn, but is not strictly271* required to.272*273* @param aborter the new aborter function, see __android_aborter_function.274*275* Available since API level 30.276*/277void __android_log_set_aborter(__android_aborter_function aborter) __INTRODUCED_IN(30);278279/**280* Calls the stored aborter function. This allows for other logging libraries to use the same281* aborter function by calling this function in liblog.282*283* @param abort_message an additional message supplied when aborting, for example this is used to284* call android_set_abort_message() in __android_log_default_aborter().285*286* Available since API level 30.287*/288void __android_log_call_aborter(const char* abort_message) __INTRODUCED_IN(30);289290/**291* Sets android_set_abort_message() on device then aborts(). This is the default aborter.292*293* @param abort_message an additional message supplied when aborting. This functions calls294* android_set_abort_message() with its contents.295*296* Available since API level 30.297*/298void __android_log_default_aborter(const char* abort_message) __attribute__((noreturn))299__INTRODUCED_IN(30);300301/**302* Use the per-tag properties "log.tag.<tagname>" along with the minimum priority from303* __android_log_set_minimum_priority() to determine if a log message with a given prio and tag will304* be printed. A non-zero result indicates yes, zero indicates false.305*306* If both a priority for a tag and a minimum priority are set by307* __android_log_set_minimum_priority(), then the lowest of the two values are to determine the308* minimum priority needed to log. If only one is set, then that value is used to determine the309* minimum priority needed. If none are set, then default_priority is used.310*311* @param prio the priority to test, takes android_LogPriority values.312* @param tag the tag to test.313* @param default_prio the default priority to use if no properties or minimum priority are set.314* @return an integer where 1 indicates that the message is loggable and 0 indicates that it is not.315*316* Available since API level 30.317*/318int __android_log_is_loggable(int prio, const char* tag, int default_prio) __INTRODUCED_IN(30);319320/**321* Use the per-tag properties "log.tag.<tagname>" along with the minimum priority from322* __android_log_set_minimum_priority() to determine if a log message with a given prio and tag will323* be printed. A non-zero result indicates yes, zero indicates false.324*325* If both a priority for a tag and a minimum priority are set by326* __android_log_set_minimum_priority(), then the lowest of the two values are to determine the327* minimum priority needed to log. If only one is set, then that value is used to determine the328* minimum priority needed. If none are set, then default_priority is used.329*330* @param prio the priority to test, takes android_LogPriority values.331* @param tag the tag to test.332* @param len the length of the tag.333* @param default_prio the default priority to use if no properties or minimum priority are set.334* @return an integer where 1 indicates that the message is loggable and 0 indicates that it is not.335*336* Available since API level 30.337*/338int __android_log_is_loggable_len(int prio, const char* tag, size_t len, int default_prio)339__INTRODUCED_IN(30);340341/**342* Sets the minimum priority that will be logged for this process.343*344* @param priority the new minimum priority to set, takes android_LogPriority values.345* @return the previous set minimum priority as android_LogPriority values, or346* ANDROID_LOG_DEFAULT if none was set.347*348* Available since API level 30.349*/350int32_t __android_log_set_minimum_priority(int32_t priority) __INTRODUCED_IN(30);351352/**353* Gets the minimum priority that will be logged for this process. If none has been set by a354* previous __android_log_set_minimum_priority() call, this returns ANDROID_LOG_DEFAULT.355*356* @return the current minimum priority as android_LogPriority values, or357* ANDROID_LOG_DEFAULT if none is set.358*359* Available since API level 30.360*/361int32_t __android_log_get_minimum_priority(void) __INTRODUCED_IN(30);362363/**364* Sets the default tag if no tag is provided when writing a log message. Defaults to365* getprogname(). This truncates tag to the maximum log message size, though appropriate tags366* should be much smaller.367*368* @param tag the new log tag.369*370* Available since API level 30.371*/372void __android_log_set_default_tag(const char* tag) __INTRODUCED_IN(30);373#endif374375#ifdef __cplusplus376}377#endif378379/** @} */380381382