2013-07-24 01:59:20 +02:00
|
|
|
/*
|
2013-11-22 21:39:43 +01:00
|
|
|
* Copyright (C) 2005-2014 The Android Open Source Project
|
2013-07-24 01:59:20 +02:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
//
|
|
|
|
// C/C++ logging functions. See the logging documentation for API details.
|
|
|
|
//
|
|
|
|
// We'd like these to be available from C code (in case we import some from
|
|
|
|
// somewhere), so this has a C interface.
|
|
|
|
//
|
|
|
|
// The output will be correct when the log file is shared between multiple
|
|
|
|
// threads and/or multiple processes so long as the operating system
|
|
|
|
// supports O_APPEND. These calls have mutex-protected data structures
|
|
|
|
// and so are NOT reentrant. Do not use LOG in a signal handler.
|
|
|
|
//
|
|
|
|
#ifndef _LIBS_LOG_LOG_H
|
|
|
|
#define _LIBS_LOG_LOG_H
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
2013-11-22 19:50:27 +01:00
|
|
|
#include <stdio.h>
|
2015-01-27 04:48:54 +01:00
|
|
|
#include <sys/types.h>
|
2013-11-22 19:50:27 +01:00
|
|
|
#include <time.h>
|
|
|
|
#include <unistd.h>
|
2015-01-27 04:48:54 +01:00
|
|
|
|
2013-07-24 01:59:20 +02:00
|
|
|
#include <log/logd.h>
|
2013-11-22 19:50:27 +01:00
|
|
|
#include <log/uio.h>
|
2013-07-24 01:59:20 +02:00
|
|
|
|
2014-01-04 01:54:28 +01:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
2013-07-24 01:59:20 +02:00
|
|
|
|
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Normally we strip ALOGV (VERBOSE messages) from release builds.
|
|
|
|
* You can modify this (for example with "#define LOG_NDEBUG 0"
|
|
|
|
* at the top of your source file) to change that behavior.
|
|
|
|
*/
|
|
|
|
#ifndef LOG_NDEBUG
|
|
|
|
#ifdef NDEBUG
|
|
|
|
#define LOG_NDEBUG 1
|
|
|
|
#else
|
|
|
|
#define LOG_NDEBUG 0
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is the local tag used for the following simplified
|
|
|
|
* logging macros. You can change this preprocessor definition
|
|
|
|
* before using the other macros to change the tag.
|
|
|
|
*/
|
|
|
|
#ifndef LOG_TAG
|
|
|
|
#define LOG_TAG NULL
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
|
2015-04-10 01:12:58 +02:00
|
|
|
#ifndef __predict_false
|
|
|
|
#define __predict_false(exp) __builtin_expect((exp) != 0, 0)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* -DLINT_RLOG in sources that you want to enforce that all logging
|
|
|
|
* goes to the radio log buffer. If any logging goes to any of the other
|
|
|
|
* log buffers, there will be a compile or link error to highlight the
|
|
|
|
* problem. This is not a replacement for a full audit of the code since
|
|
|
|
* this only catches compiled code, not ifdef'd debug code. Options to
|
|
|
|
* defining this, either temporarily to do a spot check, or permanently
|
|
|
|
* to enforce, in all the communications trees; We have hopes to ensure
|
|
|
|
* that by supplying just the radio log buffer that the communications
|
|
|
|
* teams will have their one-stop shop for triaging issues.
|
|
|
|
*/
|
|
|
|
#ifndef LINT_RLOG
|
|
|
|
|
2013-07-24 01:59:20 +02:00
|
|
|
/*
|
|
|
|
* Simplified macro to send a verbose log message using the current LOG_TAG.
|
|
|
|
*/
|
|
|
|
#ifndef ALOGV
|
2014-02-07 05:07:50 +01:00
|
|
|
#define __ALOGV(...) ((void)ALOG(LOG_VERBOSE, LOG_TAG, __VA_ARGS__))
|
2013-07-24 01:59:20 +02:00
|
|
|
#if LOG_NDEBUG
|
2014-02-07 05:07:50 +01:00
|
|
|
#define ALOGV(...) do { if (0) { __ALOGV(__VA_ARGS__); } } while (0)
|
2013-07-24 01:59:20 +02:00
|
|
|
#else
|
2014-02-07 05:07:50 +01:00
|
|
|
#define ALOGV(...) __ALOGV(__VA_ARGS__)
|
2013-07-24 01:59:20 +02:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef ALOGV_IF
|
|
|
|
#if LOG_NDEBUG
|
|
|
|
#define ALOGV_IF(cond, ...) ((void)0)
|
|
|
|
#else
|
|
|
|
#define ALOGV_IF(cond, ...) \
|
2014-10-08 16:47:08 +02:00
|
|
|
( (__predict_false(cond)) \
|
2013-07-24 01:59:20 +02:00
|
|
|
? ((void)ALOG(LOG_VERBOSE, LOG_TAG, __VA_ARGS__)) \
|
|
|
|
: (void)0 )
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Simplified macro to send a debug log message using the current LOG_TAG.
|
|
|
|
*/
|
|
|
|
#ifndef ALOGD
|
|
|
|
#define ALOGD(...) ((void)ALOG(LOG_DEBUG, LOG_TAG, __VA_ARGS__))
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef ALOGD_IF
|
|
|
|
#define ALOGD_IF(cond, ...) \
|
2014-10-08 16:47:08 +02:00
|
|
|
( (__predict_false(cond)) \
|
2013-07-24 01:59:20 +02:00
|
|
|
? ((void)ALOG(LOG_DEBUG, LOG_TAG, __VA_ARGS__)) \
|
|
|
|
: (void)0 )
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Simplified macro to send an info log message using the current LOG_TAG.
|
|
|
|
*/
|
|
|
|
#ifndef ALOGI
|
|
|
|
#define ALOGI(...) ((void)ALOG(LOG_INFO, LOG_TAG, __VA_ARGS__))
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef ALOGI_IF
|
|
|
|
#define ALOGI_IF(cond, ...) \
|
2014-10-08 16:47:08 +02:00
|
|
|
( (__predict_false(cond)) \
|
2013-07-24 01:59:20 +02:00
|
|
|
? ((void)ALOG(LOG_INFO, LOG_TAG, __VA_ARGS__)) \
|
|
|
|
: (void)0 )
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Simplified macro to send a warning log message using the current LOG_TAG.
|
|
|
|
*/
|
|
|
|
#ifndef ALOGW
|
|
|
|
#define ALOGW(...) ((void)ALOG(LOG_WARN, LOG_TAG, __VA_ARGS__))
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef ALOGW_IF
|
|
|
|
#define ALOGW_IF(cond, ...) \
|
2014-10-08 16:47:08 +02:00
|
|
|
( (__predict_false(cond)) \
|
2013-07-24 01:59:20 +02:00
|
|
|
? ((void)ALOG(LOG_WARN, LOG_TAG, __VA_ARGS__)) \
|
|
|
|
: (void)0 )
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Simplified macro to send an error log message using the current LOG_TAG.
|
|
|
|
*/
|
|
|
|
#ifndef ALOGE
|
|
|
|
#define ALOGE(...) ((void)ALOG(LOG_ERROR, LOG_TAG, __VA_ARGS__))
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef ALOGE_IF
|
|
|
|
#define ALOGE_IF(cond, ...) \
|
2014-10-08 16:47:08 +02:00
|
|
|
( (__predict_false(cond)) \
|
2013-07-24 01:59:20 +02:00
|
|
|
? ((void)ALOG(LOG_ERROR, LOG_TAG, __VA_ARGS__)) \
|
|
|
|
: (void)0 )
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Conditional based on whether the current LOG_TAG is enabled at
|
|
|
|
* verbose priority.
|
|
|
|
*/
|
|
|
|
#ifndef IF_ALOGV
|
|
|
|
#if LOG_NDEBUG
|
|
|
|
#define IF_ALOGV() if (false)
|
|
|
|
#else
|
|
|
|
#define IF_ALOGV() IF_ALOG(LOG_VERBOSE, LOG_TAG)
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Conditional based on whether the current LOG_TAG is enabled at
|
|
|
|
* debug priority.
|
|
|
|
*/
|
|
|
|
#ifndef IF_ALOGD
|
|
|
|
#define IF_ALOGD() IF_ALOG(LOG_DEBUG, LOG_TAG)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Conditional based on whether the current LOG_TAG is enabled at
|
|
|
|
* info priority.
|
|
|
|
*/
|
|
|
|
#ifndef IF_ALOGI
|
|
|
|
#define IF_ALOGI() IF_ALOG(LOG_INFO, LOG_TAG)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Conditional based on whether the current LOG_TAG is enabled at
|
|
|
|
* warn priority.
|
|
|
|
*/
|
|
|
|
#ifndef IF_ALOGW
|
|
|
|
#define IF_ALOGW() IF_ALOG(LOG_WARN, LOG_TAG)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Conditional based on whether the current LOG_TAG is enabled at
|
|
|
|
* error priority.
|
|
|
|
*/
|
|
|
|
#ifndef IF_ALOGE
|
|
|
|
#define IF_ALOGE() IF_ALOG(LOG_ERROR, LOG_TAG)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Simplified macro to send a verbose system log message using the current LOG_TAG.
|
|
|
|
*/
|
|
|
|
#ifndef SLOGV
|
2014-10-08 16:47:08 +02:00
|
|
|
#define __SLOGV(...) \
|
|
|
|
((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__))
|
2013-07-24 01:59:20 +02:00
|
|
|
#if LOG_NDEBUG
|
2014-02-07 05:07:50 +01:00
|
|
|
#define SLOGV(...) do { if (0) { __SLOGV(__VA_ARGS__); } } while (0)
|
2013-07-24 01:59:20 +02:00
|
|
|
#else
|
2014-02-07 05:07:50 +01:00
|
|
|
#define SLOGV(...) __SLOGV(__VA_ARGS__)
|
2013-07-24 01:59:20 +02:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef SLOGV_IF
|
|
|
|
#if LOG_NDEBUG
|
|
|
|
#define SLOGV_IF(cond, ...) ((void)0)
|
|
|
|
#else
|
|
|
|
#define SLOGV_IF(cond, ...) \
|
2014-10-08 16:47:08 +02:00
|
|
|
( (__predict_false(cond)) \
|
2013-07-24 01:59:20 +02:00
|
|
|
? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__)) \
|
|
|
|
: (void)0 )
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Simplified macro to send a debug system log message using the current LOG_TAG.
|
|
|
|
*/
|
|
|
|
#ifndef SLOGD
|
2014-10-08 16:47:08 +02:00
|
|
|
#define SLOGD(...) \
|
|
|
|
((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__))
|
2013-07-24 01:59:20 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef SLOGD_IF
|
|
|
|
#define SLOGD_IF(cond, ...) \
|
2014-10-08 16:47:08 +02:00
|
|
|
( (__predict_false(cond)) \
|
2013-07-24 01:59:20 +02:00
|
|
|
? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)) \
|
|
|
|
: (void)0 )
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Simplified macro to send an info system log message using the current LOG_TAG.
|
|
|
|
*/
|
|
|
|
#ifndef SLOGI
|
2014-10-08 16:47:08 +02:00
|
|
|
#define SLOGI(...) \
|
|
|
|
((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__))
|
2013-07-24 01:59:20 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef SLOGI_IF
|
|
|
|
#define SLOGI_IF(cond, ...) \
|
2014-10-08 16:47:08 +02:00
|
|
|
( (__predict_false(cond)) \
|
2013-07-24 01:59:20 +02:00
|
|
|
? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)) \
|
|
|
|
: (void)0 )
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Simplified macro to send a warning system log message using the current LOG_TAG.
|
|
|
|
*/
|
|
|
|
#ifndef SLOGW
|
2014-10-08 16:47:08 +02:00
|
|
|
#define SLOGW(...) \
|
|
|
|
((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__))
|
2013-07-24 01:59:20 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef SLOGW_IF
|
|
|
|
#define SLOGW_IF(cond, ...) \
|
2014-10-08 16:47:08 +02:00
|
|
|
( (__predict_false(cond)) \
|
2013-07-24 01:59:20 +02:00
|
|
|
? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__)) \
|
|
|
|
: (void)0 )
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Simplified macro to send an error system log message using the current LOG_TAG.
|
|
|
|
*/
|
|
|
|
#ifndef SLOGE
|
2014-10-08 16:47:08 +02:00
|
|
|
#define SLOGE(...) \
|
|
|
|
((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__))
|
2013-07-24 01:59:20 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef SLOGE_IF
|
|
|
|
#define SLOGE_IF(cond, ...) \
|
2014-10-08 16:47:08 +02:00
|
|
|
( (__predict_false(cond)) \
|
2013-07-24 01:59:20 +02:00
|
|
|
? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)) \
|
|
|
|
: (void)0 )
|
|
|
|
#endif
|
|
|
|
|
2015-04-10 01:12:58 +02:00
|
|
|
#endif /* !LINT_RLOG */
|
|
|
|
|
2013-07-24 01:59:20 +02:00
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Simplified macro to send a verbose radio log message using the current LOG_TAG.
|
|
|
|
*/
|
|
|
|
#ifndef RLOGV
|
2014-10-08 16:47:08 +02:00
|
|
|
#define __RLOGV(...) \
|
|
|
|
((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__))
|
2013-07-24 01:59:20 +02:00
|
|
|
#if LOG_NDEBUG
|
2014-02-07 05:07:50 +01:00
|
|
|
#define RLOGV(...) do { if (0) { __RLOGV(__VA_ARGS__); } } while (0)
|
2013-07-24 01:59:20 +02:00
|
|
|
#else
|
2014-02-07 05:07:50 +01:00
|
|
|
#define RLOGV(...) __RLOGV(__VA_ARGS__)
|
2013-07-24 01:59:20 +02:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef RLOGV_IF
|
|
|
|
#if LOG_NDEBUG
|
|
|
|
#define RLOGV_IF(cond, ...) ((void)0)
|
|
|
|
#else
|
|
|
|
#define RLOGV_IF(cond, ...) \
|
2014-10-08 16:47:08 +02:00
|
|
|
( (__predict_false(cond)) \
|
2013-07-24 01:59:20 +02:00
|
|
|
? ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__)) \
|
|
|
|
: (void)0 )
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Simplified macro to send a debug radio log message using the current LOG_TAG.
|
|
|
|
*/
|
|
|
|
#ifndef RLOGD
|
2014-10-08 16:47:08 +02:00
|
|
|
#define RLOGD(...) \
|
|
|
|
((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__))
|
2013-07-24 01:59:20 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef RLOGD_IF
|
|
|
|
#define RLOGD_IF(cond, ...) \
|
2014-10-08 16:47:08 +02:00
|
|
|
( (__predict_false(cond)) \
|
2013-07-24 01:59:20 +02:00
|
|
|
? ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)) \
|
|
|
|
: (void)0 )
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Simplified macro to send an info radio log message using the current LOG_TAG.
|
|
|
|
*/
|
|
|
|
#ifndef RLOGI
|
2014-10-08 16:47:08 +02:00
|
|
|
#define RLOGI(...) \
|
|
|
|
((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__))
|
2013-07-24 01:59:20 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef RLOGI_IF
|
|
|
|
#define RLOGI_IF(cond, ...) \
|
2014-10-08 16:47:08 +02:00
|
|
|
( (__predict_false(cond)) \
|
2013-07-24 01:59:20 +02:00
|
|
|
? ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)) \
|
|
|
|
: (void)0 )
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Simplified macro to send a warning radio log message using the current LOG_TAG.
|
|
|
|
*/
|
|
|
|
#ifndef RLOGW
|
2014-10-08 16:47:08 +02:00
|
|
|
#define RLOGW(...) \
|
|
|
|
((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__))
|
2013-07-24 01:59:20 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef RLOGW_IF
|
|
|
|
#define RLOGW_IF(cond, ...) \
|
2014-10-08 16:47:08 +02:00
|
|
|
( (__predict_false(cond)) \
|
2013-07-24 01:59:20 +02:00
|
|
|
? ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__)) \
|
|
|
|
: (void)0 )
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Simplified macro to send an error radio log message using the current LOG_TAG.
|
|
|
|
*/
|
|
|
|
#ifndef RLOGE
|
2014-10-08 16:47:08 +02:00
|
|
|
#define RLOGE(...) \
|
|
|
|
((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__))
|
2013-07-24 01:59:20 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef RLOGE_IF
|
|
|
|
#define RLOGE_IF(cond, ...) \
|
2014-10-08 16:47:08 +02:00
|
|
|
( (__predict_false(cond)) \
|
2013-07-24 01:59:20 +02:00
|
|
|
? ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)) \
|
|
|
|
: (void)0 )
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Log a fatal error. If the given condition fails, this stops program
|
|
|
|
* execution like a normal assertion, but also generating the given message.
|
|
|
|
* It is NOT stripped from release builds. Note that the condition test
|
|
|
|
* is -inverted- from the normal assert() semantics.
|
|
|
|
*/
|
|
|
|
#ifndef LOG_ALWAYS_FATAL_IF
|
|
|
|
#define LOG_ALWAYS_FATAL_IF(cond, ...) \
|
2014-10-08 16:47:08 +02:00
|
|
|
( (__predict_false(cond)) \
|
2013-07-24 01:59:20 +02:00
|
|
|
? ((void)android_printAssert(#cond, LOG_TAG, ## __VA_ARGS__)) \
|
|
|
|
: (void)0 )
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef LOG_ALWAYS_FATAL
|
|
|
|
#define LOG_ALWAYS_FATAL(...) \
|
|
|
|
( ((void)android_printAssert(NULL, LOG_TAG, ## __VA_ARGS__)) )
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Versions of LOG_ALWAYS_FATAL_IF and LOG_ALWAYS_FATAL that
|
|
|
|
* are stripped out of release builds.
|
|
|
|
*/
|
|
|
|
#if LOG_NDEBUG
|
|
|
|
|
|
|
|
#ifndef LOG_FATAL_IF
|
|
|
|
#define LOG_FATAL_IF(cond, ...) ((void)0)
|
|
|
|
#endif
|
|
|
|
#ifndef LOG_FATAL
|
|
|
|
#define LOG_FATAL(...) ((void)0)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
#ifndef LOG_FATAL_IF
|
|
|
|
#define LOG_FATAL_IF(cond, ...) LOG_ALWAYS_FATAL_IF(cond, ## __VA_ARGS__)
|
|
|
|
#endif
|
|
|
|
#ifndef LOG_FATAL
|
|
|
|
#define LOG_FATAL(...) LOG_ALWAYS_FATAL(__VA_ARGS__)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Assertion that generates a log message when the assertion fails.
|
|
|
|
* Stripped out of release builds. Uses the current LOG_TAG.
|
|
|
|
*/
|
|
|
|
#ifndef ALOG_ASSERT
|
|
|
|
#define ALOG_ASSERT(cond, ...) LOG_FATAL_IF(!(cond), ## __VA_ARGS__)
|
|
|
|
//#define ALOG_ASSERT(cond) LOG_FATAL_IF(!(cond), "Assertion failed: " #cond)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Basic log message macro.
|
|
|
|
*
|
|
|
|
* Example:
|
|
|
|
* ALOG(LOG_WARN, NULL, "Failed with error %d", errno);
|
|
|
|
*
|
|
|
|
* The second argument may be NULL or "" to indicate the "global" tag.
|
|
|
|
*/
|
|
|
|
#ifndef ALOG
|
|
|
|
#define ALOG(priority, tag, ...) \
|
|
|
|
LOG_PRI(ANDROID_##priority, tag, __VA_ARGS__)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Log macro that allows you to specify a number for the priority.
|
|
|
|
*/
|
|
|
|
#ifndef LOG_PRI
|
|
|
|
#define LOG_PRI(priority, tag, ...) \
|
|
|
|
android_printLog(priority, tag, __VA_ARGS__)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Log macro that allows you to pass in a varargs ("args" is a va_list).
|
|
|
|
*/
|
|
|
|
#ifndef LOG_PRI_VA
|
|
|
|
#define LOG_PRI_VA(priority, tag, fmt, args) \
|
|
|
|
android_vprintLog(priority, NULL, tag, fmt, args)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Conditional given a desired logging priority and tag.
|
|
|
|
*/
|
|
|
|
#ifndef IF_ALOG
|
|
|
|
#define IF_ALOG(priority, tag) \
|
|
|
|
if (android_testLog(ANDROID_##priority, tag))
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Event logging.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2016-02-18 01:08:13 +01:00
|
|
|
* Event log entry types.
|
2013-07-24 01:59:20 +02:00
|
|
|
*/
|
|
|
|
typedef enum {
|
2016-02-18 01:08:13 +01:00
|
|
|
/* Special markers for android_log_list_element type */
|
|
|
|
EVENT_TYPE_LIST_STOP = '\n', /* declare end of list */
|
|
|
|
EVENT_TYPE_UNKNOWN = '?', /* protocol error */
|
|
|
|
|
|
|
|
/* must match with declaration in java/android/android/util/EventLog.java */
|
|
|
|
EVENT_TYPE_INT = 0, /* uint32_t */
|
|
|
|
EVENT_TYPE_LONG = 1, /* uint64_t */
|
|
|
|
EVENT_TYPE_STRING = 2,
|
|
|
|
EVENT_TYPE_LIST = 3,
|
|
|
|
EVENT_TYPE_FLOAT = 4,
|
2013-07-24 01:59:20 +02:00
|
|
|
} AndroidEventLogType;
|
2013-11-22 19:50:27 +01:00
|
|
|
#define sizeof_AndroidEventLogType sizeof(typeof_AndroidEventLogType)
|
|
|
|
#define typeof_AndroidEventLogType unsigned char
|
2013-07-24 01:59:20 +02:00
|
|
|
|
|
|
|
#ifndef LOG_EVENT_INT
|
|
|
|
#define LOG_EVENT_INT(_tag, _value) { \
|
|
|
|
int intBuf = _value; \
|
|
|
|
(void) android_btWriteLog(_tag, EVENT_TYPE_INT, &intBuf, \
|
|
|
|
sizeof(intBuf)); \
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#ifndef LOG_EVENT_LONG
|
|
|
|
#define LOG_EVENT_LONG(_tag, _value) { \
|
|
|
|
long long longBuf = _value; \
|
|
|
|
(void) android_btWriteLog(_tag, EVENT_TYPE_LONG, &longBuf, \
|
|
|
|
sizeof(longBuf)); \
|
|
|
|
}
|
|
|
|
#endif
|
2015-04-28 21:47:02 +02:00
|
|
|
#ifndef LOG_EVENT_FLOAT
|
|
|
|
#define LOG_EVENT_FLOAT(_tag, _value) { \
|
|
|
|
float floatBuf = _value; \
|
|
|
|
(void) android_btWriteLog(_tag, EVENT_TYPE_FLOAT, &floatBuf, \
|
|
|
|
sizeof(floatBuf)); \
|
|
|
|
}
|
|
|
|
#endif
|
2013-07-24 01:59:20 +02:00
|
|
|
#ifndef LOG_EVENT_STRING
|
|
|
|
#define LOG_EVENT_STRING(_tag, _value) \
|
2014-07-01 19:57:16 +02:00
|
|
|
(void) __android_log_bswrite(_tag, _value);
|
2013-07-24 01:59:20 +02:00
|
|
|
#endif
|
2016-02-18 01:08:13 +01:00
|
|
|
|
|
|
|
typedef enum log_id {
|
|
|
|
LOG_ID_MIN = 0,
|
|
|
|
|
|
|
|
#ifndef LINT_RLOG
|
|
|
|
LOG_ID_MAIN = 0,
|
|
|
|
#endif
|
|
|
|
LOG_ID_RADIO = 1,
|
|
|
|
#ifndef LINT_RLOG
|
|
|
|
LOG_ID_EVENTS = 2,
|
|
|
|
LOG_ID_SYSTEM = 3,
|
|
|
|
LOG_ID_CRASH = 4,
|
|
|
|
LOG_ID_SECURITY = 5,
|
|
|
|
LOG_ID_KERNEL = 6, /* place last, third-parties can not use it */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
LOG_ID_MAX
|
|
|
|
} log_id_t;
|
|
|
|
#define sizeof_log_id_t sizeof(typeof_log_id_t)
|
|
|
|
#define typeof_log_id_t unsigned char
|
|
|
|
|
|
|
|
/* For manipulating lists of events. */
|
|
|
|
|
|
|
|
#define ANDROID_MAX_LIST_NEST_DEPTH 8
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The opaque context used to manipulate lists of events.
|
|
|
|
*/
|
|
|
|
typedef struct android_log_context_internal *android_log_context;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Elements returned when reading a list of events.
|
|
|
|
*/
|
|
|
|
typedef struct {
|
|
|
|
AndroidEventLogType type;
|
|
|
|
uint16_t complete;
|
|
|
|
uint16_t len;
|
|
|
|
union {
|
|
|
|
int32_t int32;
|
|
|
|
int64_t int64;
|
|
|
|
char *string;
|
|
|
|
float float32;
|
|
|
|
} data;
|
|
|
|
} android_log_list_element;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Creates a context associated with an event tag to write elements to
|
|
|
|
* the list of events.
|
|
|
|
*/
|
|
|
|
android_log_context create_android_logger(uint32_t tag);
|
|
|
|
|
|
|
|
/* All lists must be braced by a begin and end call */
|
|
|
|
/*
|
|
|
|
* NB: If the first level braces are missing when specifying multiple
|
|
|
|
* elements, we will manufacturer a list to embrace it for your API
|
|
|
|
* convenience. For a single element, it will remain solitary.
|
|
|
|
*/
|
|
|
|
int android_log_write_list_begin(android_log_context ctx);
|
|
|
|
int android_log_write_list_end(android_log_context ctx);
|
|
|
|
|
|
|
|
int android_log_write_int32(android_log_context ctx, int32_t value);
|
|
|
|
int android_log_write_int64(android_log_context ctx, int64_t value);
|
|
|
|
int android_log_write_string8(android_log_context ctx, const char *value);
|
2016-02-25 17:41:25 +01:00
|
|
|
int android_log_write_string8_len(android_log_context ctx,
|
|
|
|
const char *value, size_t maxlen);
|
2016-02-18 01:08:13 +01:00
|
|
|
int android_log_write_float32(android_log_context ctx, float value);
|
|
|
|
|
|
|
|
/* Submit the composed list context to the specified logger id */
|
|
|
|
/* NB: LOG_ID_EVENTS and LOG_ID_SECURITY only valid binary buffers */
|
|
|
|
int android_log_write_list(android_log_context ctx, log_id_t id);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Creates a context from a raw buffer representing a list of events to be read.
|
|
|
|
*/
|
|
|
|
android_log_context create_android_log_parser(const char *msg, size_t len);
|
|
|
|
|
|
|
|
android_log_list_element android_log_read_next(android_log_context ctx);
|
|
|
|
android_log_list_element android_log_peek_next(android_log_context ctx);
|
|
|
|
|
|
|
|
/* Finished with reader or writer context */
|
|
|
|
int android_log_destroy(android_log_context *ctx);
|
2013-07-24 01:59:20 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* ===========================================================================
|
|
|
|
*
|
|
|
|
* The stuff in the rest of this file should not be used directly.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define android_printLog(prio, tag, fmt...) \
|
|
|
|
__android_log_print(prio, tag, fmt)
|
|
|
|
|
|
|
|
#define android_vprintLog(prio, cond, tag, fmt...) \
|
|
|
|
__android_log_vprint(prio, tag, fmt)
|
|
|
|
|
|
|
|
/* XXX Macros to work around syntax errors in places where format string
|
|
|
|
* arg is not passed to ALOG_ASSERT, LOG_ALWAYS_FATAL or LOG_ALWAYS_FATAL_IF
|
|
|
|
* (happens only in debug builds).
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Returns 2nd arg. Used to substitute default value if caller's vararg list
|
|
|
|
* is empty.
|
|
|
|
*/
|
|
|
|
#define __android_second(dummy, second, ...) second
|
|
|
|
|
|
|
|
/* If passed multiple args, returns ',' followed by all but 1st arg, otherwise
|
|
|
|
* returns nothing.
|
|
|
|
*/
|
|
|
|
#define __android_rest(first, ...) , ## __VA_ARGS__
|
|
|
|
|
|
|
|
#define android_printAssert(cond, tag, fmt...) \
|
|
|
|
__android_log_assert(cond, tag, \
|
|
|
|
__android_second(0, ## fmt, NULL) __android_rest(fmt))
|
|
|
|
|
|
|
|
#define android_writeLog(prio, tag, text) \
|
|
|
|
__android_log_write(prio, tag, text)
|
|
|
|
|
|
|
|
#define android_bWriteLog(tag, payload, len) \
|
|
|
|
__android_log_bwrite(tag, payload, len)
|
|
|
|
#define android_btWriteLog(tag, type, payload, len) \
|
|
|
|
__android_log_btwrite(tag, type, payload, len)
|
|
|
|
|
2015-08-13 19:41:58 +02:00
|
|
|
#define android_errorWriteLog(tag, subTag) \
|
|
|
|
__android_log_error_write(tag, subTag, -1, NULL, 0)
|
|
|
|
|
|
|
|
#define android_errorWriteWithInfoLog(tag, subTag, uid, data, dataLen) \
|
|
|
|
__android_log_error_write(tag, subTag, uid, data, dataLen)
|
|
|
|
|
2015-02-10 00:15:56 +01:00
|
|
|
/*
|
|
|
|
* IF_ALOG uses android_testLog, but IF_ALOG can be overridden.
|
|
|
|
* android_testLog will remain constant in its purpose as a wrapper
|
|
|
|
* for Android logging filter policy, and can be subject to
|
|
|
|
* change. It can be reused by the developers that override
|
|
|
|
* IF_ALOG as a convenient means to reimplement their policy
|
|
|
|
* over Android.
|
|
|
|
*/
|
2015-02-10 01:13:33 +01:00
|
|
|
#if LOG_NDEBUG /* Production */
|
2015-02-10 00:15:56 +01:00
|
|
|
#define android_testLog(prio, tag) \
|
|
|
|
(__android_log_is_loggable(prio, tag, ANDROID_LOG_DEBUG) != 0)
|
|
|
|
#else
|
|
|
|
#define android_testLog(prio, tag) \
|
|
|
|
(__android_log_is_loggable(prio, tag, ANDROID_LOG_VERBOSE) != 0)
|
|
|
|
#endif
|
|
|
|
|
2014-10-02 20:12:28 +02:00
|
|
|
/*
|
|
|
|
* Use the per-tag properties "log.tag.<tagname>" to generate a runtime
|
2015-11-06 21:26:52 +01:00
|
|
|
* result of non-zero to expose a log. prio is ANDROID_LOG_VERBOSE to
|
|
|
|
* ANDROID_LOG_FATAL. default_prio if no property. Undefined behavior if
|
|
|
|
* any other value.
|
2014-10-02 20:12:28 +02:00
|
|
|
*/
|
2015-11-06 21:26:52 +01:00
|
|
|
int __android_log_is_loggable(int prio, const char *tag, int default_prio);
|
2014-10-02 20:12:28 +02:00
|
|
|
|
2015-12-04 19:59:45 +01:00
|
|
|
int __android_log_security(); /* Device Owner is present */
|
|
|
|
|
2015-08-13 19:41:58 +02:00
|
|
|
int __android_log_error_write(int tag, const char *subTag, int32_t uid, const char *data,
|
|
|
|
uint32_t dataLen);
|
|
|
|
|
2013-07-24 01:59:20 +02:00
|
|
|
/*
|
|
|
|
* Send a simple string to the log.
|
|
|
|
*/
|
|
|
|
int __android_log_buf_write(int bufID, int prio, const char *tag, const char *text);
|
2014-02-07 05:07:50 +01:00
|
|
|
int __android_log_buf_print(int bufID, int prio, const char *tag, const char *fmt, ...)
|
|
|
|
#if defined(__GNUC__)
|
|
|
|
__attribute__((__format__(printf, 4, 5)))
|
|
|
|
#endif
|
|
|
|
;
|
2013-07-24 01:59:20 +02:00
|
|
|
|
2014-01-04 01:54:28 +01:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
2013-07-24 01:59:20 +02:00
|
|
|
|
2013-11-22 21:39:43 +01:00
|
|
|
#endif /* _LIBS_LOG_LOG_H */
|