Coder Social home page Coder Social logo

logutils's Introduction

LogUtils

Codecov

More convenient and easy to use android Log manager

Features

  • 支持直接打印数据集合, 如List、Set、Map、数组等
  • 全局配置log输出, 个性化设置Tag
  • 准确显示调用方法、行,快速定位日志所在文件位置
  • 支持android系统复杂对象Intent、Bundle、Message等打印
  • 提供空实现 release-no-op版本
  • 支持高性能日志写入文件(基于mmap)
  • 兼容Android Studio 3.1 日志格式

Usage

implementation 'com.apkfuns.logutils:library:1.7.5'

release-no-op版本 (debug输出日志, release空实现)

debugImplementation 'com.apkfuns.logutils:library:1.7.5'
releaseImplementation 'com.apkfuns.logutils:logutils-no-op:1.7.5'

日志写入到文件 (基于Log4a实现)

implementation 'com.apkfuns.log2file:log2file:1.3.1'


// 设置日志写文件引擎
LogUtils.getLog2FileConfig().configLogFileEngine(new LogFileEngineFactory(context));

别忘了添加写文件权限

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

Wiki

使用教程

License

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

logutils's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

logutils's Issues

不知道为什么有时候打印不出来日志

环境如下
`
compile 'com.apkfuns.logutils:library:1.4.2'

public class App extends Application {
private static App mApp;

public static App getInstance() {
    return mApp;
}

@Override
public void onCreate() {
    super.onCreate();
    mApp = this;
    setupLogUtils();
}

private void setupLogUtils() {
    LogUtils.getLogConfig()
            .configAllowLog(true)
            .configTagPrefix("zyd")
            .configShowBorders(true)
            .configLevel(LogLevel.TYPE_VERBOSE);
}

}

public class MainController extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main_controller);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    LogUtils.d("");
}

@OnClick(R.id.bn)
public void testFunction() {
    LogUtils.d("");
    func1();
}

private void func1() {
    String[] names = {"aa", "bb", "cc"};
    Observable
            .from(names)
            .subscribe(new Action1<String>() {
                @Override
                public void call(String s) {
                    LogUtils.d(s);
                }
            });
}

}
`

输出的日志没有点击定位到代码的链接

如: (InitDataService.^____) ,显示的时候变成这样了 ,如果正确应该是(InitDataService.java:22)

不知道是如何造成的,输出短的时候不会造成这个问题,输出太长就会没有链接

打印类名方法名的问题

你好,我在使用LogUtils的时候封装了一层,这样方便统一替换或修改log工具,但这时候打印的类名和方法名就是封装的log class的类名和方法名,能否加一个配置项,设定在backtrace中找到正确的类名和方法名以及文件和行数

#4058 java.lang.NullPointerException Attempt to invoke virtual method 'int java.lang.String.length()' on a null object reference com.apkfuns.logutils.Logger.logString(Logger.java:86)

Caused by:
--
 java.lang.NullPointerException:Attempt to invoke virtual method 'int java.lang.String.length()' on a null object reference
 com.apkfuns.logutils.Logger.logString(Logger.java:86)
 com.apkfuns.logutils.Logger.logString(Logger.java:67)
 com.apkfuns.logutils.Logger.e(Logger.java:212)
 com.apkfuns.logutils.LogUtils.e(LogUtils.java:99)

打印日记时的BUG

当打印的string长度超过3072时,会导致.tag设置的tag无效,采用的tag是默认的tag..比如:
LogUtils.getLogConfig().configAllowLog(isDebug()).configTagPrefix("Test"); //初始化LogUtils
LogUtils.tag("Response").w(bodyString); //当bodyString的长度超过3072时,打印的TAG是"Test";长度3072以下时,打印的TAG是"Response"。

有多个对象作为字段 只打了第一个对象

JobData{
    dvc=Dvc{
        id=355,
        sn='',
        type=2,
        name='心电贴_3197704835',
        hint='03-2516: 04刚测过',
        sharedby='',
        shareto='',
        creator=162,
        creatorname='是硬的',
        dbShareList='',
        sharelist=[

        ],
        btaddress='A0: E6: F8: 4F: C5: B4',
        battery=-1,
        appUid=162,
        appCreated=1460441879486,
        appOrder=0
    },
    id=3555,
    prf=com.protontek.vcare.datastore.table.PrfP@60ce9ed,
    rpt=com.protontek.vcare.datastore.table.Rpt@d140022
}

准确显示调用方法、行,是否可以支持动态设置methodCount

从Logger转到LogUtils,用了一段时间感觉LogUtils比较符合使用习惯,但是能否支持类似于Logger的methodCount,methodOffset方法,因为有些log打印在公共的方法中,LogUtils默认只打印当前方法名和代码行数,不太方便定位到调用此方法的代码位置。
如果能够提供类似
LogUtils.methodCount(2).methodOffset(1).d("我是打印内容");
形式的调用方式就更好了。

对象的}{ 错了

java.util.ArrayList size = 1 [
                                                                                           [0]:WeakReference}{
                                                                                           => Reference {pendingNext = null, queue = null, queueNext = null, referent = com.protontek.vcare.ui.actvt.SplashActvt@e5abf4, disableIntrinsic = false, slowPathEnabled = false} 
                                                                                           ]

关于替换自己项目中的Logutils问题

您好,我在自己项目中封装了个基本的Log打印工具,其他地方都是调用该工具类打印的,现在换成您的log框架,我只改动了我原来Log工具类中的,i,e,等方法,只是简单的替换,比如原本是,ELogs.i(..),现在替换成您的 LogUtils.i(...);然后出现了个问题,打印行号只能打印我原来Log工具类中的行号,无法具体到调用者,这个是无法实现的吗?

Exception in thread "main" java.lang.RuntimeException: Stub!

at android.text.TextUtils.isEmpty(TextUtils.java:64)
at com.apkfuns.logutils.Logger.generateTag(Logger.java:137)
at com.apkfuns.logutils.Logger.logString(Logger.java:71)
at com.apkfuns.logutils.Logger.logString(Logger.java:67)
at com.apkfuns.logutils.Logger.logObject(Logger.java:127)
at com.apkfuns.logutils.Logger.e(Logger.java:217)
at com.apkfuns.logutils.LogUtils.e(LogUtils.java:103)

java.lang.StackOverflowError: stack size 8MB 在打印 android.app.job.JobParameters 对象的时候出现

LogUtils.w(jobParameters);

异常:

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.pycat.jobscheduler, PID: 18263
    java.lang.StackOverflowError: stack size 8MB
        at java.util.ArrayList.<init>(ArrayList.java:158)
        at java.util.Formatter.parse(Formatter.java:2511)
        at java.util.Formatter.format(Formatter.java:2472)
        at java.util.Formatter.format(Formatter.java:2426)
        at java.util.Formatter.formatString(Formatter.java:4533)
        at java.lang.String.format(String.java:2636)
        at com.apkfuns.logutils.utils.ObjectUtil.getClassFields(ObjectUtil.java:130)
        at com.apkfuns.logutils.utils.ObjectUtil.objectToString(ObjectUtil.java:63)
        at com.apkfuns.logutils.utils.ObjectUtil.objectToString(ObjectUtil.java:25)
        at com.apkfuns.logutils.parser.ReferenceParse.parseString(ReferenceParse.java:22)
        at com.apkfuns.logutils.parser.ReferenceParse.parseString(ReferenceParse.java:11)
        at com.apkfuns.logutils.utils.ObjectUtil.objectToString(ObjectUtil.java:54)
        at com.apkfuns.logutils.utils.ObjectUtil.getClassFields(ObjectUtil.java:125)
        at com.apkfuns.logutils.utils.ObjectUtil.objectToString(ObjectUtil.java:63)
        at com.apkfuns.logutils.utils.ObjectUtil.objectToString(ObjectUtil.java:25)
        at com.apkfuns.logutils.parser.ReferenceParse.parseString(ReferenceParse.java:22)
        at com.apkfuns.logutils.parser.ReferenceParse.parseString(ReferenceParse.java:11)
        at com.apkfuns.logutils.utils.ObjectUtil.objectToString(ObjectUtil.java:54)
        at com.apkfuns.logutils.utils.ObjectUtil.getClassFields(ObjectUtil.java:125)

从我 debug 跟踪来看,是代码在 logutils 里面的好几个方法里面来回执行,似乎是陷入了调用死循环里面。

有些对象层级太多,根本打不完 打一定层数就该停止

at com.apkfuns.logutils.utils.ObjectUtil.objectToString(ObjectUtil.java:32)
at com.apkfuns.logutils.utils.ObjectUtil.getClassFields(ObjectUtil.java:90)
at com.apkfuns.logutils.utils.ObjectUtil.objectToString(ObjectUtil.java:41)
at com.apkfuns.logutils.utils.ObjectUtil.getClassFields(ObjectUtil.java:90)
at com.apkfuns.logutils.utils.ObjectUtil.objectToString(ObjectUtil.java:41)
at com.apkfuns.logutils.utils.ObjectUtil.objectToString(ObjectUtil.java:22)
at com.apkfuns.logutils.parser.CollectionParse.parseString(CollectionParse.java:29)
at com.apkfuns.logutils.parser.CollectionParse.parseString(CollectionParse.java:12)
at com.apkfuns.logutils.utils.ObjectUtil.objectToString(ObjectUtil.java:32)
at com.apkfuns.logutils.utils.ObjectUtil.getClassFiel
04-22 13:30:02.592 24424-24442/com.protontek.vcare E/vcare/JobFragV1$7.onServicesDiscovered(JobFragV1.java:737): ds(ObjectUtil.java:90)
at com.apkfuns.logutils.utils.ObjectUtil.objectToString(ObjectUtil.java:41)
at com.apkfuns.logutils.utils.ObjectUtil.getClassFields(ObjectUtil.java:90)
at com.apkfuns.logutils.utils.ObjectUtil.objectToString(ObjectUtil.java:41)
at com.apkfuns.logutils.utils.ObjectUtil.objectToString(ObjectUtil.java:22)
at com.apkfuns.logutils.parser.CollectionParse.parseString(CollectionParse.java:29)
at com.apkfuns.logutils.parser.CollectionParse.parseString(CollectionParse.java:12)
at com.apkfuns.logutils.utils.ObjectUtil.objectToString(ObjectUtil.java:32)
at com.apkfuns.logutils.utils.ObjectUtil.getClassFields(ObjectUtil.java:90)
at com.apkfuns.logutils.utils.ObjectUtil.objectToString(ObjectUtil.java:41)
at com.apkfuns.logutils.utils.ObjectUtil.objectToString(ObjectUtil.java:22)
at com.apkfuns.logutils.parser.CollectionParse.parseString(CollectionParse.java:29)
at com.apkfuns.logutils.parser.CollectionParse.parseString(CollectionParse.java:12)
at com.apkfuns.logutils.utils.ObjectUtil.objectToString(ObjectUtil.java:32)
at com.apkfuns.logutils.utils.ObjectUtil.objectToString(ObjectUtil.java:22)
at com.apkfuns.logutils.Logger.logObject(Logger.java:97)
at com.apkfuns.logutils.Logger.e(Logger.java:161)
at com.apkfuns.logutils.LogUtils.e(LogUtils.java:108)
at com.protontek.vcare.ui.module.job.JobFragV1$7.onServicesDiscovered(JobFragV1.java:735)
at android.bluetooth.BluetoothGatt$1.onSearchComplete(BluetoothGatt.java:304)
at android.bluetooth.IBluetoothGattCallback$Stub.onTransact(IBluetoothGattCallback.java:217)
at android.os.Binder.execTransact(Binder.java:453)

源码怎么导出Jar包

需要更改些源码,使其更加匹配自己的想要的打印,但怎么导出Jar包呢?

希望可以临时加入tag

比如orhanobut的logger支持临时.t('TAG‘),有时候还是需要加以区分的。另外在打印普通的地方不知道为什么没有显示外边框。只在打印json才显示,但我已经开启了。

性能问题

我为了不影响release 版本的效率,我通过config 把log关闭,然后再使用hugo 简单做了一下性能测试,发现即使关闭了log,它还会去判断 该怎么打印 log,这会花费很多时间。我在MainActivity里,onCreate一共花费了140ms,但是132ms是耗费在log里。这里可以做一做优化。

具体 测试 代码 请参考 我的 pull request

#20

打印 Cursor时的空指针异常

`

java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.Object.equals(java.lang.Object)' on a null object reference
                                                       at com.apkfuns.logutils.utils.ObjectUtil.objectToString(ObjectUtil.java:63)
                                                       at com.apkfuns.logutils.utils.ObjectUtil.getClassFields(ObjectUtil.java:114)
                                                       at com.apkfuns.logutils.utils.ObjectUtil.objectToString(ObjectUtil.java:64)
                                                       at com.apkfuns.logutils.utils.ObjectUtil.getClassFields(ObjectUtil.java:114)
                                                       at com.apkfuns.logutils.utils.ObjectUtil.objectToString(ObjectUtil.java:64)
                                                       at com.apkfuns.logutils.utils.ObjectUtil.objectToString(ObjectUtil.java:23)
                                                       at com.apkfuns.logutils.Logger.logObject(Logger.java:121)
                                                       at com.apkfuns.logutils.Logger.e(Logger.java:214)
                                                       at com.apkfuns.logutils.LogUtils.e(LogUtils.java:94)

`

当有多个进程的时候我在Application里面会打印多次,用系统默认的log只打印一次!!

已经做了进程名pid的判断

    String processName = CommonUtil.getProcessName(this,
            android.os.Process.myPid());
    if (processName != null) {
        boolean defaultProcess = processName
                .equals("com.xx.xxx");
        if (defaultProcess) {
            //必要的初始化资源操作

            LogUtils.getLogConfig()
                    .configAllowLog(BuildConfig.DEBUG);
                    Log.e("*************","**********");   //系统的值打印一次
            LogUtils.e(titles);//   titles是个集合打印了多次会出现多次
        }

对比原生log,性能下降明显

使用demo中的配置,打印hello world 3000次,原生的只需要40ms,LogUtils需要6000ms,虽然是方便了不少,担心在大型项目上性能损失严重,有优化的可能不?

json打印

当json嵌套多层的时候 打印出来的结果看不全

用了一年多了

用了一年多了.几个月没看一下子丰富了那么多功能.我也fork了希望能有机会做点贡献.

java.lang.ClassCastException: char[] cannot be cast to java.lang.Object[]

at com.apkfuns.logutils.utils.ArrayUtil.traverseArray(ArrayUtil.java:97)
at com.apkfuns.logutils.utils.ArrayUtil.parseArray(ArrayUtil.java:123)
at com.apkfuns.logutils.utils.ObjectUtil.objectToString(ObjectUtil.java:59)
at com.apkfuns.logutils.utils.ObjectUtil.getClassFields(ObjectUtil.java:125)
at com.apkfuns.logutils.utils.ObjectUtil.objectToString(ObjectUtil.java:63)
at com.apkfuns.logutils.utils.ObjectUtil.getClassFields(ObjectUtil.java:125)
at com.apkfuns.logutils.utils.ObjectUtil.objectToString(ObjectUtil.java:63)
at com.apkfuns.logutils.utils.ObjectUtil.objectToString(ObjectUtil.java:25)
at com.apkfuns.logutils.parser.CollectionParse.parseString(CollectionParse.java:31)
at com.apkfuns.logutils.parser.CollectionParse.parseString(CollectionParse.java:14)
at com.apkfuns.logutils.utils.ObjectUtil.objectToString(ObjectUtil.java:54)
at com.apkfuns.logutils.utils.ObjectUtil.objectToString(ObjectUtil.java:25)
at com.apkfuns.logutils.Logger.logObject(Logger.java:127)
at com.apkfuns.logutils.Logger.e(Logger.java:217)
at com.apkfuns.logutils.LogUtils.e(LogUtils.java:103)

打印超长字符串时候的bug

1.5.1版本
如果设置了默认的tag
LogUtils.getLogConfig() .configTagPrefix("aaa")//日志log的前缀
在打印超长json的时候会分段,如果不使用默认的tag,而是类似这样写LogUtils.d("bbb",json).
只有第一部分的tag是bbb,其他几段的tag都是aaa.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.