java android Logcat类的简单扩展,便于更改调试模式。

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java android Logcat类的简单扩展,便于更改调试模式。相关的知识,希望对你有一定的参考价值。


import android.util.Log;

public class Logcat{

	/*
	 * ALLOW_LOG to enable or disable debugging log
	 */
	private static final boolean ALLOW_LOG = true;

	
	/*
	 * @since API level 1
	 * 
	 * Send an DEBUG log message.
	 */
	public static void e(String tag, String message){
		if(ALLOW_LOG){
			Log.e(tag, message);
		}
	}
	
	/*
	 * @since API level 1
	 * 
	 * Send an DEBUG log message.
	 * 
	 */
	
	public static void d(String tag, String message){
		if(ALLOW_LOG){
			Log.d(tag, message);
		}
	}
	
	/*
	 * @since API level 1
	 * 
	 * Send an VERBOSE log message.
	 */
	public static void v(String tag, String message){
		if(ALLOW_LOG){
			Log.v(tag, message);
		}
	}
	
	
	/*
	 * @since API level 1
	 * 
	 * Send an INFO log message.
	 */
	public static void i(String tag, String message){
		if(ALLOW_LOG){
			Log.i(tag, message);
		}
	}
	
	/*
	 * @since API level 1
	 * 
	 * Send a WARN log message.
	 */
	public static void w(String tag, String message){
		if(ALLOW_LOG){
			Log.w(tag, message);
		}
	}
	

	/*
	 * @since API level 8 
	 * 
	 * What a Terrible Failure: Report a condition that should never happen.
	 * The error will always be logged at level ASSERT with the call stack.
	 * Depending on system configuration, a report may be added to the DropBoxManager
	 * and/or the process may be terminated immediately with an error dialog.
	 */
	public static void wtf(String tag, String message){
		if(ALLOW_LOG){
			Log.wtf(tag, message);
		}
	}

	// Show long message in android studio 
	public static void l(String tag, String message) {
	     if(ALLOW_LOG){
	     	if(message != null){
			int maxLogSize = 1000;
		        int length = message.length() / maxLogSize;
		        for(int i = 0; i <= length; i++) {
		            int start = i * maxLogSize;
		            int end = (i+1) * maxLogSize;
		            end = end > message.length() ? message.length() : end;
		            Log.e(tag, message.substring(start, end));
		        }		    		     		
	     	}
	     }
    	}


}

以上是关于java android Logcat类的简单扩展,便于更改调试模式。的主要内容,如果未能解决你的问题,请参考以下文章

是否可以在 Android 上从 Xalan 调用 Java 扩展函数?

Android-LogCat日志工具

java 使用滚动(Android)在TextView中显示LogCat

Eclipse中多个标签的Android LogCat过滤器

如何在 Eclipse for Android 中启用 LogCat/Console?

Android Studio 中的简单计算器应用程序不断关闭