LogUtils
More convenient and easy to use android Log manager
1. Features
- ??????????,?List?Set?Map????
- ????log??
- ?????Tag
- ?????????????????????
- ??android????Intent?Bundle??
- ??release-no-op??
- ????????
2. screenshot
????
?????Tag
??????
????
??????????????
??????Intent
3. Simple
// ????? LogUtils.d("12345");
// ???? LogUtils.d("12%s3%d45", "a", 0);
// ???? LogUtils.d(new NullPointerException("12345"));
// ???? Person person = new Person();
person.setAge(11);
person.setName("pengwei");
person.setScore(37.5f);
LogUtils.d(person);
// ???? LogUtils.d(null);
// ??json?json??debug??? String json = "{
'a':'b','c':{
'aa':234,'dd':{
'az':12
}
}
}
"; LogUtils.json(json);
// ?????? List<Person> list1 = new ArrayList<>();
for(int i = 0; i < 4; i++){
list1.add(person);
}
LogUtils.d(list1);
// ???? double[][] doubles = {
{
1.2, 1.6, 1.7, 30, 33
}
,
{
1.2, 1.6, 1.7, 30, 33
}
,
{
1.2, 1.6, 1.7, 30, 33
}
,
{
1.2, 1.6, 1.7, 30, 33
}
}
; LogUtils.d(doubles);
// ???tag LogUtils.tag("?????tag").d("??????");
// ???? LogUtils.v("12345");
LogUtils.i("12345");
LogUtils.w("12345");
LogUtils.e("12345");
LogUtils.wtf("12345");
options
?? | ?? | ?? | ?? |
---|---|---|---|
configAllowLog | ???????? | boolean | true |
configTagPrefix | ??log??? | String | "LogUtils" |
configShowBorders | ?????? | boolean | false |
configLevel | ?????? | LogLevelType | LogLevel.TYPE_VERBOSE |
addParserClass | ??????? | Parser | ? |
configFormatTag | ?????Tag | String | %c{ -5 } |
configMethodOffset | ????? | int | 0 |
????????
?? | ?? | ?? | ?? |
---|---|---|---|
configLog2FileEnable | ???????? | boolean | false |
configLog2FilePath | ?????? | String | /sdcard/LogUtils/logs/ |
configLog2FileNameFormat | ??????? | string | %d{ yyyyMMdd } .txt |
configLog2FileLevel | ?????? | LogLevelType | LogLevel.TYPE_VERBOSE |
configLogFileEngine | ?????? | LogFileEngine | ? |
configLogFileFilter | ?????? | LogFileFilter | ? |
Demo
LogUtils.getLogConfig()
.configAllowLog(true)
.configTagPrefix("MyAppName")
.configShowBorders(true)
.configFormatTag("%d{
HH:mm:ss:SSS
}
%t %c{
-5
}
") # ????????? LogUtils.getLog2FileConfig().configLog2FileEnable(true)
// targetSdkVersion >= 23 ??????sdcard??
.configLog2FilePath("/sdcard/?????/logs/")
.configLog2FileNameFormat("%d{
yyyyMMdd
}
.txt")
.configLogFileEngine(new LogFileEngineFactory());
configFormatTag????
?? | ?? | ?? | ?? | ?? | ???? |
---|---|---|---|---|---|
%% | ? | ??% | ? | %%d | %d |
%date | %d | ???? | ?????,?HH:mm:ss | %d{ HH:mm:ss:SSS } | 10:00:46:238 |
%thread | %t | ?????? | ? | %t | thread-127 |
%caller | %c | ???????? | ???%c{
-5
}
???????%c{
??
}
??%caller{
??
}
????????????? com.apkfuns.logutils.demo.MainActivity.onCreate(MainActivity.java:135) ,%c{
1
}
?? com ??.??????,????0??????n???%c{
-1
}
???? apkfuns.logutils.demo.activity.MainActivity.onCreate(MainActivity.java:135) , | %c{ -5 } | MainActivity.onCreate(MainActivity.java:135) |
???????
??Parser??????parseClassType() ?parseString()??,???addParserClass()???LogUtil ????
4. Usage
Gradle
compile 'com.apkfuns.logutils:library:1.5.1.1'
release-no-op??
debugCompile 'com.apkfuns.logutils:library:1.5.1.1' releaseCompile 'com.apkfuns.logutils:logutils-no-op:1.5.1.1'
???????
- ??log2file?(??okio)
compile 'com.apkfuns.log2file:log2file:1.0.0' ... ???????okio(?pokhttp)??? compile('com.apkfuns.log2file:log2file:1.0.0') {
exclude module: 'okio'
}
... LogUtils.getLog2FileConfig().configLogFileEngine(new LogFileEngineFactory());
- ??LogFileEngine??
public class MyLogFileEngine implements LogFileEngine {
@Override
public void writeToFile(File logFile, String logContent, LogFileParam params) {
....
}
}
... LogUtils.getLog2FileConfig().configLogFileEngine(new MyLogFileEngine());
??????????
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
Eclipse??Jar
click here to download *.jar
5. Skills
6. History
- 1.0.0 (2015/07/13)
- ???????????
- ??????????
- 1.0.1 (2015/07/22)
- ??json???
- 1.0.2 (2015/07/24)
- ????List?Se?????
- 1.0.3 (2015/07/24)
- ????Map??
- 1.0.4 (2015/07/25)
- ??????(???????????)
- 1.0.6 (2015/08/28)
- ?????????%s???bug
- 1.1.0 (2016/03/02)
- ???Exception?????
- 1.2.0 (2016/03/09)
- ??android????Bundle?Intent???
- ??????
- ??????
- ?????????
- ???????4k??
- 1.2.1 (2016/03/14)
- ??Intent??Flags??
- ?????Parse???Parse?????
- 1.2.2 (2016/03/22)
- ????Reference??bug
- 1.3.0 (2016/04/20)
- ???????????????
- 1.3.1 (2016/05/09)
- ???????????????
- 1.4.0 (2016/05/19)
- ??????tag
- ??xml??
- ?? issue 10?????
- 1.4.2 (2016/05/23)
- ?????Tag(configFormatTag(); )
- **1.4.3 **
- ??Instant Run????????????
- 1.5.1 (2017/03/31)
- ???????????
7. About
- Blog: apkfuns.com
- Email: [email protected]
8. Thanks
- thanks to tinybright? DrSlark's advice.
- thanks to wyouflf/xUtils? orhanobut/logger? ZhaoKaiQiang/KLog? noveogroup/android-logger
9. License
Copyright 2015-2016 pengwei1024 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.