All Projects → iflove → Logcat

iflove / Logcat

Licence: other
这是一个Android 上 效率极高的 Log 工具,主要功能为控制不同级别的Log输出,Log信息保存到文件、打印行号、函数调用、Json解析、点击跳转、多标签Tag 支持无限长字符串打印,无Logcat4000字符限制等功能

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Logcat

logcatf
A Command line tool for format Android Logcat.
Stars: ✭ 17 (-81.11%)
Mutual labels:  logcat
TLog
Android日志工具
Stars: ✭ 16 (-82.22%)
Mutual labels:  logcat
MyLogLibrary
🚧 - Simple Android Kotlin logger (2017/2020)
Stars: ✭ 31 (-65.56%)
Mutual labels:  logcat
LogDelegate
Simple, pretty and powerful logger for android
Stars: ✭ 287 (+218.89%)
Mutual labels:  logcat
datalogger
DataLogger foi projetado para ser uma biblioteca simples de log com suporte a vários providers.
Stars: ✭ 46 (-48.89%)
Mutual labels:  logcat
slf4j-timber
SLF4J binding for Timber - a logger with a small, extensible API which provides utility on top of Android's normal Log class.
Stars: ✭ 20 (-77.78%)
Mutual labels:  logcat
Xlog
Android logger, pretty, powerful and flexible, log to everywhere, save to file, all you want is here.
Stars: ✭ 2,468 (+2642.22%)
Mutual labels:  logcat
Logger
✔️ Simple, pretty and powerful logger for android
Stars: ✭ 13,093 (+14447.78%)
Mutual labels:  logcat
StreamingAndroidLogger
Logger
Stars: ✭ 43 (-52.22%)
Mutual labels:  logcat
logcat-colorize
Command that takes adb logcat from stdin and produces formatted colorized to stdout, written in C++.
Stars: ✭ 21 (-76.67%)
Mutual labels:  logcat
dora
🌟Dora is an open-source framework focused on usability and flexibility.It is widely used to collect crash information and print variable values.It is very powerful and useful to debug android program. It is customizable and extensible in the simpleton-like ways. Dora是一个专注于易用性和灵活性的开源框架,它被广泛用于收集崩溃信息和打印变量值,对调试Android程序非常强大和有用,傻瓜式的自定义和扩展。
Stars: ✭ 15 (-83.33%)
Mutual labels:  logcat
aixlog
Header-only C++ logging library
Stars: ✭ 95 (+5.56%)
Mutual labels:  logcat

迁移:https://github.com/iflove/Android-Projects

Logcat

CircleCI MyGet tenant

这是一个Android 上 效率极高的 Log 工具,主要功能为控制不同级别的Log输出,Log信息保存到文件、打印行号、函数调用、Json解析、点击跳转、多标签Tag 支持无限长字符串打印,无Logcat4000字符限制等功能

打印行号、函数调用、Json解析、点击跳转 参照KLog of ZhaoKaiQiang. 推荐:logExtlibrary 作为相关子模块块log的打印,主模块实现Logger接口相关方法


Gradle

dependencies {
    implementation 'com.github.iflove:Logcat:2.1.2'
    #子模块用
    implementation 'com.github.iflove.Hunter:logExtlibrary:logExtlibrary-1.0'
}

1.开始使用 Logcat

你只需要在 Application 里面调用Logcat.initialize一次即可完成初始化

//初始化Logcat
Logcat.initialize(this);

配置更多信息

Builder builder = Logcat.newBuilder();
//设置Log 保存的文件夹
builder.logSavePath(StorageUtils.getDiskCacheDir(this, "log"));
//设置输出日志等级
if (BuildConfig.DEBUG) {
    builder.logCatLogLevel(Logcat.SHOW_ALL_LOG);
    //设置输出文件日志等级
    builder.fileLogLevel(Logcat.SHOW_ALL_LOG);
} else {
    builder.logCatLogLevel(Logcat.SHOW_INFO_LOG | Logcat.SHOW_WARN_LOG | Logcat.SHOW_ERROR_LOG);
    //设置输出文件日志等级
    builder.fileLogLevel(Logcat.SHOW_INFO_LOG | Logcat.SHOW_WARN_LOG | Logcat.SHOW_ERROR_LOG);
}
//不显示日志
//builder.fileLogLevel(Logcat.NOT_SHOW_LOG);

builder.topLevelTag(TAG_TOP_1);
//删除过了几天无用日志条目
builder.deleteUnusedLogEntriesAfterDays(7);
//输出到Java控制台服务端
if (isMainProcess) {
    builder.dispatchLog(new JLog("192.168.3.11", 5036));
}
//是否自动保存日志到文件中
builder.autoSaveLogToFile(true);
//是否显示打印日志调用堆栈信息
builder.showStackTraceInfo(true);
//是否显示文件日志的时间
builder.showFileTimeInfo(true);
//是否显示文件日志的进程以及Linux线程
builder.showFilePidInfo(true);
//是否显示文件日志级别
builder.showFileLogLevel(true);
//是否显示文件日志标签
builder.showFileLogTag(true);
//是否显示文件日志调用堆栈信息
builder.showFileStackTraceInfo(true);
//添加该标签,日志将被写入文件
builder.addTagToFile(TAG_APP_EVENT);
Logcat.initialize(this, builder.build());

2.示例

//控制台
Logcat.v("The is verbose log");
Logcat.d("The is debug log");
Logcat.i("The is info log");
Logcat.w("The is warn log");
Logcat.e("The is error log");

3.LogTransaction 为Logcat 提供灵活的链式调用api

msg(@NonNull final Object msg);// 打印 msg
msgs(@NonNull final Object... msg);// n ... msg
tag(@NonNull final String tag);// 打印 tag
tags(@NonNull final String... tags); //n ... tag
file(); // log默认输出到文件
file(@NonNull final String fileName); //指定文件名
ln(); //换行
format(@NonNull final String format, Object... args); //格式化
out(); //输出log

4.Logcat log 文件

--默认log文件夹 sdcard/Android/data/you.pakeage/cache/logs//默认文件log 格式
11-29 22:25:32.363 5523-1/com.lazy.logging V/Logcat[ (MainActivity.java:104)#PrintLog ] output file msg 

5.JLog

安卓开发者都知道,Android系统的单条日志打印长度是有限的, 底层Logger Logger.h 文件中限制了输出日志字符的大小,具体原因就不造了。

Logger.h

#define LOGGER_ENTRY_MAX_LEN        (4*1024)  
#define LOGGER_ENTRY_MAX_PAYLOAD    \\  
    (LOGGER_ENTRY_MAX_LEN - sizeof(struct logger_entry))

开发也没法子通过API来改变这一值。只能采取分段打印的办法输出日志信息。但是我发现了Java 的System.out.println() 是没有限制的,但是在安卓平台上这会转变为安卓INFO 级的日志,而且无需你分段打印的输出日志(是不是很😑)。在实际项目中,一般就也只有请求HTTP接口,而接口又是返回一个比较大JSON,超过4000 字符,安卓的Log API 就好截断,就无法看到完整的响应数据了。采取分段输出,虽然能看到完整的响应数据,但是每达4000字符时突然的换行以及不对齐,稍微不慎就会拷错,拷多json 字符串处理用工具解析查看。当然每次调试看请求数据也是可以的不过很是低效的。所以我做了个大胆的尝试(加入JLog),通过 socket 把日志传送到Java的控制中打印。

JLogServer

Run JLogServer 步骤: 下载JLogServer.java 到你的项目,用as 直接run main(),JLogServer 可以配置相应的端口,也可以用adb 端口映射。

Logcat dispatchLog

...
builder.dispatchLog(new JLog("192.168.3.15", 5036));

6.Future

JLogServer.java 是否能作为一个idea intellij plugin ?

7.Sample Usage

超长的Log完美输出

文件Log输出格式

License

Copyright  2016 Lazy

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.

About me
Email: [email protected]

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].