2013-07-16 515 views
0

import android.util.LogAndroid扩展:如何扩展导入android.util.Log?和它的扩展名是什么?

现在我使用Log.e,Log.i在Android.and我使用导入android.util.Log;

Log.i("TIME", "USER " + user_id + " DATE: " + date); 

Log.e("TIMESHEET", "USER ID: " + user_id + " DATE: " + date); 

Log.d("TIMESHEET", "USER ID: " + user_id + " DATE: " + date); 

我们的团队推出我们的产品。

所以我们用不同的日志在我们的代码。因为我不得不去思考。

我创建一个类,扩展日志。

使用覆盖/实现方法,我可以访问我们所需要的东西。

所以,我需要的是日志扩展在我创建的类。

so if any way to make all Log in one class control please suggest. 

谢谢,s在Advances中。

+0

你是什么意思的延伸:添加一个新的功能,如Log.doMySpecilFunction()? – k3b

回答

0

您可以创建自己的类,说LogUtils,并创建不同类型的日志的静态函数。在该类中使用本地日志功能。例如:

/** 
* Utility methods to print log messages 
* 
* @author shraddhas 
*/ 
public class LogUtils 
{ 
    /** 
    * Send a message to the debug log if debugging is on 
    */ 

    public static void trace(final String msg) 
    { 
     if (ApplicationConstants.IS_DEBUGGING_ON) 
     { 
      final String fullClassName = Thread.currentThread().getStackTrace()[3].getClassName(); 
      final String className = fullClassName.substring(fullClassName.lastIndexOf(".") + 1); 
      final String methodName = Thread.currentThread().getStackTrace()[3].getMethodName(); 
      final int lineNumber = Thread.currentThread().getStackTrace()[3].getLineNumber(); 

      Log.d(ApplicationConstants.LOG_TAG, "#" + lineNumber + " " + className + "." + methodName + "() : " + msg); 
     } 
    } 
} 
+0

您可以创建另一个重载函数来接受日志的类型,以便您可以相应地根据其类型打印日志。 – Shraddha

+0

是我的log.e方法会自动调用你的trace方法,我可以使用LogUtils类。 –

+0

LogUtils.trace(“yourmessage这里”) – Shraddha