今天翻译log.h文件。

1, 版权声明,这个不用我翻译了吧,游戏规则是这样子滴,非得来这一套,我直接把原文贴出来好了,看不看你自己负责,嘿嘿(-^^-)

* Copyright (C) 2009 The Android Open Source Project

 *

 * 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.

 

2, 重要提示:

 

   这个文件来自NDK 1.5版提供的稳定API中的一部分,依赖这份文件开发的第三方代码在将来的平台发布版中不用修改也可以正常运行。

   -不要修改枚举(除非你要加入新的32位值)

   -不要修改常数或功能宏.

   -不要修改函数声明

   -不要修改结构体的布局和大小。

 

3,支持程序向Android的内核日志缓冲区发送消息,这个消息随后可以被’logcat’工具访问。

 

每条日志消息一定有:

-优先级

-日志标签

-文本

标签与发出消息的组件相对应,应该会很简短。

日志文本可能会被删节,少于原有的限制数量(比如,最大1023个字符).

  注意,换行符会被自动加入到你的日志消息中,如果没有的话。发送几条消息,

而又要让他们在logcat中保持在一行出现,这是不可能滴。

 

4,请适度使用日志

 -发送日志会消耗CPU,减慢你的程序和系统的运行速度。

 -日志缓冲区是循环使用的,非常小,发送太多消息,可能会PUSH掉系统中其他重要的日志消息。

-在发行版,只有导致异常的条件发生时,才发送日志消息。

注意:这些函数在/system/lib/liblog.so中实现。

 

5,以下是枚举常数和函数声明。

//Android 日志优先级, 按从小到大顺序.

typedef enum android_LogPriority {

    ANDROID_LOG_UNKNOWN = 0,

    ANDROID_LOG_DEFAULT,    /* only for SetMinPriority() */

    ANDROID_LOG_VERBOSE,

    ANDROID_LOG_DEBUG,

    ANDROID_LOG_INFO,

    ANDROID_LOG_WARN,

    ANDROID_LOG_ERROR,

    ANDROID_LOG_FATAL,

    ANDROID_LOG_SILENT,     /* only for SetMinPriority(); must be last */

} android_LogPriority;

 

//发送一个字符串

int __android_log_write(int prio, const char *tag, const char *text);

 

//发送一个格式化的字符串,象printf(fmt,…)那样。

int __android_log_print(int prio, const char *tag,  const char *fmt, ...)

 

//__android_log_print()函数的变种,用va_list类型的变量列出附加的参数。

int __android_log_vprint(int prio, const char *tag,

                         const char *fmt, va_list ap);

 

//记录断言失败,让调试进程有机会检查。使用FATAL优先级。

void __android_log_assert(const char *cond, const char *tag,

              const char *fmt, ...)   

注,以上的序号是我自己加的,请自行参考原文。这份头文件在ndk的build\platforms\android-1.5\common\include\android目录下面,

打算明天写个例子程序,解释下如何使用log。

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 angledark0123 的頭像
    angledark0123

    CONY的世界

    angledark0123 發表在 痞客邦 留言(0) 人氣()