├── .gitignore
├── .idea
├── compiler.xml
├── copyright
│ └── profiles_settings.xml
├── gradle.xml
├── misc.xml
├── modules.xml
└── runConfigurations.xml
├── README.MD
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── orhanobut
│ │ └── loggerdemo
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── orhanobut
│ │ │ └── loggerdemo
│ │ │ └── MainActivity.java
│ └── res
│ │ ├── layout
│ │ └── activity_main.xml
│ │ ├── mipmap-hdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-mdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xhdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxhdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxxhdpi
│ │ └── ic_launcher.png
│ │ ├── values-w820dp
│ │ └── dimens.xml
│ │ └── values
│ │ ├── colors.xml
│ │ ├── dimens.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── com
│ └── orhanobut
│ └── loggerdemo
│ └── ExampleUnitTest.java
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── logger
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── orhanobut
│ │ └── logger
│ │ ├── AndroidLogAdapter.java
│ │ ├── Helper.java
│ │ ├── LogAdapter.java
│ │ ├── LogLevel.java
│ │ ├── Logger.java
│ │ ├── LoggerPrinter.java
│ │ ├── Printer.java
│ │ └── Settings.java
│ └── res
│ └── values
│ └── strings.xml
├── loggerdemo2
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── orhanobut
│ │ └── loggerdemo2
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── orhanobut
│ │ │ └── loggerdemo2
│ │ │ └── MainActivity.java
│ └── res
│ │ ├── layout
│ │ └── activity_main.xml
│ │ ├── mipmap-hdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-mdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xhdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxhdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxxhdpi
│ │ └── ic_launcher.png
│ │ ├── values-w820dp
│ │ └── dimens.xml
│ │ └── values
│ │ ├── colors.xml
│ │ ├── dimens.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── com
│ └── orhanobut
│ └── loggerdemo2
│ └── ExampleUnitTest.java
├── screenshot.png
├── screenshot2.png
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 | .externalNativeBuild
10 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
19 |
20 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/README.MD:
--------------------------------------------------------------------------------
1 | # orhanobut logger项目使用
2 |
3 | 开源地址:[https://github.com/open-android/Logger](https://github.com/open-android/Logger "https://github.com/open-android/Logger")
4 |
5 | # 运行效果
6 |
7 | 
8 |
9 |
10 |
11 | ## 使用步骤
12 |
13 | ### 1. 在project的build.gradle添加如下代码(如下图)
14 |
15 | allprojects {
16 | repositories {
17 | maven { url "https://jitpack.io" }
18 | }
19 | }
20 |
21 | 
22 |
23 | ### 2. 在Module的build.gradle添加依赖
24 |
25 | compile 'com.github.open-android:Logger:v1.0.0'
26 |
27 |
28 | ### 3.调用Logger功能
29 |
30 | Logger.d("打印logger信息");//输出结果如第一张 运行效果图
31 |
32 |
33 |
34 | * 详细的使用方法在DEMO里面都演示啦,如果你觉得这个库还不错,请赏我一颗star吧~~~
35 |
36 | * 欢迎关注微信公众号
37 |
38 | 
39 |
40 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 25
5 | buildToolsVersion "25.0.1"
6 | defaultConfig {
7 | applicationId "com.orhanobut.loggerdemo"
8 | minSdkVersion 9
9 | targetSdkVersion 25
10 | versionCode 1
11 | versionName "1.0"
12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(include: ['*.jar'], dir: 'libs')
24 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
25 | exclude group: 'com.android.support', module: 'support-annotations'
26 | })
27 | compile 'com.android.support:appcompat-v7:25.1.0'
28 | testCompile 'junit:junit:4.12'
29 | compile project(':logger')
30 | }
31 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in D:\ProgramFiles\Android\sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/orhanobut/loggerdemo/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.orhanobut.loggerdemo;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.orhanobut.loggerdemo", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/app/src/main/java/com/orhanobut/loggerdemo/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.orhanobut.loggerdemo;
2 |
3 | import android.os.Bundle;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.view.View;
6 | import android.widget.Button;
7 |
8 | import com.orhanobut.logger.Logger;
9 |
10 | public class MainActivity extends AppCompatActivity implements View.OnClickListener {
11 |
12 | private Button mBtn1;
13 |
14 | @Override
15 | protected void onCreate(Bundle savedInstanceState) {
16 | super.onCreate(savedInstanceState);
17 | setContentView(R.layout.activity_main);
18 | initView();
19 | }
20 |
21 | private void initView() {
22 | mBtn1 = (Button) findViewById(R.id.btn1);
23 |
24 | mBtn1.setOnClickListener(this);
25 | }
26 |
27 | @Override
28 | public void onClick(View v) {
29 | switch (v.getId()) {
30 | case R.id.btn1:
31 | Logger.d("hello test");
32 | break;
33 | }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/open-android/Logger/6b6d86ba9495a7e40210400736ef0df7cc14325e/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/open-android/Logger/6b6d86ba9495a7e40210400736ef0df7cc14325e/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/open-android/Logger/6b6d86ba9495a7e40210400736ef0df7cc14325e/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/open-android/Logger/6b6d86ba9495a7e40210400736ef0df7cc14325e/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/open-android/Logger/6b6d86ba9495a7e40210400736ef0df7cc14325e/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Logger
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/com/orhanobut/loggerdemo/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.orhanobut.loggerdemo;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:2.2.2'
9 | classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
10 | }
11 | }
12 |
13 | allprojects {
14 | repositories {
15 | jcenter()
16 | maven { url 'https://jitpack.io' }
17 | }
18 |
19 | }
20 |
21 | task clean(type: Delete) {
22 | delete rootProject.buildDir
23 | }
24 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/open-android/Logger/6b6d86ba9495a7e40210400736ef0df7cc14325e/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Dec 28 10:00:20 PST 2015
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/logger/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/logger/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'com.github.dcendents.android-maven'
3 | group='com.github.open-android'
4 | android {
5 | compileSdkVersion 25
6 | buildToolsVersion "25.0.1"
7 |
8 | defaultConfig {
9 | minSdkVersion 9
10 | targetSdkVersion 25
11 | versionCode 1
12 | versionName "1.0"
13 |
14 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
15 |
16 | }
17 | buildTypes {
18 | release {
19 | minifyEnabled false
20 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
21 | }
22 | }
23 | }
24 |
25 | dependencies {
26 | compile fileTree(dir: 'libs', include: ['*.jar'])
27 | compile 'com.android.support:appcompat-v7:25.1.0'
28 | }
29 |
--------------------------------------------------------------------------------
/logger/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in D:\ProgramFiles\Android\sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/logger/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/logger/src/main/java/com/orhanobut/logger/AndroidLogAdapter.java:
--------------------------------------------------------------------------------
1 | package com.orhanobut.logger;
2 |
3 | import android.util.Log;
4 |
5 | class AndroidLogAdapter implements LogAdapter {
6 | @Override public void d(String tag, String message) {
7 | Log.d(tag, message);
8 | }
9 |
10 | @Override public void e(String tag, String message) {
11 | Log.e(tag, message);
12 | }
13 |
14 | @Override public void w(String tag, String message) {
15 | Log.w(tag, message);
16 | }
17 |
18 | @Override public void i(String tag, String message) {
19 | Log.i(tag, message);
20 | }
21 |
22 | @Override public void v(String tag, String message) {
23 | Log.v(tag, message);
24 | }
25 |
26 | @Override public void wtf(String tag, String message) {
27 | Log.wtf(tag, message);
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/logger/src/main/java/com/orhanobut/logger/Helper.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Orhan Obut
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | * This software contains code derived from the following Android classes:
17 | * android.util.Log, android.text.TextUtils.
18 | */
19 | package com.orhanobut.logger;
20 |
21 | import java.io.PrintWriter;
22 | import java.io.StringWriter;
23 | import java.net.UnknownHostException;
24 |
25 | /**
26 | * Helper util class to be used instead of Android methods to avoid direct dependency and enable
27 | * unit testing on Android projects.
28 | */
29 | final class Helper {
30 |
31 | private Helper() {
32 | // Hidden constructor.
33 | }
34 |
35 | /**
36 | * Returns true if the string is null or 0-length.
37 | *
38 | * @param str the string to be examined
39 | *
40 | * @return true if str is null or zero length
41 | */
42 | static boolean isEmpty(CharSequence str) {
43 | return str == null || str.length() == 0;
44 | }
45 |
46 | /**
47 | * Returns true if a and b are equal, including if they are both null.
48 | *
Note: In platform versions 1.1 and earlier, this method only worked well if
49 | * both the arguments were instances of String.
50 | *
51 | * @param a first CharSequence to check
52 | * @param b second CharSequence to check
53 | *
54 | * @return true if a and b are equal
55 | *
56 | * NOTE: Logic slightly change due to strict policy on CI -
57 | * "Inner assignments should be avoided"
58 | */
59 | static boolean equals(CharSequence a, CharSequence b) {
60 | if (a == b) return true;
61 | if (a != null && b != null) {
62 | int length = a.length();
63 | if (length == b.length()) {
64 | if (a instanceof String && b instanceof String) {
65 | return a.equals(b);
66 | } else {
67 | for (int i = 0; i < length; i++) {
68 | if (a.charAt(i) != b.charAt(i)) return false;
69 | }
70 | return true;
71 | }
72 | }
73 | }
74 | return false;
75 | }
76 |
77 | /**
78 | * Copied from "android.util.Log.getStackTraceString()" in order to avoid usage of Android stack
79 | * in unit tests.
80 | *
81 | * @return Stack trace in form of String
82 | */
83 | static String getStackTraceString(Throwable tr) {
84 | if (tr == null) {
85 | return "";
86 | }
87 |
88 | // This is to reduce the amount of log spew that apps do in the non-error
89 | // condition of the network being unavailable.
90 | Throwable t = tr;
91 | while (t != null) {
92 | if (t instanceof UnknownHostException) {
93 | return "";
94 | }
95 | t = t.getCause();
96 | }
97 |
98 | StringWriter sw = new StringWriter();
99 | PrintWriter pw = new PrintWriter(sw);
100 | tr.printStackTrace(pw);
101 | pw.flush();
102 | return sw.toString();
103 | }
104 |
105 | }
106 |
--------------------------------------------------------------------------------
/logger/src/main/java/com/orhanobut/logger/LogAdapter.java:
--------------------------------------------------------------------------------
1 | package com.orhanobut.logger;
2 |
3 | public interface LogAdapter {
4 | void d(String tag, String message);
5 |
6 | void e(String tag, String message);
7 |
8 | void w(String tag, String message);
9 |
10 | void i(String tag, String message);
11 |
12 | void v(String tag, String message);
13 |
14 | void wtf(String tag, String message);
15 | }
--------------------------------------------------------------------------------
/logger/src/main/java/com/orhanobut/logger/LogLevel.java:
--------------------------------------------------------------------------------
1 | package com.orhanobut.logger;
2 |
3 | public enum LogLevel {
4 |
5 | /**
6 | * Prints all logs
7 | */
8 | FULL,
9 |
10 | /**
11 | * No log will be printed
12 | */
13 | NONE
14 | }
15 |
--------------------------------------------------------------------------------
/logger/src/main/java/com/orhanobut/logger/Logger.java:
--------------------------------------------------------------------------------
1 | package com.orhanobut.logger;
2 |
3 | /**
4 | * Logger is a wrapper of {@link android.util.Log}
5 | * But more pretty, simple and powerful
6 | */
7 | public final class Logger {
8 | public static final int DEBUG = 3;
9 | public static final int ERROR = 6;
10 | public static final int ASSERT = 7;
11 | public static final int INFO = 4;
12 | public static final int VERBOSE = 2;
13 | public static final int WARN = 5;
14 |
15 | private static final String DEFAULT_TAG = "PRETTYLOGGER";
16 |
17 | private static Printer printer = new LoggerPrinter();
18 |
19 | //no instance
20 | private Logger() {
21 | }
22 |
23 | /**
24 | * It is used to get the settings object in order to change settings
25 | *
26 | * @return the settings object
27 | */
28 | public static Settings init() {
29 | return init(DEFAULT_TAG);
30 | }
31 |
32 | /**
33 | * It is used to change the tag
34 | *
35 | * @param tag is the given string which will be used in Logger as TAG
36 | */
37 | public static Settings init(String tag) {
38 | printer = new LoggerPrinter();
39 | return printer.init(tag);
40 | }
41 |
42 | public static void resetSettings() {
43 | printer.resetSettings();
44 | }
45 |
46 | public static Printer t(String tag) {
47 | return printer.t(tag, printer.getSettings().getMethodCount());
48 | }
49 |
50 | public static Printer t(int methodCount) {
51 | return printer.t(null, methodCount);
52 | }
53 |
54 | public static Printer t(String tag, int methodCount) {
55 | return printer.t(tag, methodCount);
56 | }
57 |
58 | public static void log(int priority, String tag, String message, Throwable throwable) {
59 | printer.log(priority, tag, message, throwable);
60 | }
61 |
62 | public static void d(String message, Object... args) {
63 | printer.d(message, args);
64 | }
65 |
66 | public static void d(Object object) {
67 | printer.d(object);
68 | }
69 |
70 | public static void e(String message, Object... args) {
71 | printer.e(null, message, args);
72 | }
73 |
74 | public static void e(Throwable throwable, String message, Object... args) {
75 | printer.e(throwable, message, args);
76 | }
77 |
78 | public static void i(String message, Object... args) {
79 | printer.i(message, args);
80 | }
81 |
82 | public static void v(String message, Object... args) {
83 | printer.v(message, args);
84 | }
85 |
86 | public static void w(String message, Object... args) {
87 | printer.w(message, args);
88 | }
89 |
90 | public static void wtf(String message, Object... args) {
91 | printer.wtf(message, args);
92 | }
93 |
94 | /**
95 | * Formats the json content and print it
96 | *
97 | * @param json the json content
98 | */
99 | public static void json(String json) {
100 | printer.json(json);
101 | }
102 |
103 | /**
104 | * Formats the json content and print it
105 | *
106 | * @param xml the xml content
107 | */
108 | public static void xml(String xml) {
109 | printer.xml(xml);
110 | }
111 |
112 | }
113 |
--------------------------------------------------------------------------------
/logger/src/main/java/com/orhanobut/logger/LoggerPrinter.java:
--------------------------------------------------------------------------------
1 | package com.orhanobut.logger;
2 |
3 | import org.json.JSONArray;
4 | import org.json.JSONException;
5 | import org.json.JSONObject;
6 |
7 | import java.io.StringReader;
8 | import java.io.StringWriter;
9 | import java.util.Arrays;
10 |
11 | import javax.xml.transform.OutputKeys;
12 | import javax.xml.transform.Source;
13 | import javax.xml.transform.Transformer;
14 | import javax.xml.transform.TransformerException;
15 | import javax.xml.transform.TransformerFactory;
16 | import javax.xml.transform.stream.StreamResult;
17 | import javax.xml.transform.stream.StreamSource;
18 |
19 | final class LoggerPrinter implements Printer {
20 |
21 | private static final String DEFAULT_TAG = "PRETTYLOGGER";
22 |
23 | private static final int DEBUG = 3;
24 | private static final int ERROR = 6;
25 | private static final int ASSERT = 7;
26 | private static final int INFO = 4;
27 | private static final int VERBOSE = 2;
28 | private static final int WARN = 5;
29 |
30 | /**
31 | * Android's max limit for a log entry is ~4076 bytes,
32 | * so 4000 bytes is used as chunk size since default charset
33 | * is UTF-8
34 | */
35 | private static final int CHUNK_SIZE = 4000;
36 |
37 | /**
38 | * It is used for json pretty print
39 | */
40 | private static final int JSON_INDENT = 2;
41 |
42 | /**
43 | * The minimum stack trace index, starts at this class after two native calls.
44 | */
45 | private static final int MIN_STACK_OFFSET = 3;
46 |
47 | /**
48 | * Drawing toolbox
49 | */
50 | private static final char TOP_LEFT_CORNER = '╔';
51 | private static final char BOTTOM_LEFT_CORNER = '╚';
52 | private static final char MIDDLE_CORNER = '╟';
53 | private static final char HORIZONTAL_DOUBLE_LINE = '║';
54 | private static final String DOUBLE_DIVIDER = "════════════════════════════════════════════";
55 | private static final String SINGLE_DIVIDER = "────────────────────────────────────────────";
56 | private static final String TOP_BORDER = TOP_LEFT_CORNER + DOUBLE_DIVIDER + DOUBLE_DIVIDER;
57 | private static final String BOTTOM_BORDER = BOTTOM_LEFT_CORNER + DOUBLE_DIVIDER + DOUBLE_DIVIDER;
58 | private static final String MIDDLE_BORDER = MIDDLE_CORNER + SINGLE_DIVIDER + SINGLE_DIVIDER;
59 |
60 | /**
61 | * tag is used for the Log, the name is a little different
62 | * in order to differentiate the logs easily with the filter
63 | */
64 | private String tag;
65 |
66 | /**
67 | * Localize single tag and method count for each thread
68 | */
69 | private final ThreadLocal localTag = new ThreadLocal<>();
70 | private final ThreadLocal localMethodCount = new ThreadLocal<>();
71 |
72 | /**
73 | * It is used to determine log settings such as method count, thread info visibility
74 | */
75 | private final Settings settings = new Settings();
76 |
77 | public LoggerPrinter() {
78 | init(DEFAULT_TAG);
79 | }
80 |
81 | /**
82 | * It is used to change the tag
83 | *
84 | * @param tag is the given string which will be used in Logger
85 | */
86 | @Override public Settings init(String tag) {
87 | if (tag == null) {
88 | throw new NullPointerException("tag may not be null");
89 | }
90 | if (tag.trim().length() == 0) {
91 | throw new IllegalStateException("tag may not be empty");
92 | }
93 | this.tag = tag;
94 | return settings;
95 | }
96 |
97 | @Override public Settings getSettings() {
98 | return settings;
99 | }
100 |
101 | @Override public Printer t(String tag, int methodCount) {
102 | if (tag != null) {
103 | localTag.set(tag);
104 | }
105 | localMethodCount.set(methodCount);
106 | return this;
107 | }
108 |
109 | @Override public void d(String message, Object... args) {
110 | log(DEBUG, null, message, args);
111 | }
112 |
113 | @Override public void d(Object object) {
114 | String message;
115 | if (object.getClass().isArray()) {
116 | message = Arrays.deepToString((Object[]) object);
117 | } else {
118 | message = object.toString();
119 | }
120 | log(DEBUG, null, message);
121 | }
122 |
123 | @Override public void e(String message, Object... args) {
124 | e(null, message, args);
125 | }
126 |
127 | @Override public void e(Throwable throwable, String message, Object... args) {
128 | log(ERROR, throwable, message, args);
129 | }
130 |
131 | @Override public void w(String message, Object... args) {
132 | log(WARN, null, message, args);
133 | }
134 |
135 | @Override public void i(String message, Object... args) {
136 | log(INFO, null, message, args);
137 | }
138 |
139 | @Override public void v(String message, Object... args) {
140 | log(VERBOSE, null, message, args);
141 | }
142 |
143 | @Override public void wtf(String message, Object... args) {
144 | log(ASSERT, null, message, args);
145 | }
146 |
147 | /**
148 | * Formats the json content and print it
149 | *
150 | * @param json the json content
151 | */
152 | @Override public void json(String json) {
153 | if (Helper.isEmpty(json)) {
154 | d("Empty/Null json content");
155 | return;
156 | }
157 | try {
158 | json = json.trim();
159 | if (json.startsWith("{")) {
160 | JSONObject jsonObject = new JSONObject(json);
161 | String message = jsonObject.toString(JSON_INDENT);
162 | d(message);
163 | return;
164 | }
165 | if (json.startsWith("[")) {
166 | JSONArray jsonArray = new JSONArray(json);
167 | String message = jsonArray.toString(JSON_INDENT);
168 | d(message);
169 | return;
170 | }
171 | e("Invalid Json");
172 | } catch (JSONException e) {
173 | e("Invalid Json");
174 | }
175 | }
176 |
177 | /**
178 | * Formats the json content and print it
179 | *
180 | * @param xml the xml content
181 | */
182 | @Override public void xml(String xml) {
183 | if (Helper.isEmpty(xml)) {
184 | d("Empty/Null xml content");
185 | return;
186 | }
187 | try {
188 | Source xmlInput = new StreamSource(new StringReader(xml));
189 | StreamResult xmlOutput = new StreamResult(new StringWriter());
190 | Transformer transformer = TransformerFactory.newInstance().newTransformer();
191 | transformer.setOutputProperty(OutputKeys.INDENT, "yes");
192 | transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
193 | transformer.transform(xmlInput, xmlOutput);
194 | d(xmlOutput.getWriter().toString().replaceFirst(">", ">\n"));
195 | } catch (TransformerException e) {
196 | e("Invalid xml");
197 | }
198 | }
199 |
200 | @Override public synchronized void log(int priority, String tag, String message, Throwable throwable) {
201 | if (settings.getLogLevel() == LogLevel.NONE) {
202 | return;
203 | }
204 | if (throwable != null && message != null) {
205 | message += " : " + Helper.getStackTraceString(throwable);
206 | }
207 | if (throwable != null && message == null) {
208 | message = Helper.getStackTraceString(throwable);
209 | }
210 | if (message == null) {
211 | message = "No message/exception is set";
212 | }
213 | int methodCount = getMethodCount();
214 | if (Helper.isEmpty(message)) {
215 | message = "Empty/NULL log message";
216 | }
217 |
218 | logTopBorder(priority, tag);
219 | logHeaderContent(priority, tag, methodCount);
220 |
221 | //get bytes of message with system's default charset (which is UTF-8 for Android)
222 | byte[] bytes = message.getBytes();
223 | int length = bytes.length;
224 | if (length <= CHUNK_SIZE) {
225 | if (methodCount > 0) {
226 | logDivider(priority, tag);
227 | }
228 | logContent(priority, tag, message);
229 | logBottomBorder(priority, tag);
230 | return;
231 | }
232 | if (methodCount > 0) {
233 | logDivider(priority, tag);
234 | }
235 | for (int i = 0; i < length; i += CHUNK_SIZE) {
236 | int count = Math.min(length - i, CHUNK_SIZE);
237 | //create a new String with system's default charset (which is UTF-8 for Android)
238 | logContent(priority, tag, new String(bytes, i, count));
239 | }
240 | logBottomBorder(priority, tag);
241 | }
242 |
243 | @Override public void resetSettings() {
244 | settings.reset();
245 | }
246 |
247 | /**
248 | * This method is synchronized in order to avoid messy of logs' order.
249 | */
250 | private synchronized void log(int priority, Throwable throwable, String msg, Object... args) {
251 | if (settings.getLogLevel() == LogLevel.NONE) {
252 | return;
253 | }
254 | String tag = getTag();
255 | String message = createMessage(msg, args);
256 | log(priority, tag, message, throwable);
257 | }
258 |
259 | private void logTopBorder(int logType, String tag) {
260 | logChunk(logType, tag, TOP_BORDER);
261 | }
262 |
263 | @SuppressWarnings("StringBufferReplaceableByString")
264 | private void logHeaderContent(int logType, String tag, int methodCount) {
265 | StackTraceElement[] trace = Thread.currentThread().getStackTrace();
266 | if (settings.isShowThreadInfo()) {
267 | logChunk(logType, tag, HORIZONTAL_DOUBLE_LINE + " Thread: " + Thread.currentThread().getName());
268 | logDivider(logType, tag);
269 | }
270 | String level = "";
271 |
272 | int stackOffset = getStackOffset(trace) + settings.getMethodOffset();
273 |
274 | //corresponding method count with the current stack may exceeds the stack trace. Trims the count
275 | if (methodCount + stackOffset > trace.length) {
276 | methodCount = trace.length - stackOffset - 1;
277 | }
278 |
279 | for (int i = methodCount; i > 0; i--) {
280 | int stackIndex = i + stackOffset;
281 | if (stackIndex >= trace.length) {
282 | continue;
283 | }
284 | StringBuilder builder = new StringBuilder();
285 | builder.append("║ ")
286 | .append(level)
287 | .append(getSimpleClassName(trace[stackIndex].getClassName()))
288 | .append(".")
289 | .append(trace[stackIndex].getMethodName())
290 | .append(" ")
291 | .append(" (")
292 | .append(trace[stackIndex].getFileName())
293 | .append(":")
294 | .append(trace[stackIndex].getLineNumber())
295 | .append(")");
296 | level += " ";
297 | logChunk(logType, tag, builder.toString());
298 | }
299 | }
300 |
301 | private void logBottomBorder(int logType, String tag) {
302 | logChunk(logType, tag, BOTTOM_BORDER);
303 | }
304 |
305 | private void logDivider(int logType, String tag) {
306 | logChunk(logType, tag, MIDDLE_BORDER);
307 | }
308 |
309 | private void logContent(int logType, String tag, String chunk) {
310 | String[] lines = chunk.split(System.getProperty("line.separator"));
311 | for (String line : lines) {
312 | logChunk(logType, tag, HORIZONTAL_DOUBLE_LINE + " " + line);
313 | }
314 | }
315 |
316 | private void logChunk(int logType, String tag, String chunk) {
317 | String finalTag = formatTag(tag);
318 | switch (logType) {
319 | case ERROR:
320 | settings.getLogAdapter().e(finalTag, chunk);
321 | break;
322 | case INFO:
323 | settings.getLogAdapter().i(finalTag, chunk);
324 | break;
325 | case VERBOSE:
326 | settings.getLogAdapter().v(finalTag, chunk);
327 | break;
328 | case WARN:
329 | settings.getLogAdapter().w(finalTag, chunk);
330 | break;
331 | case ASSERT:
332 | settings.getLogAdapter().wtf(finalTag, chunk);
333 | break;
334 | case DEBUG:
335 | // Fall through, log debug by default
336 | default:
337 | settings.getLogAdapter().d(finalTag, chunk);
338 | break;
339 | }
340 | }
341 |
342 | private String getSimpleClassName(String name) {
343 | int lastIndex = name.lastIndexOf(".");
344 | return name.substring(lastIndex + 1);
345 | }
346 |
347 | private String formatTag(String tag) {
348 | if (!Helper.isEmpty(tag) && !Helper.equals(this.tag, tag)) {
349 | return this.tag + "-" + tag;
350 | }
351 | return this.tag;
352 | }
353 |
354 | /**
355 | * @return the appropriate tag based on local or global
356 | */
357 | private String getTag() {
358 | String tag = localTag.get();
359 | if (tag != null) {
360 | localTag.remove();
361 | return tag;
362 | }
363 | return this.tag;
364 | }
365 |
366 | private String createMessage(String message, Object... args) {
367 | return args == null || args.length == 0 ? message : String.format(message, args);
368 | }
369 |
370 | private int getMethodCount() {
371 | Integer count = localMethodCount.get();
372 | int result = settings.getMethodCount();
373 | if (count != null) {
374 | localMethodCount.remove();
375 | result = count;
376 | }
377 | if (result < 0) {
378 | throw new IllegalStateException("methodCount cannot be negative");
379 | }
380 | return result;
381 | }
382 |
383 | /**
384 | * Determines the starting index of the stack trace, after method calls made by this class.
385 | *
386 | * @param trace the stack trace
387 | *
388 | * @return the stack offset
389 | */
390 | private int getStackOffset(StackTraceElement[] trace) {
391 | for (int i = MIN_STACK_OFFSET; i < trace.length; i++) {
392 | StackTraceElement e = trace[i];
393 | String name = e.getClassName();
394 | if (!name.equals(LoggerPrinter.class.getName()) && !name.equals(Logger.class.getName())) {
395 | return --i;
396 | }
397 | }
398 | return -1;
399 | }
400 |
401 | }
402 |
--------------------------------------------------------------------------------
/logger/src/main/java/com/orhanobut/logger/Printer.java:
--------------------------------------------------------------------------------
1 | package com.orhanobut.logger;
2 |
3 | public interface Printer {
4 |
5 | Printer t(String tag, int methodCount);
6 |
7 | Settings init(String tag);
8 |
9 | Settings getSettings();
10 |
11 | void d(String message, Object... args);
12 |
13 | void d(Object object);
14 |
15 | void e(String message, Object... args);
16 |
17 | void e(Throwable throwable, String message, Object... args);
18 |
19 | void w(String message, Object... args);
20 |
21 | void i(String message, Object... args);
22 |
23 | void v(String message, Object... args);
24 |
25 | void wtf(String message, Object... args);
26 |
27 | void json(String json);
28 |
29 | void xml(String xml);
30 |
31 | void log(int priority, String tag, String message, Throwable throwable);
32 |
33 | void resetSettings();
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/logger/src/main/java/com/orhanobut/logger/Settings.java:
--------------------------------------------------------------------------------
1 | package com.orhanobut.logger;
2 |
3 | public final class Settings {
4 |
5 | private int methodCount = 2;
6 | private boolean showThreadInfo = true;
7 | private int methodOffset = 0;
8 | private LogAdapter logAdapter;
9 |
10 | /**
11 | * Determines to how logs will be printed
12 | */
13 | private LogLevel logLevel = LogLevel.FULL;
14 |
15 | public Settings hideThreadInfo() {
16 | showThreadInfo = false;
17 | return this;
18 | }
19 |
20 | public Settings methodCount(int methodCount) {
21 | if (methodCount < 0) {
22 | methodCount = 0;
23 | }
24 | this.methodCount = methodCount;
25 | return this;
26 | }
27 |
28 | public Settings logLevel(LogLevel logLevel) {
29 | this.logLevel = logLevel;
30 | return this;
31 | }
32 |
33 | public Settings methodOffset(int offset) {
34 | this.methodOffset = offset;
35 | return this;
36 | }
37 |
38 | public Settings logAdapter(LogAdapter logAdapter) {
39 | this.logAdapter = logAdapter;
40 | return this;
41 | }
42 |
43 | public int getMethodCount() {
44 | return methodCount;
45 | }
46 |
47 | public boolean isShowThreadInfo() {
48 | return showThreadInfo;
49 | }
50 |
51 | public LogLevel getLogLevel() {
52 | return logLevel;
53 | }
54 |
55 | public int getMethodOffset() {
56 | return methodOffset;
57 | }
58 |
59 | public LogAdapter getLogAdapter() {
60 | if (logAdapter == null) {
61 | logAdapter = new AndroidLogAdapter();
62 | }
63 | return logAdapter;
64 | }
65 |
66 | public void reset() {
67 | methodCount = 2;
68 | methodOffset = 0;
69 | showThreadInfo = true;
70 | logLevel = LogLevel.FULL;
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/logger/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Logger
3 |
4 |
--------------------------------------------------------------------------------
/loggerdemo2/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/loggerdemo2/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 25
5 | buildToolsVersion "25.0.1"
6 |
7 | defaultConfig {
8 | applicationId "com.orhanobut.loggerdemo2"
9 | minSdkVersion 9
10 | targetSdkVersion 25
11 | versionCode 1
12 | versionName "1.0"
13 |
14 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
15 |
16 | }
17 | buildTypes {
18 | release {
19 | minifyEnabled false
20 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
21 | }
22 | }
23 | }
24 |
25 | dependencies {
26 | compile fileTree(dir: 'libs', include: ['*.jar'])
27 | compile 'com.android.support:appcompat-v7:25.1.0'
28 | compile 'com.github.open-android:Logger:v1.0.0'
29 | }
30 |
--------------------------------------------------------------------------------
/loggerdemo2/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in D:\ProgramFiles\Android\sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/loggerdemo2/src/androidTest/java/com/orhanobut/loggerdemo2/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.orhanobut.loggerdemo2;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.orhanobut.loggerdemo2", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/loggerdemo2/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/loggerdemo2/src/main/java/com/orhanobut/loggerdemo2/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.orhanobut.loggerdemo2;
2 |
3 | import android.os.Bundle;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.view.View;
6 | import android.widget.Button;
7 |
8 | import com.orhanobut.logger.Logger;
9 |
10 | public class MainActivity extends AppCompatActivity implements View.OnClickListener {
11 |
12 | private Button mBtn1;
13 |
14 | @Override
15 | protected void onCreate(Bundle savedInstanceState) {
16 | super.onCreate(savedInstanceState);
17 | setContentView(R.layout.activity_main);
18 | initView();
19 | }
20 |
21 | private void initView() {
22 | mBtn1 = (Button) findViewById(R.id.btn1);
23 |
24 | mBtn1.setOnClickListener(this);
25 | }
26 |
27 | @Override
28 | public void onClick(View v) {
29 | switch (v.getId()) {
30 | case R.id.btn1:
31 | Logger.d("打印logger信息");
32 | break;
33 | }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/loggerdemo2/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
12 |
13 |
--------------------------------------------------------------------------------
/loggerdemo2/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/open-android/Logger/6b6d86ba9495a7e40210400736ef0df7cc14325e/loggerdemo2/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/loggerdemo2/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/open-android/Logger/6b6d86ba9495a7e40210400736ef0df7cc14325e/loggerdemo2/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/loggerdemo2/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/open-android/Logger/6b6d86ba9495a7e40210400736ef0df7cc14325e/loggerdemo2/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/loggerdemo2/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/open-android/Logger/6b6d86ba9495a7e40210400736ef0df7cc14325e/loggerdemo2/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/loggerdemo2/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/open-android/Logger/6b6d86ba9495a7e40210400736ef0df7cc14325e/loggerdemo2/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/loggerdemo2/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/loggerdemo2/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/loggerdemo2/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/loggerdemo2/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | LoggerDemo2
3 |
4 |
--------------------------------------------------------------------------------
/loggerdemo2/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/loggerdemo2/src/test/java/com/orhanobut/loggerdemo2/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.orhanobut.loggerdemo2;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/screenshot.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/open-android/Logger/6b6d86ba9495a7e40210400736ef0df7cc14325e/screenshot.png
--------------------------------------------------------------------------------
/screenshot2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/open-android/Logger/6b6d86ba9495a7e40210400736ef0df7cc14325e/screenshot2.png
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':logger', ':loggerdemo2'
2 |
--------------------------------------------------------------------------------