LogUtil

Log太长了,as里默认打印不完全,于是网上找了一个LogUtil工具类,按照需求换行,就可以打印全部的内容了

package com.axnet.zhhz.util;

import android.util.Log;

/**
 * log工具类
 * Created by lyl on 2016/11/29.
 */

public class LogUtil {

    private LogUtil(){
        throw new UnsupportedOperationException("cannt be init");
    }

    public static boolean isDebug = true;// 是否需要打印bug,可以在application的onCreate函数里面初始化
    private static final String TAG = "way";

    // 下面四个是默认tag的函数
    public static void i(String msg)
    {
        if (isDebug)
            Log.i(TAG, msg);
    }

    public static void d(String msg)
    {
        if (isDebug)
            Log.d(TAG, msg);
    }

    public static void e(String msg)
    {
        if (isDebug)
            Log.e(TAG, msg);
    }

    public static void v(String msg)
    {
        if (isDebug)
            Log.v(TAG, msg);
    }

    // 下面是传入自定义tag的函数
    public static void i(String tag, String msg)
    {
        if (isDebug)
            Log.i(tag, msg);
    }

    public static void d(String tag, String msg)
    {
        if (isDebug)
            Log.d(tag, msg);
    }

    public static void e(String tag, String msg)
    {
        if (isDebug)
            Log.e(tag, msg);
    }

    public static void v(String tag, String msg)
    {
        if (isDebug)
            Log.v(tag, msg);
    }

    /**
     * 分段打印出较长log文本
     * @param logContent  打印文本
     * @param showLength  规定每段显示的长度(AndroidStudio控制台打印log的最大信息量大小为4k)
     * @param tag         打印log的标记
     */
    public static void showLargeLog(String logContent, int showLength, String tag){
        if(logContent.length() > showLength){
            String show = logContent.substring(0, showLength);
            e(tag, show);
            /*剩余的字符串如果大于规定显示的长度,截取剩余字符串进行递归,否则打印结果*/
            if((logContent.length() - showLength) > showLength){
                String partLog = logContent.substring(showLength,logContent.length());
                showLargeLog(partLog, showLength, tag);
            }else{
                String printLog = logContent.substring(showLength, logContent.length());
                e(tag, printLog);
            }

        }else{
            e(tag, logContent);
        }
    }
}

下载地址直接拿去用

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值