• Android日志输出工具类


    package com.rctd.tmzs.util;


    import android.util.Log;


    /**  
     * 日志输出工具类
     * @author    WuHao; Email: 1024778537@qq.com  
     * @version   V1.0;  Date:  2014-05-26 11:35:20  
     */  
    public class LogUtil {


    private static String tag = "LogUtil";

    private int logLevel = Log.VERBOSE;
    private static final boolean isDebug = true;
    private static LogUtil instance = null;


    public static synchronized LogUtil getInstance() {
    return getInstance(Log.VERBOSE);
    }

    public static synchronized LogUtil getInstance(int level) {
    if (instance == null)
    instance = new LogUtil();
    if (level >= 2)
    instance.setLevel(level);
    return instance;
    }


    private LogUtil() {

    }

    public void setLevel(int level){
    this.logLevel = level;
    }


    private String getFunctionName() {
    StackTraceElement[] sts = Thread.currentThread().getStackTrace();
    if (sts == null) {
    return null;
    }
    for (StackTraceElement st : sts) {
    if (st.isNativeMethod()) {
    continue;
    }
    if (st.getClassName().equals(Thread.class.getName())) {
    continue;
    }
    if (st.getClassName().equals(this.getClass().getName())) {
    continue;
    }
    return "[" + Thread.currentThread().getName() + "(" + Thread.currentThread().getId() + "): " + st.getFileName() + ":" + st.getLineNumber() + "]";
    }
    return null;
    }


    private void outMsg(Object str) {
    String msg = (str == null ? "" : str.toString());
    String name = getFunctionName();
    String ls = (name == null ?

    msg.toString() : (name + " - " + msg));
    if (logLevel == Log.DEBUG) {
    Log.d(tag, ls);
    } else if (logLevel == Log.INFO) {
    Log.i(tag, ls);
    } else if (logLevel == Log.WARN) {
    Log.w(tag, ls);
    } else if (logLevel == Log.ERROR) {
    Log.e(tag, ls);
    } else {
    Log.v(tag, ls);
    }
    }


    public void out(Object msg) {
    if (isDebug) {
    outMsg(msg);
    }
    }
    }

  • 相关阅读:
    【二分图最大独立集/最小割】P3355 骑士共存问题
    【费用流+正负费用处理】UVA11613 Acme Corporation
    【费用流】P2517 [HAOI2010]订货
    【最小割】P1361 小M的作物
    【最小割】[SHOI2007]善意的投票
    【最小割+割点转换】[USACO5.4]奶牛的电信Telecowmunication
    数据结构学习笔记——ST表
    图论学习笔记——LCA
    基于CNN的手写数字识别程序
    [Atcoder]M-Solutions 题解
  • 原文地址:https://www.cnblogs.com/mqxnongmin/p/10858912.html
Copyright © 2020-2023  润新知