1dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project/*
2dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project * Copyright (C) 2005 The Android Open Source Project
3dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project *
4dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project * Licensed under the Apache License, Version 2.0 (the "License");
5dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project * you may not use this file except in compliance with the License.
6dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project * You may obtain a copy of the License at
7dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project *
8dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project *      http://www.apache.org/licenses/LICENSE-2.0
9dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project *
10dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project * Unless required by applicable law or agreed to in writing, software
11dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project * distributed under the License is distributed on an "AS IS" BASIS,
12dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project * See the License for the specific language governing permissions and
14dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project * limitations under the License.
15dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project */
16dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
17dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project//
18dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project// C/C++ logging functions.  See the logging documentation for API details.
19dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project//
20dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project// We'd like these to be available from C code (in case we import some from
21dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project// somewhere), so this has a C interface.
22dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project//
23dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project// The output will be correct when the log file is shared between multiple
24dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project// threads and/or multiple processes so long as the operating system
25dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project// supports O_APPEND.  These calls have mutex-protected data structures
26dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project// and so are NOT reentrant.  Do not use LOG in a signal handler.
27dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project//
28dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#ifndef _LIBS_CUTILS_LOG_H
29dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#define _LIBS_CUTILS_LOG_H
30dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
31dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#include <stdio.h>
32dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#include <time.h>
33dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#include <sys/types.h>
34dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#include <unistd.h>
35dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#ifdef HAVE_PTHREADS
36dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#include <pthread.h>
37dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#endif
38dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#include <stdarg.h>
39dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
40dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#include <cutils/uio.h>
41dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#include <cutils/logd.h>
42dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
43dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#ifdef __cplusplus
44dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectextern "C" {
45dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#endif
46dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
47dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project// ---------------------------------------------------------------------
48dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
49dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project/*
5069f4cd7f5add7a7c7f5915e5292aab7eb2a42e9fSteve Block * Normally we strip ALOGV (VERBOSE messages) from release builds.
51dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project * You can modify this (for example with "#define LOG_NDEBUG 0"
52dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project * at the top of your source file) to change that behavior.
53dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project */
54dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#ifndef LOG_NDEBUG
55dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#ifdef NDEBUG
56dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#define LOG_NDEBUG 1
57dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#else
58dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#define LOG_NDEBUG 0
59dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#endif
60dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#endif
61dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
62dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project/*
63dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project * This is the local tag used for the following simplified
64dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project * logging macros.  You can change this preprocessor definition
65dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project * before using the other macros to change the tag.
66dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project */
67dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#ifndef LOG_TAG
68dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#define LOG_TAG NULL
69dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#endif
70dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
71dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project// ---------------------------------------------------------------------
72dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
73dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project/*
74dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project * Simplified macro to send a verbose log message using the current LOG_TAG.
75dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project */
7669f4cd7f5add7a7c7f5915e5292aab7eb2a42e9fSteve Block#ifndef ALOGV
77dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#if LOG_NDEBUG
7869f4cd7f5add7a7c7f5915e5292aab7eb2a42e9fSteve Block#define ALOGV(...)   ((void)0)
79dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#else
8069f4cd7f5add7a7c7f5915e5292aab7eb2a42e9fSteve Block#define ALOGV(...) ((void)ALOG(LOG_VERBOSE, LOG_TAG, __VA_ARGS__))
81dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#endif
82dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#endif
83dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
84dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#define CONDITION(cond)     (__builtin_expect((cond)!=0, 0))
85dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
8669f4cd7f5add7a7c7f5915e5292aab7eb2a42e9fSteve Block#ifndef ALOGV_IF
87dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#if LOG_NDEBUG
8869f4cd7f5add7a7c7f5915e5292aab7eb2a42e9fSteve Block#define ALOGV_IF(cond, ...)   ((void)0)
89dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#else
9069f4cd7f5add7a7c7f5915e5292aab7eb2a42e9fSteve Block#define ALOGV_IF(cond, ...) \
91dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    ( (CONDITION(cond)) \
925fb44952f6584e7cdeeafb82beb878c3e7546cfdSteve Block    ? ((void)ALOG(LOG_VERBOSE, LOG_TAG, __VA_ARGS__)) \
93dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    : (void)0 )
94dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#endif
95dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#endif
96dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
97dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project/*
98dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project * Simplified macro to send a debug log message using the current LOG_TAG.
99dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project */
1008d66c49258ac4f59bd67c23c9c914cca81f85b01Steve Block#ifndef ALOGD
1018d66c49258ac4f59bd67c23c9c914cca81f85b01Steve Block#define ALOGD(...) ((void)ALOG(LOG_DEBUG, LOG_TAG, __VA_ARGS__))
102dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#endif
103dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
1048d66c49258ac4f59bd67c23c9c914cca81f85b01Steve Block#ifndef ALOGD_IF
1058d66c49258ac4f59bd67c23c9c914cca81f85b01Steve Block#define ALOGD_IF(cond, ...) \
106dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    ( (CONDITION(cond)) \
1075fb44952f6584e7cdeeafb82beb878c3e7546cfdSteve Block    ? ((void)ALOG(LOG_DEBUG, LOG_TAG, __VA_ARGS__)) \
108dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    : (void)0 )
109dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#endif
110dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
111dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project/*
112dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project * Simplified macro to send an info log message using the current LOG_TAG.
113dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project */
114fe71a61e5b0cb666675900d206251a7c18ed944bSteve Block#ifndef ALOGI
115fe71a61e5b0cb666675900d206251a7c18ed944bSteve Block#define ALOGI(...) ((void)ALOG(LOG_INFO, LOG_TAG, __VA_ARGS__))
116dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#endif
117dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
118fe71a61e5b0cb666675900d206251a7c18ed944bSteve Block#ifndef ALOGI_IF
119fe71a61e5b0cb666675900d206251a7c18ed944bSteve Block#define ALOGI_IF(cond, ...) \
120dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    ( (CONDITION(cond)) \
1215fb44952f6584e7cdeeafb82beb878c3e7546cfdSteve Block    ? ((void)ALOG(LOG_INFO, LOG_TAG, __VA_ARGS__)) \
122dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    : (void)0 )
123dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#endif
124dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
125dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project/*
126dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project * Simplified macro to send a warning log message using the current LOG_TAG.
127dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project */
128ae8b56c0d17a97aff0b98e6405c7cc9811bbbc3dSteve Block#ifndef ALOGW
129ae8b56c0d17a97aff0b98e6405c7cc9811bbbc3dSteve Block#define ALOGW(...) ((void)ALOG(LOG_WARN, LOG_TAG, __VA_ARGS__))
130dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#endif
131dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
132ae8b56c0d17a97aff0b98e6405c7cc9811bbbc3dSteve Block#ifndef ALOGW_IF
133ae8b56c0d17a97aff0b98e6405c7cc9811bbbc3dSteve Block#define ALOGW_IF(cond, ...) \
134dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    ( (CONDITION(cond)) \
1355fb44952f6584e7cdeeafb82beb878c3e7546cfdSteve Block    ? ((void)ALOG(LOG_WARN, LOG_TAG, __VA_ARGS__)) \
136dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    : (void)0 )
137dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#endif
138dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
139dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project/*
140dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project * Simplified macro to send an error log message using the current LOG_TAG.
141dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project */
14201dda204cd28fe181691b4a44a51be7e5666d0c8Steve Block#ifndef ALOGE
14301dda204cd28fe181691b4a44a51be7e5666d0c8Steve Block#define ALOGE(...) ((void)ALOG(LOG_ERROR, LOG_TAG, __VA_ARGS__))
144dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#endif
145dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
14601dda204cd28fe181691b4a44a51be7e5666d0c8Steve Block#ifndef ALOGE_IF
14701dda204cd28fe181691b4a44a51be7e5666d0c8Steve Block#define ALOGE_IF(cond, ...) \
148dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    ( (CONDITION(cond)) \
1495fb44952f6584e7cdeeafb82beb878c3e7546cfdSteve Block    ? ((void)ALOG(LOG_ERROR, LOG_TAG, __VA_ARGS__)) \
150dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    : (void)0 )
151dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#endif
152dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
153dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project// ---------------------------------------------------------------------
154dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
155dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project/*
156dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project * Conditional based on whether the current LOG_TAG is enabled at
157dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project * verbose priority.
158dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project */
15969f4cd7f5add7a7c7f5915e5292aab7eb2a42e9fSteve Block#ifndef IF_ALOGV
160dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#if LOG_NDEBUG
16169f4cd7f5add7a7c7f5915e5292aab7eb2a42e9fSteve Block#define IF_ALOGV() if (false)
162dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#else
16369f4cd7f5add7a7c7f5915e5292aab7eb2a42e9fSteve Block#define IF_ALOGV() IF_ALOG(LOG_VERBOSE, LOG_TAG)
164dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#endif
165dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#endif
166dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
167dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project/*
168dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project * Conditional based on whether the current LOG_TAG is enabled at
169dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project * debug priority.
170dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project */
1718d66c49258ac4f59bd67c23c9c914cca81f85b01Steve Block#ifndef IF_ALOGD
1728d66c49258ac4f59bd67c23c9c914cca81f85b01Steve Block#define IF_ALOGD() IF_ALOG(LOG_DEBUG, LOG_TAG)
173dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#endif
174dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
175dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project/*
176dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project * Conditional based on whether the current LOG_TAG is enabled at
177dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project * info priority.
178dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project */
179fe71a61e5b0cb666675900d206251a7c18ed944bSteve Block#ifndef IF_ALOGI
180fe71a61e5b0cb666675900d206251a7c18ed944bSteve Block#define IF_ALOGI() IF_ALOG(LOG_INFO, LOG_TAG)
181dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#endif
182dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
183dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project/*
184dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project * Conditional based on whether the current LOG_TAG is enabled at
185dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project * warn priority.
186dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project */
187ae8b56c0d17a97aff0b98e6405c7cc9811bbbc3dSteve Block#ifndef IF_ALOGW
188ae8b56c0d17a97aff0b98e6405c7cc9811bbbc3dSteve Block#define IF_ALOGW() IF_ALOG(LOG_WARN, LOG_TAG)
189dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#endif
190dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
191dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project/*
192dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project * Conditional based on whether the current LOG_TAG is enabled at
193dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project * error priority.
194dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project */
19501dda204cd28fe181691b4a44a51be7e5666d0c8Steve Block#ifndef IF_ALOGE
19601dda204cd28fe181691b4a44a51be7e5666d0c8Steve Block#define IF_ALOGE() IF_ALOG(LOG_ERROR, LOG_TAG)
197dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#endif
198dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
199e2bf2ea4d2846031edfc52b942ad53e5467243f6Joe Onorato
200e2bf2ea4d2846031edfc52b942ad53e5467243f6Joe Onorato// ---------------------------------------------------------------------
201e2bf2ea4d2846031edfc52b942ad53e5467243f6Joe Onorato
202e2bf2ea4d2846031edfc52b942ad53e5467243f6Joe Onorato/*
203e2bf2ea4d2846031edfc52b942ad53e5467243f6Joe Onorato * Simplified macro to send a verbose system log message using the current LOG_TAG.
204e2bf2ea4d2846031edfc52b942ad53e5467243f6Joe Onorato */
205e2bf2ea4d2846031edfc52b942ad53e5467243f6Joe Onorato#ifndef SLOGV
206e2bf2ea4d2846031edfc52b942ad53e5467243f6Joe Onorato#if LOG_NDEBUG
207e2bf2ea4d2846031edfc52b942ad53e5467243f6Joe Onorato#define SLOGV(...)   ((void)0)
208e2bf2ea4d2846031edfc52b942ad53e5467243f6Joe Onorato#else
209e2bf2ea4d2846031edfc52b942ad53e5467243f6Joe Onorato#define SLOGV(...) ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__))
210e2bf2ea4d2846031edfc52b942ad53e5467243f6Joe Onorato#endif
211e2bf2ea4d2846031edfc52b942ad53e5467243f6Joe Onorato#endif
212e2bf2ea4d2846031edfc52b942ad53e5467243f6Joe Onorato
213e2bf2ea4d2846031edfc52b942ad53e5467243f6Joe Onorato#define CONDITION(cond)     (__builtin_expect((cond)!=0, 0))
214e2bf2ea4d2846031edfc52b942ad53e5467243f6Joe Onorato
215e2bf2ea4d2846031edfc52b942ad53e5467243f6Joe Onorato#ifndef SLOGV_IF
216e2bf2ea4d2846031edfc52b942ad53e5467243f6Joe Onorato#if LOG_NDEBUG
217e2bf2ea4d2846031edfc52b942ad53e5467243f6Joe Onorato#define SLOGV_IF(cond, ...)   ((void)0)
218e2bf2ea4d2846031edfc52b942ad53e5467243f6Joe Onorato#else
219e2bf2ea4d2846031edfc52b942ad53e5467243f6Joe Onorato#define SLOGV_IF(cond, ...) \
220e2bf2ea4d2846031edfc52b942ad53e5467243f6Joe Onorato    ( (CONDITION(cond)) \
221e2bf2ea4d2846031edfc52b942ad53e5467243f6Joe Onorato    ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__)) \
222e2bf2ea4d2846031edfc52b942ad53e5467243f6Joe Onorato    : (void)0 )
223e2bf2ea4d2846031edfc52b942ad53e5467243f6Joe Onorato#endif
224e2bf2ea4d2846031edfc52b942ad53e5467243f6Joe Onorato#endif
225e2bf2ea4d2846031edfc52b942ad53e5467243f6Joe Onorato
226e2bf2ea4d2846031edfc52b942ad53e5467243f6Joe Onorato/*
227e2bf2ea4d2846031edfc52b942ad53e5467243f6Joe Onorato * Simplified macro to send a debug system log message using the current LOG_TAG.
228e2bf2ea4d2846031edfc52b942ad53e5467243f6Joe Onorato */
229e2bf2ea4d2846031edfc52b942ad53e5467243f6Joe Onorato#ifndef SLOGD
230e2bf2ea4d2846031edfc52b942ad53e5467243f6Joe Onorato#define SLOGD(...) ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__))
231e2bf2ea4d2846031edfc52b942ad53e5467243f6Joe Onorato#endif
232e2bf2ea4d2846031edfc52b942ad53e5467243f6Joe Onorato
233e2bf2ea4d2846031edfc52b942ad53e5467243f6Joe Onorato#ifndef SLOGD_IF
234e2bf2ea4d2846031edfc52b942ad53e5467243f6Joe Onorato#define SLOGD_IF(cond, ...) \
235e2bf2ea4d2846031edfc52b942ad53e5467243f6Joe Onorato    ( (CONDITION(cond)) \
236e2bf2ea4d2846031edfc52b942ad53e5467243f6Joe Onorato    ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)) \
237e2bf2ea4d2846031edfc52b942ad53e5467243f6Joe Onorato    : (void)0 )
238e2bf2ea4d2846031edfc52b942ad53e5467243f6Joe Onorato#endif
239e2bf2ea4d2846031edfc52b942ad53e5467243f6Joe Onorato
240e2bf2ea4d2846031edfc52b942ad53e5467243f6Joe Onorato/*
241e2bf2ea4d2846031edfc52b942ad53e5467243f6Joe Onorato * Simplified macro to send an info system log message using the current LOG_TAG.
242e2bf2ea4d2846031edfc52b942ad53e5467243f6Joe Onorato */
243e2bf2ea4d2846031edfc52b942ad53e5467243f6Joe Onorato#ifndef SLOGI
244e2bf2ea4d2846031edfc52b942ad53e5467243f6Joe Onorato#define SLOGI(...) ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__))
245e2bf2ea4d2846031edfc52b942ad53e5467243f6Joe Onorato#endif
246e2bf2ea4d2846031edfc52b942ad53e5467243f6Joe Onorato
247e2bf2ea4d2846031edfc52b942ad53e5467243f6Joe Onorato#ifndef SLOGI_IF
248e2bf2ea4d2846031edfc52b942ad53e5467243f6Joe Onorato#define SLOGI_IF(cond, ...) \
249e2bf2ea4d2846031edfc52b942ad53e5467243f6Joe Onorato    ( (CONDITION(cond)) \
250e2bf2ea4d2846031edfc52b942ad53e5467243f6Joe Onorato    ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)) \
251e2bf2ea4d2846031edfc52b942ad53e5467243f6Joe Onorato    : (void)0 )
252e2bf2ea4d2846031edfc52b942ad53e5467243f6Joe Onorato#endif
253e2bf2ea4d2846031edfc52b942ad53e5467243f6Joe Onorato
254e2bf2ea4d2846031edfc52b942ad53e5467243f6Joe Onorato/*
255e2bf2ea4d2846031edfc52b942ad53e5467243f6Joe Onorato * Simplified macro to send a warning system log message using the current LOG_TAG.
256e2bf2ea4d2846031edfc52b942ad53e5467243f6Joe Onorato */
257e2bf2ea4d2846031edfc52b942ad53e5467243f6Joe Onorato#ifndef SLOGW
258e2bf2ea4d2846031edfc52b942ad53e5467243f6Joe Onorato#define SLOGW(...) ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__))
259e2bf2ea4d2846031edfc52b942ad53e5467243f6Joe Onorato#endif
260e2bf2ea4d2846031edfc52b942ad53e5467243f6Joe Onorato
261e2bf2ea4d2846031edfc52b942ad53e5467243f6Joe Onorato#ifndef SLOGW_IF
262e2bf2ea4d2846031edfc52b942ad53e5467243f6Joe Onorato#define SLOGW_IF(cond, ...) \
263e2bf2ea4d2846031edfc52b942ad53e5467243f6Joe Onorato    ( (CONDITION(cond)) \
264e2bf2ea4d2846031edfc52b942ad53e5467243f6Joe Onorato    ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__)) \
265e2bf2ea4d2846031edfc52b942ad53e5467243f6Joe Onorato    : (void)0 )
266e2bf2ea4d2846031edfc52b942ad53e5467243f6Joe Onorato#endif
267e2bf2ea4d2846031edfc52b942ad53e5467243f6Joe Onorato
268e2bf2ea4d2846031edfc52b942ad53e5467243f6Joe Onorato/*
269e2bf2ea4d2846031edfc52b942ad53e5467243f6Joe Onorato * Simplified macro to send an error system log message using the current LOG_TAG.
270e2bf2ea4d2846031edfc52b942ad53e5467243f6Joe Onorato */
271e2bf2ea4d2846031edfc52b942ad53e5467243f6Joe Onorato#ifndef SLOGE
272e2bf2ea4d2846031edfc52b942ad53e5467243f6Joe Onorato#define SLOGE(...) ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__))
273e2bf2ea4d2846031edfc52b942ad53e5467243f6Joe Onorato#endif
274e2bf2ea4d2846031edfc52b942ad53e5467243f6Joe Onorato
275e2bf2ea4d2846031edfc52b942ad53e5467243f6Joe Onorato#ifndef SLOGE_IF
276e2bf2ea4d2846031edfc52b942ad53e5467243f6Joe Onorato#define SLOGE_IF(cond, ...) \
277e2bf2ea4d2846031edfc52b942ad53e5467243f6Joe Onorato    ( (CONDITION(cond)) \
278e2bf2ea4d2846031edfc52b942ad53e5467243f6Joe Onorato    ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)) \
279e2bf2ea4d2846031edfc52b942ad53e5467243f6Joe Onorato    : (void)0 )
280e2bf2ea4d2846031edfc52b942ad53e5467243f6Joe Onorato#endif
281e2bf2ea4d2846031edfc52b942ad53e5467243f6Joe Onorato
282e2bf2ea4d2846031edfc52b942ad53e5467243f6Joe Onorato
283e2bf2ea4d2846031edfc52b942ad53e5467243f6Joe Onorato
284dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project// ---------------------------------------------------------------------
285dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
286dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project/*
287dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project * Log a fatal error.  If the given condition fails, this stops program
288dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project * execution like a normal assertion, but also generating the given message.
289dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project * It is NOT stripped from release builds.  Note that the condition test
290dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project * is -inverted- from the normal assert() semantics.
291dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project */
292412514ea60a707cefb42f2609a3422223bd86381Alexandre Elias#ifndef LOG_ALWAYS_FATAL_IF
293dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#define LOG_ALWAYS_FATAL_IF(cond, ...) \
294dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    ( (CONDITION(cond)) \
29519299904343daf191267564fe32e6cd5c165cd42Chris Pearson    ? ((void)android_printAssert(#cond, LOG_TAG, ## __VA_ARGS__)) \
296dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    : (void)0 )
297412514ea60a707cefb42f2609a3422223bd86381Alexandre Elias#endif
298dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
299412514ea60a707cefb42f2609a3422223bd86381Alexandre Elias#ifndef LOG_ALWAYS_FATAL
300dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#define LOG_ALWAYS_FATAL(...) \
30119299904343daf191267564fe32e6cd5c165cd42Chris Pearson    ( ((void)android_printAssert(NULL, LOG_TAG, ## __VA_ARGS__)) )
302412514ea60a707cefb42f2609a3422223bd86381Alexandre Elias#endif
303dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
304dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project/*
305dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project * Versions of LOG_ALWAYS_FATAL_IF and LOG_ALWAYS_FATAL that
306dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project * are stripped out of release builds.
307dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project */
308dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#if LOG_NDEBUG
309dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
310412514ea60a707cefb42f2609a3422223bd86381Alexandre Elias#ifndef LOG_FATAL_IF
311dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#define LOG_FATAL_IF(cond, ...) ((void)0)
312412514ea60a707cefb42f2609a3422223bd86381Alexandre Elias#endif
313412514ea60a707cefb42f2609a3422223bd86381Alexandre Elias#ifndef LOG_FATAL
314dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#define LOG_FATAL(...) ((void)0)
315412514ea60a707cefb42f2609a3422223bd86381Alexandre Elias#endif
316dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
317dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#else
318dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
319412514ea60a707cefb42f2609a3422223bd86381Alexandre Elias#ifndef LOG_FATAL_IF
32019299904343daf191267564fe32e6cd5c165cd42Chris Pearson#define LOG_FATAL_IF(cond, ...) LOG_ALWAYS_FATAL_IF(cond, ## __VA_ARGS__)
321412514ea60a707cefb42f2609a3422223bd86381Alexandre Elias#endif
322412514ea60a707cefb42f2609a3422223bd86381Alexandre Elias#ifndef LOG_FATAL
323dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#define LOG_FATAL(...) LOG_ALWAYS_FATAL(__VA_ARGS__)
324412514ea60a707cefb42f2609a3422223bd86381Alexandre Elias#endif
325dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
326dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#endif
327dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
328dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project/*
329dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project * Assertion that generates a log message when the assertion fails.
330dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project * Stripped out of release builds.  Uses the current LOG_TAG.
331dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project */
332ceabb17306f4de9850516dae96bb0d2d5853f028Steve Block#ifndef ALOG_ASSERT
333ceabb17306f4de9850516dae96bb0d2d5853f028Steve Block#define ALOG_ASSERT(cond, ...) LOG_FATAL_IF(!(cond), ## __VA_ARGS__)
334ceabb17306f4de9850516dae96bb0d2d5853f028Steve Block//#define ALOG_ASSERT(cond) LOG_FATAL_IF(!(cond), "Assertion failed: " #cond)
335412514ea60a707cefb42f2609a3422223bd86381Alexandre Elias#endif
336dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
337dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project// ---------------------------------------------------------------------
338dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
339dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project/*
340dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project * Basic log message macro.
341dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project *
342dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project * Example:
3435fb44952f6584e7cdeeafb82beb878c3e7546cfdSteve Block *  ALOG(LOG_WARN, NULL, "Failed with error %d", errno);
344dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project *
345dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project * The second argument may be NULL or "" to indicate the "global" tag.
346dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project */
3475fb44952f6584e7cdeeafb82beb878c3e7546cfdSteve Block#ifndef ALOG
3485fb44952f6584e7cdeeafb82beb878c3e7546cfdSteve Block#define ALOG(priority, tag, ...) \
349dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    LOG_PRI(ANDROID_##priority, tag, __VA_ARGS__)
350dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#endif
351dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
352dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project/*
353dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project * Log macro that allows you to specify a number for the priority.
354dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project */
355dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#ifndef LOG_PRI
356dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#define LOG_PRI(priority, tag, ...) \
357dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    android_printLog(priority, tag, __VA_ARGS__)
358dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#endif
359dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
360dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project/*
361dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project * Log macro that allows you to pass in a varargs ("args" is a va_list).
362dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project */
363dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#ifndef LOG_PRI_VA
364dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#define LOG_PRI_VA(priority, tag, fmt, args) \
365dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    android_vprintLog(priority, NULL, tag, fmt, args)
366dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#endif
367dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
368dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project/*
369dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project * Conditional given a desired logging priority and tag.
370dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project */
3715fb44952f6584e7cdeeafb82beb878c3e7546cfdSteve Block#ifndef IF_ALOG
3725fb44952f6584e7cdeeafb82beb878c3e7546cfdSteve Block#define IF_ALOG(priority, tag) \
373dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    if (android_testLog(ANDROID_##priority, tag))
374dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#endif
375dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
376dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project// ---------------------------------------------------------------------
377dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
378dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project/*
379dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project * Event logging.
380dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project */
381dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
382dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project/*
383dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project * Event log entry types.  These must match up with the declarations in
384dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project * java/android/android/util/EventLog.java.
385dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project */
386dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projecttypedef enum {
387dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    EVENT_TYPE_INT      = 0,
388dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    EVENT_TYPE_LONG     = 1,
389dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    EVENT_TYPE_STRING   = 2,
390dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    EVENT_TYPE_LIST     = 3,
391dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project} AndroidEventLogType;
392dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
393dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
394412514ea60a707cefb42f2609a3422223bd86381Alexandre Elias#ifndef LOG_EVENT_INT
395dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#define LOG_EVENT_INT(_tag, _value) {                                       \
396dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        int intBuf = _value;                                                \
397dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        (void) android_btWriteLog(_tag, EVENT_TYPE_INT, &intBuf,            \
398dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            sizeof(intBuf));                                                \
399dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    }
400412514ea60a707cefb42f2609a3422223bd86381Alexandre Elias#endif
401412514ea60a707cefb42f2609a3422223bd86381Alexandre Elias#ifndef LOG_EVENT_LONG
402dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#define LOG_EVENT_LONG(_tag, _value) {                                      \
403dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        long long longBuf = _value;                                         \
404dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        (void) android_btWriteLog(_tag, EVENT_TYPE_LONG, &longBuf,          \
405dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            sizeof(longBuf));                                               \
406dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    }
407412514ea60a707cefb42f2609a3422223bd86381Alexandre Elias#endif
408412514ea60a707cefb42f2609a3422223bd86381Alexandre Elias#ifndef LOG_EVENT_STRING
409dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#define LOG_EVENT_STRING(_tag, _value)                                      \
410dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    ((void) 0)  /* not implemented -- must combine len with string */
411412514ea60a707cefb42f2609a3422223bd86381Alexandre Elias#endif
412dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project/* TODO: something for LIST */
413dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
414dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project/*
415dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project * ===========================================================================
416dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project *
417dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project * The stuff in the rest of this file should not be used directly.
418dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project */
419dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
420dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#define android_printLog(prio, tag, fmt...) \
421dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    __android_log_print(prio, tag, fmt)
422dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
423dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#define android_vprintLog(prio, cond, tag, fmt...) \
424dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    __android_log_vprint(prio, tag, fmt)
425dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
42619299904343daf191267564fe32e6cd5c165cd42Chris Pearson/* XXX Macros to work around syntax errors in places where format string
427ceabb17306f4de9850516dae96bb0d2d5853f028Steve Block * arg is not passed to ALOG_ASSERT, LOG_ALWAYS_FATAL or LOG_ALWAYS_FATAL_IF
42819299904343daf191267564fe32e6cd5c165cd42Chris Pearson * (happens only in debug builds).
42919299904343daf191267564fe32e6cd5c165cd42Chris Pearson */
43019299904343daf191267564fe32e6cd5c165cd42Chris Pearson
43119299904343daf191267564fe32e6cd5c165cd42Chris Pearson/* Returns 2nd arg.  Used to substitute default value if caller's vararg list
43219299904343daf191267564fe32e6cd5c165cd42Chris Pearson * is empty.
43319299904343daf191267564fe32e6cd5c165cd42Chris Pearson */
43419299904343daf191267564fe32e6cd5c165cd42Chris Pearson#define __android_second(dummy, second, ...)     second
43519299904343daf191267564fe32e6cd5c165cd42Chris Pearson
43619299904343daf191267564fe32e6cd5c165cd42Chris Pearson/* If passed multiple args, returns ',' followed by all but 1st arg, otherwise
43719299904343daf191267564fe32e6cd5c165cd42Chris Pearson * returns nothing.
43819299904343daf191267564fe32e6cd5c165cd42Chris Pearson */
43919299904343daf191267564fe32e6cd5c165cd42Chris Pearson#define __android_rest(first, ...)               , ## __VA_ARGS__
44019299904343daf191267564fe32e6cd5c165cd42Chris Pearson
441dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#define android_printAssert(cond, tag, fmt...) \
44219299904343daf191267564fe32e6cd5c165cd42Chris Pearson    __android_log_assert(cond, tag, \
44319299904343daf191267564fe32e6cd5c165cd42Chris Pearson        __android_second(0, ## fmt, NULL) __android_rest(fmt))
444dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
445dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#define android_writeLog(prio, tag, text) \
446dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    __android_log_write(prio, tag, text)
447dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
448dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#define android_bWriteLog(tag, payload, len) \
449dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    __android_log_bwrite(tag, payload, len)
450dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#define android_btWriteLog(tag, type, payload, len) \
451dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    __android_log_btwrite(tag, type, payload, len)
45219299904343daf191267564fe32e6cd5c165cd42Chris Pearson
453dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project// TODO: remove these prototypes and their users
454dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#define android_testLog(prio, tag) (1)
455dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#define android_writevLog(vec,num) do{}while(0)
456dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#define android_write1Log(str,len) do{}while (0)
457dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#define android_setMinPriority(tag, prio) do{}while(0)
458dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project//#define android_logToCallback(func) do{}while(0)
459dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#define android_logToFile(tag, file) (0)
460dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#define android_logToFd(tag, fd) (0)
461dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
462e2bf2ea4d2846031edfc52b942ad53e5467243f6Joe Onoratotypedef enum {
463e2bf2ea4d2846031edfc52b942ad53e5467243f6Joe Onorato    LOG_ID_MAIN = 0,
464e2bf2ea4d2846031edfc52b942ad53e5467243f6Joe Onorato    LOG_ID_RADIO = 1,
465e2bf2ea4d2846031edfc52b942ad53e5467243f6Joe Onorato    LOG_ID_EVENTS = 2,
466e2bf2ea4d2846031edfc52b942ad53e5467243f6Joe Onorato    LOG_ID_SYSTEM = 3,
467e2bf2ea4d2846031edfc52b942ad53e5467243f6Joe Onorato
468e2bf2ea4d2846031edfc52b942ad53e5467243f6Joe Onorato    LOG_ID_MAX
469e2bf2ea4d2846031edfc52b942ad53e5467243f6Joe Onorato} log_id_t;
470e2bf2ea4d2846031edfc52b942ad53e5467243f6Joe Onorato
471e2bf2ea4d2846031edfc52b942ad53e5467243f6Joe Onorato/*
472e2bf2ea4d2846031edfc52b942ad53e5467243f6Joe Onorato * Send a simple string to the log.
473e2bf2ea4d2846031edfc52b942ad53e5467243f6Joe Onorato */
474e2bf2ea4d2846031edfc52b942ad53e5467243f6Joe Onoratoint __android_log_buf_write(int bufID, int prio, const char *tag, const char *text);
475e2bf2ea4d2846031edfc52b942ad53e5467243f6Joe Onoratoint __android_log_buf_print(int bufID, int prio, const char *tag, const char *fmt, ...);
476e2bf2ea4d2846031edfc52b942ad53e5467243f6Joe Onorato
477dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
478dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#ifdef __cplusplus
479dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project}
480dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#endif
481dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
482dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#endif // _LIBS_CUTILS_LOG_H
483