android log4,GitHub - oronno/log4android: Log4Android - Simple Logging Wrapper Library for Android

log4android

Log4Android - Simple Logging Wrapper Library for Android

Tired writing TAG each time writing log in Android? Bored with printing variables by concatenating string with "+"??

Come from Java Enterprise Development where infamous Log4J used heavily??

Well, with this Log4Android library, you can easily write log with your old habit

log.debug("in myMethod, id={}, name={}", ver1, ver2);

You also can easily disable printing logs by calling method Logger.disableLogging(true). This specially

useful when you want to remove log printing while publishing app in playstore.

Features

Log syntax similar with popular log4j framework

Automatically added TAG with log message

Derive TAG from the package name

Can disable logging by simply calling Logger.disableLogging(true) method preferably from the class extends Application.

Fully Qualified Class name or SimpleClassName will logged as prefix with log message

Variable Arguments (more than 2) can be passed for printing unlike log4j framework

Very lightweight, < 5KB library size!

Quick Start

First, add Log4Android-x.x.jar (can download from releases directory) at your android project library

Obtain a logger object in your Android code (Activity, Fragment, Service etc) like:

private static final Logger log = Logger.getLogger(MyActivity.class);

OR

private static final Logger log = Logger.getLogger("YOUR_TAG");

OR

private static final Logger log = Logger.getLogger(MyActivity.class, "YOUR_TAG");

Now, start writing log like:

log.info("onStart(), id={}, someObject={}", id, someObject);

log.debug(tvName.getText());

log.verbose("var1={}, var2={}, var3={}, var4={}", v1, v2, v3, v4);

log.error(ex, "Error occur while trying to load image with id={}", id);

Also can pass throwable/exception as the last argument which will print accordingly:

log.error("Exception at row id={}", id, throwable);

API Docs

Motivation

No other library found for Android Development except "SLF4J Android", provide similar logging mechanism as standard

java logging framework. But "SLF4J Android" library has the following limitation:

SLF4J try to use full qualified class name as tag. This cause problem when, auto generated log tags that are

<= 23 characters long due to a length restriction of log tags on the Android platform (e.g., com.example.myapp.MyClass

tag translated to c*.e*.m*.MyClass), which can result in the same log tag for different classes

(e.g., com.example.app.MyClass and com.example.anotherapp.MyClass both translate to c*.e*.a*.MyClass);

So, sometimes, you can't distinguish classes. Besides, there is no other way to define your own TAG here.

Also log4j framework does not support variable arguments (more than 2) in a easy way, one have to write like new Object[]{var1, var2, var3} which I found annoying.

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值