Current location - Quotes Website - Signature design - How to use logCat in JNI programming
How to use logCat in JNI programming
In the java code of android programming, we know that we can use Log.v to output logs to logcat, and then we can see the log output information. Of course, you can also use ADB NDK in the shell. In the past, in JNI programming, it was difficult to debug local interface methods, and the logs were often output to files through logging. Today, in the catalog,

/build/platforms/Android-8/arch-arm/usr/include/Android/log . h

The header file found under Android NDK, open it and have a look.

[CPP] In view of the plain text

/ *

* Copyright (C)2009 Android Open Source Project.

*

* Authorized under the Apache License Version 2.0 (hereinafter referred to as the "License");

* You can't use this file unless you comply with the license.

* You can obtain a copy of the license from.

*

* http://www.apache.org/licenses/LICENSE-2.0

*

* Unless required by applicable laws or agreed in writing, the Software

* Distribution under license is based on "as is" distribution,

* There is no guarantee or any kind of condition, express or implied guarantee.

* See license language-specific administrative rights and.

* Restrictions under the license.

* /

_ANDROID_LOG_H of #ifndef

# definition _ANDROID_LOG_H

/ ******************* *****************

*

* Important note:

*

* This file is part of the header file of Android stability system.

* Android NDK (native development kit) is exposed because

* Platform 65438+ Version 0.5

*

* Third-party source code and binary code depend on the definition.

* This has been frozen in all versions of the upcoming platform.

*

*-Do not modify the enumeration (unless you add a new 32-bit value).

*-Do not modify constants or function macros.

*-Do not change the signature of the function in any way.

*-Do not change the layout and size of the structure.

* /

/ *

* Support routines to send messages to the kernel log buffer of Android.

* You can access it later through the "logcat" utility.

*

* Each log message must have

*-Priority

*-Log label

*-Some texts

*

* Tags usually correspond to components that send log messages.

* And it should be small.

*

* The text of the log message may be truncated according to the specific implementation.

* restrictions (such as 1023 characters).

*

* Please note that a line break ("/N") will be automatically added to your.

* Log message, if it doesn't exist. It is impossible to send a few messages.

*, and make them appear on one line in logcat.

*

* please use the log, don't overuse it:

*

*-Send log messages to consume CPU and slow down the application.

* system.

*

*-Circular log buffer is very small (

* Important log messages may be pushed from the rest of the system.

*

*-In the release version, only log messages are sent to explain the exception.

* conditions.

*

* Note: These functions must be implemented by/system/lib/librog.so..

* /

# Including

#ifdef __cplusplus of

External "c" (

#ENDIF

/ *

* Android log priority values, arranged in ascending order of priority.

* /

Typedef enumerates android_LogPriority {

ANDROID_LOG_UNKNOWN = 0

ANDROID_LOG_DEFAULT,/* for SetMinPriority()*/

Android _ Log _ Details,

ANDROID_LOG_DEBUG,

Android _ Log _ Info,

ANDROID_LOG_WARN,

Android _ Log _ Error,

ANDROID_LOG_FATAL,

ANDROID_LOG_SILENT,/* SetMinPriority()only; Must be the last */

} android _ LogPriority

/ *

* Send a simple string log.

* /

INT __android_log_write(INT PRIO, marked with const char *, marked with const char * text);

/ *

* send a formatted string to the log, using such as printf(FMT, ...)

* /

INT __android_log_print(INT PRIO, marked with const char *, const char * FMT ...)

# If you define (__ GNUC__)

__attribute__ ((format (of printf, 3,4)))

#ENDIF

/ *

* __android_log_print (variant of) requires a list of va_list.

* Additional parameters.

* /

Int _ _ Android _ log _ vprint (int prio, marked with const char *,

Is const char * FMT, AP); of va_list);

/ *

* Login assertion failed, there is an opportunity during SIGTRAP.

* If a debugger is attached, please check it. It uses fatal priority.

* /

__android_log_assert is invalid (for const char * COND, for const char * tag,

For the constant char * FMT, ...)

# If you define (__ GNUC__)

__attribute__ ((not returned))

__attribute__ ((format (of printf, 3,4)))

#ENDIF

#ifdef __cplusplus of

}

#ENDIF

#ENDIF / * * _ANDROID_LOG_H /

Please read this header file carefully, and we will find that the NDK of Android fully supports JNI local method debugging. It provides four functions for us to use, as follows

[CPP] In view of the plain text

/ *

* Send a simple string log.

* /

INT __android_log_write(INT PRIO, marked with const char *, marked with const char * text);

/ *

* send a formatted string to the log, using such as printf(FMT, ...)

* /

INT __android_log_print(INT PRIO, marked with const char *, const char * FMT ...)

/ *

* __android_log_print (variant of) requires a list of va_list.

* Additional parameters.

* /

Int _ _ Android _ log _ vprint (int prio, marked with const char *,

Is const char * FMT, AP); of va_list);

/ *

* Login assertion failed, there is an opportunity during SIGTRAP.

* If a debugger is attached, please check it. It uses fatal priority.

* /

__android_log_assert is invalid (for const char * COND, for const char * tag,

For the constant char * FMT, ...)

We can send local method debugging information to logcat. (Isn't it cool, so you don't have to worry so much about debugging local methods in the future _)

To use these functions, you must add the following inclusion statements to the local file.

# Including