From 7806d1d20f0541ff1765bf8d81687f9d8b3ebab5 Mon Sep 17 00:00:00 2001 From: orhanobut Date: Sat, 21 Mar 2015 11:17:23 +0100 Subject: [PATCH] v1.1 --- README.md | 8 ++++--- gradle.properties | 4 ++-- .../java/com/orhanobut/logger/LogLevel.java | 17 +++++++++++++++ .../java/com/orhanobut/logger/Logger.java | 21 ++++++++++++++++--- 4 files changed, 42 insertions(+), 8 deletions(-) create mode 100644 logger/src/main/java/com/orhanobut/logger/LogLevel.java diff --git a/README.md b/README.md index ebad4cd0..36a9cf81 100644 --- a/README.md +++ b/README.md @@ -9,11 +9,11 @@ Logger provides : - Method information - Pretty-print for json content - Clean log -- Jump to source feature : Easily go to source which made the log info +- Jump to source feature ### Gradle ```groovy -compile 'com.orhanobut:logger:1.0' +compile 'com.orhanobut:logger:1.1' ``` ### Current Log system @@ -44,10 +44,12 @@ Logger.json(JSON_CONTENT); Change the settings with init. This should be called only once. Best place would be in application class ```java Logger - .init(YOUR_TAG) // default tag : PRETTYLOGGER + .init(LogLevel, YOUR_TAG) // default tag : PRETTYLOGGER, LogLevel = FULL .setMethodCount(3) // default 2 .hideThreadInfo(); // default it is shown ``` +- If you init Logger with LogLevel.NONE, no log will be printed, use it for release versions. + ### More log samples ```java Logger.d("hello"); diff --git a/gradle.properties b/gradle.properties index 63e6426d..c22cb622 100644 --- a/gradle.properties +++ b/gradle.properties @@ -18,8 +18,8 @@ # org.gradle.parallel=true #VERSION_NAME=1.0-SNAPSHOT -VERSION_NAME=1.0 -VERSION_CODE=1 +VERSION_NAME=1.1 +VERSION_CODE=2 GROUP=com.orhanobut POM_DESCRIPTION=Simple,pretty and powerful log diff --git a/logger/src/main/java/com/orhanobut/logger/LogLevel.java b/logger/src/main/java/com/orhanobut/logger/LogLevel.java new file mode 100644 index 00000000..54e86f30 --- /dev/null +++ b/logger/src/main/java/com/orhanobut/logger/LogLevel.java @@ -0,0 +1,17 @@ +package com.orhanobut.logger; + +/** + * @author Orhan Obut + */ +public enum LogLevel { + + /** + * Prints all logs + */ + FULL, + + /** + * No log will be printed + */ + NONE +} diff --git a/logger/src/main/java/com/orhanobut/logger/Logger.java b/logger/src/main/java/com/orhanobut/logger/Logger.java index 4e744cb2..b9a23022 100644 --- a/logger/src/main/java/com/orhanobut/logger/Logger.java +++ b/logger/src/main/java/com/orhanobut/logger/Logger.java @@ -19,13 +19,16 @@ public final class Logger { */ private static final int CHUNK_SIZE = 4000; private static final int JSON_INDENT = 4; + private static final Settings settings = new Settings(); + + private static LogLevel logLevel = LogLevel.FULL; /** * TAG is used for the Log, the name is a little different * in order to differentiate the logs easily with the filter */ private static String TAG = "PRETTYLOGGER"; - private static Settings settings = new Settings(); + //no instance private Logger() { @@ -40,12 +43,20 @@ public static Settings init() { return settings; } + public static Settings init(LogLevel logLevel) { + return init(logLevel, TAG); + } + + public static Settings init(String tag) { + return init(LogLevel.FULL, tag); + } + /** * It is used to change the tag * * @param tag is the given string which will be used in Logger */ - public static Settings init(String tag) { + public static Settings init(LogLevel logLevel, String tag) { if (tag == null) { throw new NullPointerException("tag may not be null"); } @@ -53,6 +64,7 @@ public static Settings init(String tag) { throw new IllegalStateException("tag may not be empty"); } Logger.TAG = tag; + Logger.logLevel = logLevel; return settings; } @@ -171,6 +183,9 @@ public static void json(String json, int methodCount) { } private static void log(int logType, String message, int methodCount) { + if (logLevel == LogLevel.NONE) { + return; + } logHeader(logType); logHeaderContent(logType, methodCount); @@ -236,7 +251,7 @@ private static void logDivider(int logType) { private static void logContent(int logType, String chunk) { String[] lines = chunk.split(System.getProperty("line.separator")); - for (String line : lines){ + for (String line : lines) { logChunk(logType, "║ " + line); } }