0

导入 android.util.Log

现在我在 Android.and 中使用 Log.e,Log.i 我正在使用导入 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.

谢谢,提前。

4

1 回答 1

1

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

/**
 * 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);
        }
    }
}
于 2013-07-16T13:31:26.377 回答