package com.showself.utils;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

import android.content.Context;
import android.os.Environment;

import com.showself.ui.ShowSelfApp;

/**
 * Log统一管理工具类
 * @author JustMe
 *
 */
public class DLog {

/**
  * 开发阶段设为true
  */
 public static boolean printLog = false;
 private static boolean printClassLog = printLog;

public static boolean D = printLog;
 public static boolean V = printLog;
 public static boolean I = printLog;
 public static boolean W = printLog;
 public static boolean E = printLog;
 
 public final static String FILE_DIR_NAME = "Log";
 public final static String FILE_NAME = "ShowSelf.log";
 public static void d(String tag, String msg) {
  if (!D || msg == null) {
   return;
  }
  android.util.Log.d(tag, msg);
 }

public static void d(String tag, String msg, Throwable tr) {
  if (!D || msg == null) {
   return;
  }
  android.util.Log.d(tag, msg, tr);
 }

public static void v(String tag, String msg) {
  if (!V || msg == null) {
   return;
  }
  android.util.Log.v(tag, msg);
 }

public static void v(String tag, String msg, Throwable tr) {
  if (!V || msg == null) {
   return;
  }
  android.util.Log.v(tag, msg, tr);
 }

public static void i(String tag, String msg) {
  if (!I || msg == null) {
   return;
  }
  android.util.Log.i(tag, msg);
 }

public static void i(String msg) {
  if (!I || msg == null) {
   return;
  }
  android.util.Log.i(getStackTraceName(), msg);
 }
 
 public static void i(String tag, String msg, Throwable tr) {
  if (!I || msg == null) {
   return;
  }
  android.util.Log.i(tag, msg, tr);
 }

public static void w(String tag, String msg) {
  if (!W || msg == null) {
   return;
  }
  android.util.Log.w(tag, msg);
 }

public static void w(String tag, Throwable tr) {
  if (!W) {
   return;
  }
  android.util.Log.w(tag, tr);
 }

public static void w(String tag, String msg, Throwable tr) {
  if (!W) {
   return;
  }
  android.util.Log.w(tag, msg, tr);
 }

public static void e(String tag, String msg) {
  if (!E || msg == null) {
   return;
  }
  android.util.Log.e(tag, msg);
 }

public static void e(String tag, String msg, Throwable tr) {
  if (!E) {
   return;
  }
  android.util.Log.e(tag, msg, tr);
 }
 public static void e(Throwable tr) {
  if (!E) {
   return;
  }
  tr.printStackTrace();
 }
 
 public static String getStackTraceName(){
  if(!printClassLog){
   return "";
  }
   StackTraceElement[]  stackTrace = Thread.currentThread().getStackTrace(); 
   String  stackTraceName = null;
  if(stackTrace.length>4){
   stackTraceName = stackTrace[4].getClassName()+ stackTrace[4].getMethodName();
    }
  return stackTraceName;
 }
 
 /**
  * 将日志写到程序的文件里面
  */
 public static void writeToFile(String msg) {
  try {
   File fileDir = ShowSelfApp.getInstance().getApplicationContext().getDir(FILE_DIR_NAME, Context.MODE_PRIVATE);
   String filePath = fileDir.getAbsolutePath() + File.separator + FILE_NAME;
   StreamUtil.saveStringToFile(msg, filePath);
  } catch (IOException e) {
   i("", "书写日志发生错误:" + e.toString());
  }
 }
 
 /**
  * 将日志写到SD卡里面
  */
 public static void writeToSDCard(String msg) {
  writeToSDCard(null, msg);
 }
 
 /**
  * 将日志写到SD卡里面,同时输出log日志
  */
 public static void writeToSDCard(String tag, String msg) {
     if (printLog && msg != null) {
         if (tag != null) {
                DLog.i(tag, msg);
            }
        
         FileWriter fw = null;
         try {
             File file = new File(Environment.getExternalStorageDirectory() + "/" + FILE_NAME);
             if (!file.exists()) {
                    file.createNewFile();
                } else if (file.length() > 10 * 1024) {
                    file.delete();
                    file.createNewFile();
                }
             fw = new FileWriter(file, true);
             fw.write(TimeUtil.getTimeStamp() + " : " + msg + "\r\n");
         } catch (Exception e) {
             i("", "书写日志发生错误:" + e.toString());
         } finally {
             try {
                 if (fw != null) {
                     fw.close();
                 }
             } catch (IOException e) {
             }
         }
        }
 }

}

http://r.virscan.org/language/zh-cn/report/ec6ba3b02c6feb533000f2ffc64279f3

com.showself.utils.DLog相关推荐

  1. 【OpenGL ES】 Android OpenGL ES -- 透视投影 和 正交投影

    博客地址 : http://blog.csdn.net/shulianghan/article/details/46680803 源码下载 : http://download.csdn.net/det ...

  2. openpyxl.utils.exceptions.InvalidFileException: openpyxl does not support the old

    具体错误如下: openpyxl.utils.exceptions.InvalidFileException: openpyxl does not support the old .xls file ...

  3. Error: module pages/utils/util is not defined

    错误如下: 处理方法是两个../上再加一个../ 自己之前写的会报错,const util = require('../../utils/util') 修改之后:const util = requir ...

  4. $g.$utils.实用工具类

    $g.$utils = {/**舒工Ajax-lite 1.0 -- 最精简的ajax自定义访问方法*/ajax: function (o) {var p = o.post, g = o.get, d ...

  5. 【Qt】通过QtCreator源码学习Qt(十一):Utils::Icon,根据不同主题、不同状态变换图标

    1.简介 在QtCreator中Utils::Icon封装的图标可以根据主题变换,还可以设置不同状态下的图标的颜色.不同状态下的颜色变换,由QIcon::addPixmap函数实现: void QIc ...

  6. 【原创】Kakfa utils源代码分析(三)

    Kafka utils包最后一篇~~~ 十五.ShutdownableThread.scala 可关闭的线程抽象类! 继承自Thread同时还接收一个boolean变量isInterruptible表 ...

  7. 使用Tape和Vue Test Utils编写快速的Vue单元测试

    by Edd Yerburgh 埃德·耶堡(Edd Yerburgh) 使用Tape和Vue Test Utils编写快速的Vue单元测试 (Write blazing fast Vue unit t ...

  8. Keras中神经网络可视化模块keras.utils.vis_util 的安装

    Bug: ModuleNotFoundError: No module named 'keras.utils.vis_util' 解决方案: pip install pydot_ngpip insta ...

  9. tensorflow tf.keras.utils.plot_model 画深度学习神经网络拓扑图

    tensorflow tf.keras.utils.plot_model 画网络拓扑图 # pip install graphviz # pip install pydot # 下载 graphviz ...

最新文章

  1. linux开机自动打开全屏,如何修改Linux开机启动logo并使其全屏显示?
  2. 使用css3制作正方形、三角形、扇形和饼状图
  3. 计算机网络技术基础教学内容,计算机网络技术基础
  4. 计算机检测维修与数据恢复试卷,计算机检测维修与数据恢复技术及应用原稿(范文1)...
  5. 小米上市破发,其生态内部的隐患终于显露了?
  6. keras实例化model后,结果返回NoneType
  7. smarty入门教程
  8. UDP数据包最大传输长度
  9. 总结oracle10g在Win10上安装时出现的问题及解决方案
  10. Rails笔记《一》Routing
  11. 电商 秒杀系统 设计思路和实现方法
  12. entrez检索系统要服务器吗,Entrez 系统
  13. win7搜索文件内容
  14. Matery主题友联随机排列
  15. 希腊字母及对应的英文
  16. 数据通信初级工程师题库
  17. 深入理解以太网PHY自协商及调试心得
  18. undefined相关
  19. R语言使用sd函数计算向量数据的标准差
  20. 云南烟草:科技引领财务变革 智能创造财务价值

热门文章

  1. 2020山东春季高考计算机专业,2020山东春季高考科目时间及总分
  2. 2022javascript面试题
  3. Jrtplib发送视频文件 + FFMPEG解码+VFW播放视频 (回调方式)
  4. 【Java从零到架构师第1季】【并发 Concurrent 03】线程间通信_ReentrantLock_线程池
  5. CSS 3之模糊与透明色背景
  6. 聊聊主流的分布式数据库
  7. java path file转换_Java-技术专区-Files类和Paths类的用法
  8. CDMA 1X 语音业务流程
  9. 如何解决苹果手机onclick点击无效的问题?
  10. Sql排序(当有Null值存在时,将它排在最后面)