Android Log 封装

package com.tv.ui.metro.utils;

/* * Copyright (C) 2010 Lytsing Huang http://lytsing.org * * 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. */

/** * Wrapper API for sending log output. */public class _Log {    protected static final String TAG = "MyApplication";

    public _Log() {    }

    /**     * Send a VERBOSE log message.     * @param msg The message you would like logged.     */    public static void v(String msg) {        android.util.Log.v(TAG, buildMessage(msg));    }

    /**     * Send a VERBOSE log message and log the exception.     * @param msg The message you would like logged.     * @param thr An exception to log     */    public static void v(String msg, Throwable thr) {        android.util.Log.v(TAG, buildMessage(msg), thr);    }

    /**     * Send a DEBUG log message.     * @param msg     */    public static void d(String msg) {        android.util.Log.d(TAG, buildMessage(msg));    }

    public static void dI() {        android.util.Log.d(TAG, buildMessage("IN"));    }    public static void dO() {        android.util.Log.d(TAG, buildMessage("OUT"));    }    /**     * Send a DEBUG log message and log the exception.     * @param msg The message you would like logged.     * @param tr An exception to log     */    public static void d(String msg, Throwable thr) {        android.util.Log.d(TAG, buildMessage(msg), thr);    }

    /**     * Send an INFO log message.     * @param msg The message you would like logged.     */    public static void i(String msg) {        android.util.Log.i(TAG, buildMessage(msg));    }

    /**     * Send a INFO log message and log the exception.     * @param msg The message you would like logged.     * @param thr An exception to log     */    public static void i(String msg, Throwable thr) {        android.util.Log.i(TAG, buildMessage(msg), thr);    }

    /**     * Send an ERROR log message.     * @param msg The message you would like logged.     */    public static void e(String msg) {        android.util.Log.e(TAG, buildMessage(msg));    }

    /**     * Send a WARN log message     * @param msg The message you would like logged.     */    public static void w(String msg) {        android.util.Log.w(TAG, buildMessage(msg));    }

    /**     * Send a WARN log message and log the exception.     * @param msg The message you would like logged.     * @param thr An exception to log     */    public static void w(String msg, Throwable thr) {        android.util.Log.w(TAG, buildMessage(msg), thr);    }

    /**     * Send an empty WARN log message and log the exception.     * @param thr An exception to log     */    public static void w(Throwable thr) {        android.util.Log.w(TAG, buildMessage(""), thr);    }

    /**     * Send an ERROR log message and log the exception.     * @param msg The message you would like logged.     * @param thr An exception to log     */    public static void e(String msg, Throwable thr) {        android.util.Log.e(TAG, buildMessage(msg), thr);    }

    /**     * Building Message     * @param msg The message you would like logged.     * @return Message String     */    protected static String buildMessage(String msg) {        StackTraceElement caller = new Throwable().fillInStackTrace().getStackTrace()[2];

        return new StringBuilder()                .append(caller.getClassName())                .append(".")                .append(caller.getMethodName())                .append("(): ")                .append(msg).toString();    }}
时间: 2024-10-12 16:24:06

Android Log 封装的相关文章

Android简单封装类似JQuery异步请求

在android开发中经常会使用异步请求数据,通常会使用handler或者AsyncTask去做,handler 配合message 使用起来比较麻烦,AsyncTask 线程池只允许128个线程工作,会有溢出的问题,(当然一般情况不会有那么多线程同时工作的)所以写了这个代码,还望高手指正! [Java]代码 01 package com.xbl.task; 02 03 import java.io.BufferedReader; 04 import java.io.InputStream; 0

Log中'main', 'system', 'radio', 'events'以及android log分析

在Android中不同的log写到不同的设备中,共有/dev/log/system, /dev/log/main, /dev/log/radion, /dev/log/events四中类型.其中默认Log.v等写入/dev/log/main中.Slog写入/dev/log/system中. 我们在使用logcat 抓去日至的时候, 可以指定buffer,来请求不同的环形缓冲区 ('main', 'system', 'radio', 'events',默认为"-b main -b system&q

sqlite与android交互 (封装)

学android已经有大概一周时间了吧 ,总感觉自己基础不怎么好,只能通过一点一点积累着敲来巩固平常的知识,有的时候就先不封装的敲一遍,再封装上,有些语句真的记不住,虽然知道他是什么意思,于是乎就反复的敲着,加油吧!少年,下面进入正题吧 DBConn.java类 主要是将raw写入到DDMS里的data/data/xxx包/下,代码如下: package com.tp.soft.util; import java.io.File; import java.io.FileOutputStream;

Android LOG机制流程图

以下只是Android LOG机制流程图,关于Android LOG机制的更多详细内容请参阅<Android LOG机制详解> 结束. Android LOG机制流程图,布布扣,bubuko.com

android Log图文详解(Log.v,Log.d,Log.i,Log.w,Log.e)

在Android群里,经常会有人问我,Android Log是怎么用的,今天我就把从网上以及SDK里东拼西凑过来,让大家先一睹为快,希望对大家入门Android Log有一定的帮助. android.util.Log常用的方法有以下5个:Log.v() Log.d() Log.i() Log.w() 以及 Log.e() .根据首字母对应VERBOSE,DEBUG,INFO, WARN,ERROR. 1.Log.v 的调试颜色为黑色的,任何消息都会输出,这里的v代表verbose啰嗦的意思,平时

Android Log

1.Android Log简介: 在程序中输出日志,使用 android.util.Log 类.该类提供了若干静态方法: Log.v(String tag, String msg); // 任何消息都会输出 Log.d(String tag, String msg); // 仅输出debug调试的意思,但他会输出上层的信息 Log.i(String tag, String msg); // 一般提示性的消息information Log.w(String tag, String msg);  

Android 谈谈封装那些事 --BaseActivity 和 BaseFragment(二)

1.前言 昨天谈了BaseActivity的封装,Android谈谈封装那些事--BaseActivity和BaseFragment(一)有很多小伙伴提了很多建议,比如: 通用标题栏可以自定义View而不放在Base里面,代码更统一 BaseEventActivity里面应该留出开关保证不需要Bus的Activity使用 BaseStatusActivity里面就一个方法没必要新建一个 还有一些小的细节 在这里感谢大家的建议了啊.我修改了一部分,后面会慢慢优化,最后在HLibrary里面贴出最优

(Android系统)android log机制浅析

在android下面debug,最主要的方式就是用logcat抓log了,我们可能有尝试过使用printf来打印,当然结果是不行的,这里有时间就看了一下android平台下log的flow,在此做个笔记以作记录 我们一般使用ALOGD来打印log,所以这里就跟一下ALOGD的flow system/core/include/log/log.h system/core/include/log/log.h #ifndef ALOGD #define ALOGD(...) ((void)ALOG(LO

【Util】Android Toast封装

1 /** 2 * Android Toast封装 3 */ 4 5 import android.content.Context; 6 import android.widget.Toast; 7 8 public class ToastUtil { 9 10 // 短时间显示Toast信息 11 public static void showShort(Context context, String info) { 12 Toast.makeText(context, info, Toast