Skip to content

Commit

Permalink
v1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
orhanobut committed Mar 21, 2015
1 parent 41788c0 commit 7806d1d
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 8 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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");
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions logger/src/main/java/com/orhanobut/logger/LogLevel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.orhanobut.logger;

/**
* @author Orhan Obut
*/
public enum LogLevel {

/**
* Prints all logs
*/
FULL,

/**
* No log will be printed
*/
NONE
}
21 changes: 18 additions & 3 deletions logger/src/main/java/com/orhanobut/logger/Logger.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -40,19 +43,28 @@ 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");
}
if (tag.trim().length() == 0) {
throw new IllegalStateException("tag may not be empty");
}
Logger.TAG = tag;
Logger.logLevel = logLevel;
return settings;
}

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);
}
}
Expand Down

0 comments on commit 7806d1d

Please sign in to comment.