diff --git a/.idea/codeStyleSettings.xml b/.idea/codeStyleSettings.xml new file mode 100644 index 00000000..a0ccdcbf --- /dev/null +++ b/.idea/codeStyleSettings.xml @@ -0,0 +1,229 @@ + + + + + + \ No newline at end of file diff --git a/README.md b/README.md index 258e44f9..9dce5753 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ Simple, pretty and powerful logger for android ### Setup Download ```groovy -compile 'com.orhanobut:logger:2.1.1' +implementation 'com.orhanobut:logger:2.2.0' ``` Initialize @@ -32,7 +32,7 @@ Logger.e("error"); Logger.w("warning"); Logger.v("verbose"); Logger.i("information"); -Logger.wtf("wtf!!!!"); +Logger.wtf("What a Terrible Failure"); ``` String format arguments are supported @@ -40,7 +40,7 @@ String format arguments are supported Logger.d("hello %s", "world"); ``` -Collections support (only available for debug logs) +Collections are supported (only available for debug logs) ```java Logger.d(MAP); Logger.d(SET); @@ -68,8 +68,9 @@ Logger.addLogAdapter(new AndroidLogAdapter(formatStrategy)); ``` ### Loggable -Log adapters checks whether the log should be printed out or not by checking this function. -If you want to disable/hide logs for output, override `isLoggable` method and put the condition. +Log adapter checks whether the log should be printed or not by checking this function. +If you want to disable/hide logs for output, override `isLoggable` method. +`true` will print the log message, `false` will ignore it. ```java Logger.addLogAdapter(new AndroidLogAdapter() { @Override public boolean isLoggable(int priority, String tag) { @@ -98,7 +99,7 @@ Logger.addLogAdapter(new DiskLogAdapter(formatStrategy)); ### More -- Use the filter for a better result. PRETTY_LOGGER or your custom tag +- Use filter for a better result. PRETTY_LOGGER or your custom tag - Make sure that wrap option is disabled - You can also simplify output by changing settings. @@ -114,13 +115,9 @@ Timber.plant(new Timber.DebugTree() { }); ``` -### Breaking changes -- Initialization is changed. No backward compatibility support. Use `Logger.addLogAdapter` -- LogLevel is removed. Use the new `isLoggable` approach - ### License
-Copyright 2017 Orhan Obut
+Copyright 2018 Orhan Obut
 
 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
diff --git a/gradle.properties b/gradle.properties
index 1ec89437..86a28fb1 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -1,4 +1,4 @@
-VERSION_NAME=2.1.1
+VERSION_NAME=2.2.0
 GROUP=com.orhanobut
 
 POM_DESCRIPTION=Simple, Pretty and Advanced Logger
diff --git a/gradle/maven_push.gradle b/gradle/maven_push.gradle
index 584ecfb7..d15c1f2d 100644
--- a/gradle/maven_push.gradle
+++ b/gradle/maven_push.gradle
@@ -27,7 +27,7 @@ afterEvaluate { project ->
         pom.artifactId = POM_ARTIFACT_ID
         repository(url: sonatypeRepositoryUrl) {
           try {
-            authentication(userName: mavenUser, password: mavenPassword)
+            authentication(userName: NEXUS_USERNAME, password: NEXUS_PASSWORD)
           } catch (Exception ignored) {
             println "mavenUser or mavenPassword is missing"
           }
diff --git a/logger/src/main/java/com/orhanobut/logger/AndroidLogAdapter.java b/logger/src/main/java/com/orhanobut/logger/AndroidLogAdapter.java
index 35a884a4..3eaedab3 100644
--- a/logger/src/main/java/com/orhanobut/logger/AndroidLogAdapter.java
+++ b/logger/src/main/java/com/orhanobut/logger/AndroidLogAdapter.java
@@ -5,6 +5,19 @@
 
 import static com.orhanobut.logger.Utils.checkNotNull;
 
+/**
+ * Android terminal log output implementation for {@link LogAdapter}.
+ *
+ * Prints output to LogCat with pretty borders.
+ *
+ * 
+ *  ┌──────────────────────────
+ *  │ Method stack history
+ *  ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
+ *  │ Log message
+ *  └──────────────────────────
+ * 
+ */ public class AndroidLogAdapter implements LogAdapter { @NonNull private final FormatStrategy formatStrategy; diff --git a/logger/src/main/java/com/orhanobut/logger/DiskLogAdapter.java b/logger/src/main/java/com/orhanobut/logger/DiskLogAdapter.java index 6576090e..2d4fb5ce 100644 --- a/logger/src/main/java/com/orhanobut/logger/DiskLogAdapter.java +++ b/logger/src/main/java/com/orhanobut/logger/DiskLogAdapter.java @@ -5,6 +5,10 @@ import static com.orhanobut.logger.Utils.checkNotNull; +/** + * This is used to saves log messages to the disk. + * By default it uses {@link CsvFormatStrategy} to translates text message into CSV format. + */ public class DiskLogAdapter implements LogAdapter { @NonNull private final FormatStrategy formatStrategy; diff --git a/logger/src/main/java/com/orhanobut/logger/DiskLogStrategy.java b/logger/src/main/java/com/orhanobut/logger/DiskLogStrategy.java index eef68813..7d742d06 100644 --- a/logger/src/main/java/com/orhanobut/logger/DiskLogStrategy.java +++ b/logger/src/main/java/com/orhanobut/logger/DiskLogStrategy.java @@ -15,6 +15,8 @@ /** * Abstract class that takes care of background threading the file log operation on Android. * implementing classes are free to directly perform I/O operations there. + * + * Writes all logs to the disk with CSV format. */ public class DiskLogStrategy implements LogStrategy { diff --git a/logger/src/main/java/com/orhanobut/logger/FormatStrategy.java b/logger/src/main/java/com/orhanobut/logger/FormatStrategy.java index 44d043bb..2256dc86 100644 --- a/logger/src/main/java/com/orhanobut/logger/FormatStrategy.java +++ b/logger/src/main/java/com/orhanobut/logger/FormatStrategy.java @@ -3,6 +3,12 @@ import android.support.annotation.NonNull; import android.support.annotation.Nullable; +/** + * Used to determine how messages should be printed or saved. + * + * @see PrettyFormatStrategy + * @see CsvFormatStrategy + */ public interface FormatStrategy { void log(int priority, @Nullable String tag, @NonNull String message); diff --git a/logger/src/main/java/com/orhanobut/logger/LogAdapter.java b/logger/src/main/java/com/orhanobut/logger/LogAdapter.java index 1468566c..f58e54d2 100644 --- a/logger/src/main/java/com/orhanobut/logger/LogAdapter.java +++ b/logger/src/main/java/com/orhanobut/logger/LogAdapter.java @@ -3,9 +3,31 @@ import android.support.annotation.NonNull; import android.support.annotation.Nullable; +/** + * Provides a common interface to emits logs through. This is a required contract for Logger. + * + * @see AndroidLogAdapter + * @see DiskLogAdapter + */ public interface LogAdapter { + /** + * Used to determine whether log should be printed out or not. + * + * @param priority is the log level e.g. DEBUG, WARNING + * @param tag is the given tag for the log message + * + * @return is used to determine if log should printed. + * If it is true, it will be printed, otherwise it'll be ignored. + */ boolean isLoggable(int priority, @Nullable String tag); + /** + * Each log will use this pipeline + * + * @param priority is the log level e.g. DEBUG, WARNING + * @param tag is the given tag for the log message. + * @param message is the given message for the log message. + */ void log(int priority, @Nullable String tag, @NonNull String message); -} +} \ No newline at end of file diff --git a/logger/src/main/java/com/orhanobut/logger/LogStrategy.java b/logger/src/main/java/com/orhanobut/logger/LogStrategy.java index ad71110d..ad7040f3 100644 --- a/logger/src/main/java/com/orhanobut/logger/LogStrategy.java +++ b/logger/src/main/java/com/orhanobut/logger/LogStrategy.java @@ -3,7 +3,21 @@ import android.support.annotation.NonNull; import android.support.annotation.Nullable; +/** + * Determines destination target for the logs such as Disk, Logcat etc. + * + * @see LogcatLogStrategy + * @see DiskLogStrategy + */ public interface LogStrategy { + /** + * This is invoked by Logger each time a log message is processed. + * Interpret this method as last destination of the log in whole pipeline. + * + * @param priority is the log level e.g. DEBUG, WARNING + * @param tag is the given tag for the log message. + * @param message is the given message for the log message. + */ void log(int priority, @Nullable String tag, @NonNull String message); } diff --git a/logger/src/main/java/com/orhanobut/logger/LogcatLogStrategy.java b/logger/src/main/java/com/orhanobut/logger/LogcatLogStrategy.java index 4c75f2d6..1ead6221 100644 --- a/logger/src/main/java/com/orhanobut/logger/LogcatLogStrategy.java +++ b/logger/src/main/java/com/orhanobut/logger/LogcatLogStrategy.java @@ -6,6 +6,11 @@ import static com.orhanobut.logger.Utils.checkNotNull; +/** + * LogCat implementation for {@link LogStrategy} + * + * This simply prints out all logs to Logcat by using standard {@link Log} class. + */ public class LogcatLogStrategy implements LogStrategy { static final String DEFAULT_TAG = "NO_TAG"; diff --git a/logger/src/main/java/com/orhanobut/logger/Logger.java b/logger/src/main/java/com/orhanobut/logger/Logger.java index 6d5dc278..6a538f21 100644 --- a/logger/src/main/java/com/orhanobut/logger/Logger.java +++ b/logger/src/main/java/com/orhanobut/logger/Logger.java @@ -6,7 +6,63 @@ import static com.orhanobut.logger.Utils.checkNotNull; /** - * But more pretty, simple and powerful + *
+ *  ┌────────────────────────────────────────────
+ *  │ LOGGER
+ *  ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
+ *  │ Standard logging mechanism
+ *  ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
+ *  │ But more pretty, simple and powerful
+ *  └────────────────────────────────────────────
+ * 
+ * + *

How to use it

+ * Initialize it first + *

+ *   Logger.addLogAdapter(new AndroidLogAdapter());
+ * 
+ * + * And use the appropriate static Logger methods. + * + *

+ *   Logger.d("debug");
+ *   Logger.e("error");
+ *   Logger.w("warning");
+ *   Logger.v("verbose");
+ *   Logger.i("information");
+ *   Logger.wtf("What a Terrible Failure");
+ * 
+ * + *

String format arguments are supported

+ *

+ *   Logger.d("hello %s", "world");
+ * 
+ * + *

Collections are support ed(only available for debug logs)

+ *

+ *   Logger.d(MAP);
+ *   Logger.d(SET);
+ *   Logger.d(LIST);
+ *   Logger.d(ARRAY);
+ * 
+ * + *

Json and Xml support (output will be in debug level)

+ *

+ *   Logger.json(JSON_CONTENT);
+ *   Logger.xml(XML_CONTENT);
+ * 
+ * + *

Customize Logger

+ * Based on your needs, you can change the following settings: + * + * + * @see LogAdapter + * @see FormatStrategy + * @see LogStrategy */ public final class Logger { diff --git a/logger/src/main/java/com/orhanobut/logger/PrettyFormatStrategy.java b/logger/src/main/java/com/orhanobut/logger/PrettyFormatStrategy.java index f71a460a..74e33ad5 100644 --- a/logger/src/main/java/com/orhanobut/logger/PrettyFormatStrategy.java +++ b/logger/src/main/java/com/orhanobut/logger/PrettyFormatStrategy.java @@ -5,6 +5,35 @@ import static com.orhanobut.logger.Utils.checkNotNull; +/** + * Draws borders around the given log message along with additional information such as : + * + * + * + *
+ *  ┌──────────────────────────
+ *  │ Method stack history
+ *  ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
+ *  │ Thread information
+ *  ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
+ *  │ Log message
+ *  └──────────────────────────
+ * 
+ * + *

Customize

+ *

+ *   FormatStrategy formatStrategy = PrettyFormatStrategy.newBuilder()
+ *       .showThreadInfo(false)  // (Optional) Whether to show thread info or not. Default true
+ *       .methodCount(0)         // (Optional) How many method line to show. Default 2
+ *       .methodOffset(7)        // (Optional) Hides internal method calls up to offset. Default 5
+ *       .logStrategy(customLog) // (Optional) Changes the log strategy to print out. Default LogCat
+ *       .tag("My custom tag")   // (Optional) Global tag for every log. Default PRETTY_LOGGER
+ *       .build();
+ * 
+ */ public class PrettyFormatStrategy implements FormatStrategy { /** diff --git a/logger/src/main/java/com/orhanobut/logger/Printer.java b/logger/src/main/java/com/orhanobut/logger/Printer.java index 93b6fda3..9fad8de3 100644 --- a/logger/src/main/java/com/orhanobut/logger/Printer.java +++ b/logger/src/main/java/com/orhanobut/logger/Printer.java @@ -3,6 +3,10 @@ import android.support.annotation.NonNull; import android.support.annotation.Nullable; +/** + * A proxy interface to enable additional operations. + * Contains all possible Log message usages. + */ public interface Printer { void addAdapter(@NonNull LogAdapter adapter);