├── xlog ├── .gitignore ├── src │ ├── main │ │ ├── AndroidManifest.xml │ │ └── java │ │ │ └── com │ │ │ └── elvishew │ │ │ └── xlog │ │ │ ├── printer │ │ │ ├── file │ │ │ │ ├── clean │ │ │ │ │ ├── NeverCleanStrategy.java │ │ │ │ │ ├── CleanStrategy.java │ │ │ │ │ └── FileLastModifiedCleanStrategy.java │ │ │ │ ├── backup │ │ │ │ │ ├── NeverBackupStrategy.java │ │ │ │ │ ├── BackupStrategy.java │ │ │ │ │ ├── AbstractBackupStrategy.java │ │ │ │ │ ├── FileSizeBackupStrategy.java │ │ │ │ │ ├── FileSizeBackupStrategy2.java │ │ │ │ │ └── BackupStrategy2.java │ │ │ │ ├── naming │ │ │ │ │ ├── LevelFileNameGenerator.java │ │ │ │ │ ├── FileNameGenerator.java │ │ │ │ │ ├── ChangelessFileNameGenerator.java │ │ │ │ │ └── DateFileNameGenerator.java │ │ │ │ └── writer │ │ │ │ │ ├── Writer.java │ │ │ │ │ └── SimpleWriter.java │ │ │ ├── SystemPrinter.java │ │ │ ├── flattener │ │ │ │ ├── LogFlattener.java │ │ │ │ └── DefaultLogFlattener.java │ │ │ ├── RemotePrinter.java │ │ │ ├── PrinterSet.java │ │ │ ├── Printer.java │ │ │ ├── ConsolePrinter.java │ │ │ └── AndroidPrinter.java │ │ │ ├── internal │ │ │ ├── SystemCompat.java │ │ │ ├── printer │ │ │ │ └── file │ │ │ │ │ └── backup │ │ │ │ │ ├── BackupStrategyWrapper.java │ │ │ │ │ └── BackupUtil.java │ │ │ ├── Platform.java │ │ │ ├── util │ │ │ │ ├── StackTraceUtil.java │ │ │ │ └── ObjectToStringUtil.java │ │ │ └── DefaultsFactory.java │ │ │ ├── formatter │ │ │ ├── thread │ │ │ │ ├── ThreadFormatter.java │ │ │ │ └── DefaultThreadFormatter.java │ │ │ ├── message │ │ │ │ ├── xml │ │ │ │ │ ├── XmlFormatter.java │ │ │ │ │ └── DefaultXmlFormatter.java │ │ │ │ ├── json │ │ │ │ │ ├── JsonFormatter.java │ │ │ │ │ └── DefaultJsonFormatter.java │ │ │ │ ├── throwable │ │ │ │ │ ├── ThrowableFormatter.java │ │ │ │ │ └── DefaultThrowableFormatter.java │ │ │ │ └── object │ │ │ │ │ ├── ObjectFormatter.java │ │ │ │ │ ├── BundleFormatter.java │ │ │ │ │ └── IntentFormatter.java │ │ │ ├── stacktrace │ │ │ │ ├── StackTraceFormatter.java │ │ │ │ └── DefaultStackTraceFormatter.java │ │ │ ├── Formatter.java │ │ │ ├── border │ │ │ │ ├── BorderFormatter.java │ │ │ │ └── DefaultBorderFormatter.java │ │ │ └── FormatException.java │ │ │ ├── flattener │ │ │ ├── Flattener.java │ │ │ ├── Flattener2.java │ │ │ ├── ClassicFlattener.java │ │ │ └── DefaultFlattener.java │ │ │ ├── interceptor │ │ │ ├── AbstractFilterInterceptor.java │ │ │ ├── Interceptor.java │ │ │ ├── BlacklistTagsFilterInterceptor.java │ │ │ └── WhitelistTagsFilterInterceptor.java │ │ │ ├── LogItem.java │ │ │ ├── LogLevel.java │ │ │ └── LogUtils.java │ └── test │ │ └── java │ │ └── com │ │ └── elvishew │ │ └── xlog │ │ ├── XLogUtil.java │ │ ├── RandomUtil.java │ │ ├── ContainerPrinter.java │ │ ├── interceptor │ │ ├── BlacklistTagsFilterInterceptorTest.java │ │ └── WhitelistTagsFilterInterceptorTest.java │ │ ├── AssertUtil.java │ │ ├── printer │ │ └── AndroidPrinterTest.java │ │ ├── flattener │ │ └── PatternFlattenerTest.java │ │ └── ConcurrentTest.java ├── gradle.properties ├── build.gradle └── proguard-rules.pro ├── xlog-sample ├── .gitignore ├── src │ └── main │ │ ├── res │ │ ├── mipmap-xxxhdpi │ │ │ └── ic_launcher.png │ │ ├── drawable-xxxhdpi │ │ │ └── ic_print_white_24dp.png │ │ ├── values │ │ │ ├── colors.xml │ │ │ ├── arrays.xml │ │ │ ├── styles.xml │ │ │ └── strings.xml │ │ └── layout │ │ │ ├── dialog_change_tag.xml │ │ │ ├── item_log.xml │ │ │ └── activity_main.xml │ │ ├── AndroidManifest.xml │ │ └── java │ │ └── com │ │ └── elvishew │ │ └── xlogsample │ │ ├── RecyclerViewPrinter.java │ │ └── XLogSampleApplication.java ├── proguard-rules.pro └── build.gradle ├── settings.gradle ├── images ├── qq_group.jpg ├── architecture.png └── logcat-output.png ├── .gitignore ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── xlog-libcat ├── gradle.properties ├── src │ └── main │ │ ├── AndroidManifest.xml │ │ └── java │ │ └── com │ │ └── elvishew │ │ └── xlog │ │ └── libcat │ │ ├── LibCat.java │ │ └── internal │ │ ├── Cat.java │ │ └── LogAspect.java ├── build.gradle ├── README_ZH.md └── README.md ├── .travis.yml ├── .buildscript └── deploy.sh ├── gradle.properties ├── gradlew.bat ├── maven-push.gradle └── gradlew /xlog/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /xlog-sample/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':xlog', ':xlog-libcat', ':xlog-sample' 2 | -------------------------------------------------------------------------------- /xlog/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /images/qq_group.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elvishew/xLog/HEAD/images/qq_group.jpg -------------------------------------------------------------------------------- /images/architecture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elvishew/xLog/HEAD/images/architecture.png -------------------------------------------------------------------------------- /images/logcat-output.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elvishew/xLog/HEAD/images/logcat-output.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | .idea 5 | .DS_Store 6 | build 7 | /captures 8 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elvishew/xLog/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /xlog-sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elvishew/xLog/HEAD/xlog-sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /xlog-sample/src/main/res/drawable-xxxhdpi/ic_print_white_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elvishew/xLog/HEAD/xlog-sample/src/main/res/drawable-xxxhdpi/ic_print_white_24dp.png -------------------------------------------------------------------------------- /xlog-libcat/gradle.properties: -------------------------------------------------------------------------------- 1 | POM_NAME=XLog: LibCat 2 | POM_ARTIFACT_ID=xlog-libcat 3 | POM_PACKAGING=jar 4 | POM_DESCRIPTION=Intercept the origin log and pass it to specific printer 5 | 6 | VERSION_NAME=1.0.0 7 | VERSION_CODE=3 8 | -------------------------------------------------------------------------------- /xlog/gradle.properties: -------------------------------------------------------------------------------- 1 | POM_NAME=XLog 2 | POM_ARTIFACT_ID=xlog 3 | POM_PACKAGING=jar 4 | POM_DESCRIPTION=Android logger, pretty, powerful and flexible, logging to file and everywhere 5 | 6 | VERSION_NAME=1.11.1 7 | VERSION_CODE=20 8 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Tue Jul 28 14:59:22 CST 2020 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-6.5-all.zip 7 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: android 2 | android: 3 | components: 4 | - tools 5 | - platform-tools 6 | - build-tools-29.0.3 7 | - android-29 8 | - extra-android-m2repository 9 | 10 | jdk: 11 | - oraclejdk8 12 | 13 | after_success: 14 | - .buildscript/deploy.sh 15 | 16 | sudo: false 17 | 18 | cache: 19 | directories: 20 | - $HOME/.gradle -------------------------------------------------------------------------------- /xlog/src/main/java/com/elvishew/xlog/printer/file/clean/NeverCleanStrategy.java: -------------------------------------------------------------------------------- 1 | package com.elvishew.xlog.printer.file.clean; 2 | 3 | import java.io.File; 4 | 5 | /** 6 | * Never Limit the file life. 7 | * 8 | * @since 1.5.0 9 | */ 10 | public class NeverCleanStrategy implements CleanStrategy { 11 | 12 | @Override 13 | public boolean shouldClean(File file) { 14 | return false; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /xlog/src/main/java/com/elvishew/xlog/printer/file/clean/CleanStrategy.java: -------------------------------------------------------------------------------- 1 | package com.elvishew.xlog.printer.file.clean; 2 | 3 | import java.io.File; 4 | 5 | /** 6 | * Decide whether the log file should be clean. 7 | * 8 | * @since 1.5.0 9 | */ 10 | public interface CleanStrategy { 11 | 12 | /** 13 | * Whether we should clean a specified log file. 14 | * 15 | * @param file the log file 16 | * @return true is we should clean the log file 17 | */ 18 | boolean shouldClean(File file); 19 | } 20 | -------------------------------------------------------------------------------- /xlog/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | apply from: '../maven-push.gradle' 3 | 4 | android { 5 | compileSdkVersion 29 6 | buildToolsVersion "29.0.3" 7 | 8 | defaultConfig { 9 | minSdkVersion 14 10 | targetSdkVersion 29 11 | } 12 | buildTypes { 13 | release { 14 | minifyEnabled false 15 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 16 | } 17 | } 18 | } 19 | 20 | dependencies { 21 | implementation fileTree(dir: 'libs', include: ['*.jar']) 22 | testImplementation 'junit:junit:4.12' 23 | } 24 | -------------------------------------------------------------------------------- /xlog/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 /Users/elvishew/Library/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 | -------------------------------------------------------------------------------- /xlog-libcat/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | -------------------------------------------------------------------------------- /xlog-sample/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 /Users/elvishew/Library/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 | -------------------------------------------------------------------------------- /xlog/src/test/java/com/elvishew/xlog/XLogUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Elvis Hew 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 | 17 | package com.elvishew.xlog; 18 | 19 | public class XLogUtil { 20 | 21 | public static void beforeTest() { 22 | XLog.sIsInitialized = false; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /xlog/src/main/java/com/elvishew/xlog/printer/file/clean/FileLastModifiedCleanStrategy.java: -------------------------------------------------------------------------------- 1 | package com.elvishew.xlog.printer.file.clean; 2 | 3 | import java.io.File; 4 | 5 | /** 6 | * Limit the file life of a max time. 7 | * 8 | * @since 1.5.0 9 | */ 10 | public class FileLastModifiedCleanStrategy implements CleanStrategy { 11 | 12 | private long maxTimeMillis; 13 | 14 | /** 15 | * Constructor. 16 | * 17 | * @param maxTimeMillis the max time the file can keep 18 | */ 19 | public FileLastModifiedCleanStrategy(long maxTimeMillis) { 20 | this.maxTimeMillis = maxTimeMillis; 21 | } 22 | 23 | @Override 24 | public boolean shouldClean(File file) { 25 | long currentTimeMillis = System.currentTimeMillis(); 26 | long lastModified = file.lastModified(); 27 | return (currentTimeMillis - lastModified > maxTimeMillis); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /xlog/src/main/java/com/elvishew/xlog/printer/SystemPrinter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Elvis Hew 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 | 17 | package com.elvishew.xlog.printer; 18 | 19 | /** 20 | * @deprecated use {@link ConsolePrinter} instead, since 1.3.0 21 | */ 22 | @Deprecated 23 | public class SystemPrinter extends ConsolePrinter { 24 | } 25 | -------------------------------------------------------------------------------- /xlog-sample/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | #3F51B5 19 | #303F9F 20 | #FF4081 21 | 22 | -------------------------------------------------------------------------------- /.buildscript/deploy.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Deploy to Sonatype's repo. 4 | # 5 | # Adapted from https://github.com/JakeWharton/butterknife/blob/master/.buildscript/deploy_snapshot.sh 6 | 7 | SLUG="elvishew/xLog" 8 | JDK="oraclejdk8" 9 | BRANCH="master" 10 | 11 | set -e 12 | 13 | if [ "$TRAVIS_REPO_SLUG" != "$SLUG" ]; then 14 | echo "Skipping snapshot deployment: wrong repository. Expected '$SLUG' but was '$TRAVIS_REPO_SLUG'." 15 | elif [ "$TRAVIS_JDK_VERSION" != "$JDK" ]; then 16 | echo "Skipping snapshot deployment: wrong JDK. Expected '$JDK' but was '$TRAVIS_JDK_VERSION'." 17 | elif [ "$TRAVIS_PULL_REQUEST" != "false" ]; then 18 | echo "Skipping snapshot deployment: was pull request." 19 | elif [ "$TRAVIS_BRANCH" != "$BRANCH" ]; then 20 | echo "Skipping snapshot deployment: wrong branch. Expected '$BRANCH' but was '$TRAVIS_BRANCH'." 21 | else 22 | echo "Deploying..." 23 | ./gradlew uploadArchives 24 | echo "Deployed!" 25 | fi 26 | -------------------------------------------------------------------------------- /xlog/src/main/java/com/elvishew/xlog/internal/SystemCompat.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Elvis Hew 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 | 17 | package com.elvishew.xlog.internal; 18 | 19 | /** 20 | * System environment. 21 | */ 22 | public class SystemCompat { 23 | 24 | /** 25 | * The line separator of system. 26 | */ 27 | public static String lineSeparator = Platform.get().lineSeparator(); 28 | } 29 | -------------------------------------------------------------------------------- /xlog/src/main/java/com/elvishew/xlog/printer/flattener/LogFlattener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Elvis Hew 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 | 17 | package com.elvishew.xlog.printer.flattener; 18 | 19 | import com.elvishew.xlog.flattener.Flattener; 20 | 21 | /** 22 | * @deprecated use {@link Flattener} instead, since 1.3.0 23 | */ 24 | @Deprecated 25 | public interface LogFlattener extends Flattener { 26 | } 27 | -------------------------------------------------------------------------------- /xlog/src/main/java/com/elvishew/xlog/formatter/thread/ThreadFormatter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Elvis Hew 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 | 17 | package com.elvishew.xlog.formatter.thread; 18 | 19 | import com.elvishew.xlog.formatter.Formatter; 20 | 21 | /** 22 | * The thread formatter used to format the thread info when logging. 23 | */ 24 | public interface ThreadFormatter extends Formatter { 25 | } 26 | -------------------------------------------------------------------------------- /xlog/src/main/java/com/elvishew/xlog/formatter/message/xml/XmlFormatter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Elvis Hew 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 | 17 | package com.elvishew.xlog.formatter.message.xml; 18 | 19 | import com.elvishew.xlog.formatter.Formatter; 20 | 21 | /** 22 | * The XML formatter used to format the XML string when log a XML string. 23 | */ 24 | public interface XmlFormatter extends Formatter { 25 | } 26 | -------------------------------------------------------------------------------- /xlog/src/main/java/com/elvishew/xlog/formatter/message/json/JsonFormatter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Elvis Hew 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 | 17 | package com.elvishew.xlog.formatter.message.json; 18 | 19 | import com.elvishew.xlog.formatter.Formatter; 20 | 21 | /** 22 | * The JSON formatter used to format the JSON string when log a JSON string. 23 | */ 24 | public interface JsonFormatter extends Formatter { 25 | } 26 | -------------------------------------------------------------------------------- /xlog/src/main/java/com/elvishew/xlog/printer/flattener/DefaultLogFlattener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Elvis Hew 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 | 17 | package com.elvishew.xlog.printer.flattener; 18 | 19 | import com.elvishew.xlog.flattener.DefaultFlattener; 20 | 21 | /** 22 | * @deprecated use {@link DefaultFlattener} instead, since 1.3.0 23 | */ 24 | @Deprecated 25 | public class DefaultLogFlattener extends DefaultFlattener { 26 | } 27 | -------------------------------------------------------------------------------- /xlog/src/main/java/com/elvishew/xlog/formatter/stacktrace/StackTraceFormatter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Elvis Hew 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 | 17 | package com.elvishew.xlog.formatter.stacktrace; 18 | 19 | import com.elvishew.xlog.formatter.Formatter; 20 | 21 | /** 22 | * The stack trace formatter used to format the stack trace when logging. 23 | */ 24 | public interface StackTraceFormatter extends Formatter { 25 | } 26 | -------------------------------------------------------------------------------- /xlog/src/test/java/com/elvishew/xlog/RandomUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Elvis Hew 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 | 17 | package com.elvishew.xlog; 18 | 19 | import java.util.Random; 20 | 21 | public class RandomUtil { 22 | 23 | private static Random sAsciiCharRandom = new Random(); 24 | 25 | public static char randomAsciiChar() { 26 | return (char) (sAsciiCharRandom.nextInt(100) + 28/* Just don't random to a line separator*/); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /xlog/src/main/java/com/elvishew/xlog/formatter/message/throwable/ThrowableFormatter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Elvis Hew 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 | 17 | package com.elvishew.xlog.formatter.message.throwable; 18 | 19 | import com.elvishew.xlog.formatter.Formatter; 20 | 21 | /** 22 | * The throwable formatter used to format the throwable when log a message with throwable. 23 | */ 24 | public interface ThrowableFormatter extends Formatter { 25 | } 26 | -------------------------------------------------------------------------------- /xlog/src/main/java/com/elvishew/xlog/formatter/message/object/ObjectFormatter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Elvis Hew 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 | 17 | package com.elvishew.xlog.formatter.message.object; 18 | 19 | import com.elvishew.xlog.formatter.Formatter; 20 | 21 | /** 22 | * The Object formatter used to format an object to a string. 23 | * 24 | * @param the type of object 25 | * @since 1.1.0 26 | */ 27 | public interface ObjectFormatter extends Formatter { 28 | } 29 | -------------------------------------------------------------------------------- /xlog/src/main/java/com/elvishew/xlog/formatter/thread/DefaultThreadFormatter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Elvis Hew 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 | 17 | package com.elvishew.xlog.formatter.thread; 18 | 19 | /** 20 | * Formatted stack trace looks like: 21 | *
Thread: thread-name 22 | */ 23 | public class DefaultThreadFormatter implements ThreadFormatter { 24 | 25 | @Override 26 | public String format(Thread data) { 27 | return "Thread: " + data.getName(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /xlog/src/main/java/com/elvishew/xlog/printer/file/backup/NeverBackupStrategy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Elvis Hew 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 | 17 | package com.elvishew.xlog.printer.file.backup; 18 | 19 | import java.io.File; 20 | 21 | /** 22 | * Never backup the log file. 23 | * 24 | * @since 1.3.0 25 | */ 26 | public class NeverBackupStrategy implements BackupStrategy { 27 | 28 | @Override 29 | public boolean shouldBackup(File file) { 30 | return false; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /xlog-sample/src/main/res/layout/dialog_change_tag.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 21 | 22 | 27 | -------------------------------------------------------------------------------- /xlog/src/main/java/com/elvishew/xlog/printer/file/backup/BackupStrategy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Elvis Hew 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 | 17 | package com.elvishew.xlog.printer.file.backup; 18 | 19 | import java.io.File; 20 | 21 | /** 22 | * Decide whether the log file should be backup and use a new file for next logging. 23 | */ 24 | public interface BackupStrategy { 25 | 26 | /** 27 | * Whether we should backup a specified log file. 28 | * 29 | * @param file the log file 30 | * @return true is we should backup the log file 31 | */ 32 | boolean shouldBackup(File file); 33 | } 34 | -------------------------------------------------------------------------------- /xlog/src/main/java/com/elvishew/xlog/formatter/message/throwable/DefaultThrowableFormatter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Elvis Hew 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 | 17 | package com.elvishew.xlog.formatter.message.throwable; 18 | 19 | import com.elvishew.xlog.internal.util.StackTraceUtil; 20 | 21 | /** 22 | * Simply put each stack trace(method name, source file and line number) of the throwable 23 | * in a single line. 24 | */ 25 | public class DefaultThrowableFormatter implements ThrowableFormatter { 26 | 27 | @Override 28 | public String format(Throwable tr) { 29 | return StackTraceUtil.getStackTraceString(tr); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /xlog-sample/src/main/res/layout/item_log.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 20 | 21 | 25 | 26 | 30 | -------------------------------------------------------------------------------- /xlog/src/main/java/com/elvishew/xlog/printer/RemotePrinter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Elvis Hew 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 | 17 | package com.elvishew.xlog.printer; 18 | 19 | /** 20 | * Log {@link Printer} which should print the log to remote server. 21 | *

22 | * This is just a empty implementation telling you that you can do 23 | * such thing, you can override {@link #println(int, String, String)} )} and sending the log by your 24 | * implementation. 25 | */ 26 | public class RemotePrinter implements Printer { 27 | 28 | @Override 29 | public void println(int logLevel, String tag, String msg) { 30 | // TODO: Send the log to your server. 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /xlog-sample/src/main/res/values/arrays.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 19 | VERBOSE 20 | DEBUG 21 | INFO 22 | WARN 23 | ERROR 24 | 25 | 26 | 27 | No Limitation 28 | 1 29 | 2 30 | 3 31 | 4 32 | 5 33 | 34 | -------------------------------------------------------------------------------- /xlog/src/main/java/com/elvishew/xlog/formatter/Formatter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Elvis Hew 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 | 17 | package com.elvishew.xlog.formatter; 18 | 19 | /** 20 | * A formatter is used for format the data that is not a string, or that is a string but not well 21 | * formatted, we should format the data to a well formatted string so printers can print them. 22 | * 23 | * @param the type of the data 24 | */ 25 | public interface Formatter { 26 | 27 | /** 28 | * Format the data to a readable and loggable string. 29 | * 30 | * @param data the data to format 31 | * @return the formatted string data 32 | */ 33 | String format(T data); 34 | } 35 | -------------------------------------------------------------------------------- /xlog/src/main/java/com/elvishew/xlog/printer/file/backup/AbstractBackupStrategy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 Elvis Hew 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 | 17 | package com.elvishew.xlog.printer.file.backup; 18 | 19 | /** 20 | * An abstract {@link BackupStrategy2}, simply append '.bak.n' to the end of normal file name when 21 | * naming a backup with index n. 22 | *

23 | * Developers can simply extend this class when defining their own {@link BackupStrategy2}. 24 | * 25 | * @since 1.9.0 26 | */ 27 | public abstract class AbstractBackupStrategy implements BackupStrategy2 { 28 | 29 | @Override 30 | public String getBackupFileName(String fileName, int backupIndex) { 31 | return fileName + ".bak." + backupIndex; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /xlog/src/main/java/com/elvishew/xlog/flattener/Flattener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Elvis Hew 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 | 17 | package com.elvishew.xlog.flattener; 18 | 19 | /** 20 | * The flattener used to flatten log elements(log level, tag and message) to a single CharSequence. 21 | * 22 | * @since 1.3.0 23 | * @deprecated use {@link Flattener2} instead, since 1.6.0 24 | */ 25 | @Deprecated 26 | public interface Flattener { 27 | 28 | /** 29 | * Flatten the log. 30 | * 31 | * @param logLevel the level of log 32 | * @param tag the tag of log 33 | * @param message the message of log 34 | * @return the formatted final log Charsequence 35 | */ 36 | CharSequence flatten(int logLevel, String tag, String message); 37 | } 38 | -------------------------------------------------------------------------------- /xlog/src/main/java/com/elvishew/xlog/formatter/message/object/BundleFormatter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Elvis Hew 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 | 17 | package com.elvishew.xlog.formatter.message.object; 18 | 19 | import android.os.Bundle; 20 | 21 | import com.elvishew.xlog.internal.util.ObjectToStringUtil; 22 | 23 | /** 24 | * Format an Bundle object to a string. 25 | * 26 | * @since 1.4.0 27 | */ 28 | public class BundleFormatter implements ObjectFormatter { 29 | 30 | /** 31 | * Format an Bundle object to a string. 32 | * 33 | * @param data the Bundle object to format 34 | * @return the formatted string 35 | */ 36 | @Override 37 | public String format(Bundle data) { 38 | return ObjectToStringUtil.bundleToString(data); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /xlog/src/main/java/com/elvishew/xlog/flattener/Flattener2.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Elvis Hew 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 | 17 | package com.elvishew.xlog.flattener; 18 | 19 | /** 20 | * The flattener used to flatten log elements(log time milliseconds, level, tag and message) to 21 | * a single CharSequence. 22 | * 23 | * @since 1.6.0 24 | */ 25 | public interface Flattener2 { 26 | 27 | /** 28 | * Flatten the log. 29 | * 30 | * @param timeMillis the time milliseconds of log 31 | * @param logLevel the level of log 32 | * @param tag the tag of log 33 | * @param message the message of log 34 | * @return the formatted final log Charsequence 35 | */ 36 | CharSequence flatten(long timeMillis, int logLevel, String tag, String message); 37 | } 38 | -------------------------------------------------------------------------------- /xlog/src/main/java/com/elvishew/xlog/formatter/message/object/IntentFormatter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Elvis Hew 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 | 17 | package com.elvishew.xlog.formatter.message.object; 18 | 19 | import android.content.Intent; 20 | 21 | import com.elvishew.xlog.internal.util.ObjectToStringUtil; 22 | 23 | /** 24 | * Format an Intent object to a string. 25 | * 26 | * @since 1.4.0 27 | */ 28 | public class IntentFormatter implements ObjectFormatter { 29 | 30 | /** 31 | * Format an Intent object to a string. 32 | * 33 | * @param data the Intent object to format 34 | * @return the formatted string 35 | */ 36 | @Override 37 | public String format(Intent data) { 38 | return ObjectToStringUtil.intentToString(data); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /xlog/src/main/java/com/elvishew/xlog/printer/file/naming/LevelFileNameGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Elvis Hew 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 | 17 | package com.elvishew.xlog.printer.file.naming; 18 | 19 | import com.elvishew.xlog.LogLevel; 20 | 21 | /** 22 | * Generate file name according to the log level, different levels lead to different file names. 23 | */ 24 | public class LevelFileNameGenerator implements FileNameGenerator { 25 | 26 | @Override 27 | public boolean isFileNameChangeable() { 28 | return true; 29 | } 30 | 31 | /** 32 | * Generate a file name which represent a specific log level. 33 | */ 34 | @Override 35 | public String generateFileName(int logLevel, long timestamp) { 36 | return LogLevel.getLevelName(logLevel); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /xlog/src/main/java/com/elvishew/xlog/flattener/ClassicFlattener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Elvis Hew 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 | 17 | package com.elvishew.xlog.flattener; 18 | 19 | import com.elvishew.xlog.LogLevel; 20 | 21 | /** 22 | * The classic flattener, flatten the log with pattern "{@value #DEFAULT_PATTERN}". 23 | *

24 | * Imagine there is a log, with {@link LogLevel#DEBUG} level, "my_tag" tag and "Simple message" 25 | * message, the flattened log would be: "2016-11-30 13:00:00.000 D/my_tag: Simple message" 26 | * 27 | * @since 1.3.0 28 | */ 29 | public class ClassicFlattener extends PatternFlattener { 30 | 31 | private static final String DEFAULT_PATTERN = "{d} {l}/{t}: {m}"; 32 | 33 | public ClassicFlattener() { 34 | super(DEFAULT_PATTERN); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /xlog/src/main/java/com/elvishew/xlog/printer/file/naming/FileNameGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Elvis Hew 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 | 17 | package com.elvishew.xlog.printer.file.naming; 18 | 19 | /** 20 | * Generates names for log files. 21 | */ 22 | public interface FileNameGenerator { 23 | 24 | /** 25 | * Whether the generated file name will change or not. 26 | * 27 | * @return true if the file name is changeable 28 | */ 29 | boolean isFileNameChangeable(); 30 | 31 | /** 32 | * Generate file name for specified log level and timestamp. 33 | * 34 | * @param logLevel the level of the log 35 | * @param timestamp the timestamp when the logging happen 36 | * @return the generated file name 37 | */ 38 | String generateFileName(int logLevel, long timestamp); 39 | } 40 | -------------------------------------------------------------------------------- /xlog-libcat/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 Elvis Hew 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 | 17 | apply plugin: 'com.android.library' 18 | apply from: '../maven-push.gradle' 19 | 20 | android { 21 | compileSdkVersion 29 22 | buildToolsVersion "29.0.3" 23 | 24 | compileOptions { 25 | sourceCompatibility JavaVersion.VERSION_1_8 26 | targetCompatibility JavaVersion.VERSION_1_8 27 | } 28 | 29 | defaultConfig { 30 | minSdkVersion 14 31 | targetSdkVersion 29 32 | } 33 | 34 | buildTypes { 35 | release { 36 | minifyEnabled false 37 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt') 38 | } 39 | } 40 | } 41 | 42 | dependencies { 43 | api 'com.elvishew:xlog:1.11.1' 44 | api 'org.aspectj:aspectjrt:1.9.5' 45 | } -------------------------------------------------------------------------------- /xlog/src/main/java/com/elvishew/xlog/printer/file/naming/ChangelessFileNameGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Elvis Hew 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 | 17 | package com.elvishew.xlog.printer.file.naming; 18 | 19 | /** 20 | * Generate a file name that is changeless. 21 | */ 22 | public class ChangelessFileNameGenerator implements FileNameGenerator { 23 | 24 | private final String fileName; 25 | 26 | /** 27 | * Constructor. 28 | * 29 | * @param fileName the changeless file name 30 | */ 31 | public ChangelessFileNameGenerator(String fileName) { 32 | this.fileName = fileName; 33 | } 34 | 35 | @Override 36 | public boolean isFileNameChangeable() { 37 | return false; 38 | } 39 | 40 | @Override 41 | public String generateFileName(int logLevel, long timestamp) { 42 | return fileName; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /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 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true 19 | GROUP=com.elvishew 20 | 21 | POM_URL=https://github.com/elvishew/XLog 22 | POM_SCM_URL=https://github.com/elvishew/XLog 23 | POM_SCM_CONNECTION=scm:git@github.com:elvishew/XLog.git 24 | POM_SCM_DEV_CONNECTION=scm:git@github.com:elvishew/XLog.git 25 | POM_LICENCE_NAME=The Apache Software License, Version 2.0 26 | POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt 27 | POM_LICENCE_DIST=repo 28 | POM_DEVELOPER_ID=elvishew 29 | POM_DEVELOPER_NAME=Elvis Hew 30 | 31 | android.useAndroidX=true 32 | android.enableJetifier=true -------------------------------------------------------------------------------- /xlog/src/main/java/com/elvishew/xlog/flattener/DefaultFlattener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Elvis Hew 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 | 17 | package com.elvishew.xlog.flattener; 18 | 19 | import com.elvishew.xlog.LogLevel; 20 | 21 | /** 22 | * Simply join the timestamp, log level, tag and message together. 23 | * 24 | * @since 1.3.0 25 | */ 26 | public class DefaultFlattener implements Flattener, Flattener2 { 27 | 28 | @Override 29 | public CharSequence flatten(int logLevel, String tag, String message) { 30 | return flatten(System.currentTimeMillis(), logLevel, tag, message); 31 | } 32 | 33 | @Override 34 | public CharSequence flatten(long timeMillis, int logLevel, String tag, String message) { 35 | return Long.toString(timeMillis) 36 | + '|' + LogLevel.getShortLevelName(logLevel) 37 | + '|' + tag 38 | + '|' + message; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /xlog/src/test/java/com/elvishew/xlog/ContainerPrinter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Elvis Hew 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 | 17 | package com.elvishew.xlog; 18 | 19 | import com.elvishew.xlog.printer.Printer; 20 | 21 | import java.util.ArrayList; 22 | import java.util.List; 23 | 24 | public class ContainerPrinter implements Printer { 25 | 26 | private List logsContainers = new ArrayList<>(); 27 | 28 | public ContainerPrinter(List logsContainer) { 29 | this.logsContainers = logsContainer; 30 | } 31 | 32 | @Override 33 | public void println(int logLevel, String tag, String msg) { 34 | LogItem log = onPrint(new LogItem(logLevel, tag, msg)); 35 | afterPrint(log); 36 | } 37 | 38 | protected LogItem onPrint(LogItem logItem) { 39 | return logItem; 40 | } 41 | 42 | private void afterPrint(LogItem log) { 43 | logsContainers.add(log); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /xlog/src/main/java/com/elvishew/xlog/printer/PrinterSet.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Elvis Hew 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 | 17 | package com.elvishew.xlog.printer; 18 | 19 | /** 20 | * Represents a group of Printers that should used to print logs in the same time, each printer 21 | * may probably print the log to different place. 22 | */ 23 | public class PrinterSet implements Printer { 24 | 25 | private Printer[] printers; 26 | 27 | /** 28 | * Constructor, pass printers in and will use all these printers to print the same logs. 29 | * 30 | * @param printers the printers used to print the same logs 31 | */ 32 | public PrinterSet(Printer... printers) { 33 | this.printers = printers; 34 | } 35 | 36 | @Override 37 | public void println(int logLevel, String tag, String msg) { 38 | for (Printer printer : printers) { 39 | printer.println(logLevel, tag, msg); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /xlog/src/main/java/com/elvishew/xlog/printer/file/backup/FileSizeBackupStrategy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Elvis Hew 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 | 17 | package com.elvishew.xlog.printer.file.backup; 18 | 19 | import java.io.File; 20 | 21 | /** 22 | * Limit the file size of a max length. 23 | * 24 | * @deprecated use {@link FileSizeBackupStrategy2} instead, since 1.9.0. 25 | * A {@link FileSizeBackupStrategy2} allows you to define the max number of backup files 26 | */ 27 | @Deprecated 28 | public class FileSizeBackupStrategy implements BackupStrategy { 29 | 30 | private long maxSize; 31 | 32 | /** 33 | * Constructor. 34 | * 35 | * @param maxSize the max size the file can reach 36 | */ 37 | public FileSizeBackupStrategy(long maxSize) { 38 | this.maxSize = maxSize; 39 | } 40 | 41 | @Override 42 | public boolean shouldBackup(File file) { 43 | return file.length() > maxSize; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /xlog-sample/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | apply plugin: 'android-aspectjx' 3 | 4 | android { 5 | compileSdkVersion 29 6 | buildToolsVersion "29.0.3" 7 | 8 | compileOptions { 9 | sourceCompatibility JavaVersion.VERSION_1_8 10 | targetCompatibility JavaVersion.VERSION_1_8 11 | } 12 | 13 | defaultConfig { 14 | applicationId "com.elvishew.xlogsample" 15 | minSdkVersion 14 16 | targetSdkVersion 29 17 | versionCode 1 18 | versionName "1.0" 19 | } 20 | buildTypes { 21 | release { 22 | minifyEnabled false 23 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 24 | } 25 | } 26 | } 27 | 28 | buildscript { 29 | repositories { 30 | jcenter() 31 | google() 32 | } 33 | dependencies { 34 | classpath 'com.hujiang.aspectjx:gradle-android-plugin-aspectjx:2.0.10' 35 | } 36 | } 37 | 38 | aspectjx { 39 | exclude 'androidx.appcompat' 40 | exclude 'android.support' 41 | } 42 | 43 | dependencies { 44 | implementation 'com.elvishew:xlog:1.11.1' 45 | implementation 'com.elvishew:xlog-libcat:1.0.0' 46 | implementation fileTree(dir: 'libs', include: ['*.jar']) 47 | implementation 'com.google.android.material:material:1.3.0-alpha02' 48 | implementation 'androidx.appcompat:appcompat:1.3.0-alpha02' 49 | implementation 'androidx.legacy:legacy-support-v4:1.0.0' 50 | testImplementation 'junit:junit:4.12' 51 | } 52 | -------------------------------------------------------------------------------- /xlog-sample/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 19 | 20 | 26 | 27 | 31 | 32 |