Android输出日志到本地

Android本地日志工具

在日常开发过程中,一些后台服务,比如IM,后台定时任务,都需要一套本地日志系统来监控程序是否正常,Android本身提供的日志系统只能在终端显示,为了模拟一套和android Log系统相同的环境,我自己写了一套本地日志系统来解决以上问题。

为了能让不同等级的日志以不同的颜色显示,我用html的方式来实现,这样我们通过浏览器打开就可以了。演示效果如下: htmldemoimg

github地址: https://github.com/lorcanluo/LogLocal

##使用方法

在你的Application或则主Activity调用:

LogLocal.init(this.getPackageName());

方法来初始化,传入参数为你需要存放文件的目录。

目前支持三种级别的日志:

普通消息

在文件中以黑色字体显示

调用方法:

   /**
     * info log
     *
     * @param tag Used to identify the source of a log message.  It usually identifies
     *            the class or activity where the log call occurs.
     * @param msg The message you would like logged.
     */
    public static void i(String tag, String msg) {

    }

调试信息

在文件中以绿色字体显示

调用方式:

/**
     * debug log
     *
     * @param tag Used to identify the source of a log message.  It usually identifies
     *            the class or activity where the log call occurs.
     * @param msg The message you would like logged.
     */
    public static void d(String tag, String msg) {
     
    }

错误信息

在文件中以红色字体显示

调用方法:

    /**
     * error log
     *
     * @param tag Used to identify the source of a log message.  It usually identifies
     *            the class or activity where the log call occurs.
     * @param msg The message you would like logged.
     */
    public static void e(String tag, String msg) {

    }

关闭日志

如果你不想在正式环境输出日志,可以调用以下方法来屏蔽日志输出:

/**
 * open or close the function
 *
 * @param isDebuggable if set to false, not print the message.
 */
 public static void setIsDebuggable(boolean isDebuggable)()

问题

有什么问题,可以直接提交issus 或则联系我 email 763736665@qq.com

转载于:https://my.oschina.net/lorcan/blog/551313

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值