-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Remove System.out.println statements (#16)
- Loading branch information
1 parent
9d2e468
commit 41a65b3
Showing
6 changed files
with
118 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package com.mparticle; | ||
|
||
public class Logger { | ||
private static AbstractLogHandler logHandler; | ||
public enum LogLevel { | ||
INFO, ERROR | ||
} | ||
|
||
public static void info(String message) { | ||
if(getLogHandler() != null) | ||
getLogHandler().log(LogLevel.INFO, null, message); | ||
} | ||
|
||
public static void error(String message) { | ||
if(getLogHandler() != null) | ||
getLogHandler().log(LogLevel.ERROR, null, message); | ||
} | ||
|
||
public static void error(Throwable error) { | ||
if(getLogHandler() != null) | ||
getLogHandler().log(LogLevel.ERROR, error, error.toString()); | ||
} | ||
|
||
/** | ||
* Testing method. Use this method to intercept Logs, or customize what happens when something is logged. | ||
* For example, you can use this method to throw an exception every time an "error" log is called. | ||
* @param logListener | ||
*/ | ||
public static void setLogHandler(AbstractLogHandler logListener) { | ||
Logger.logHandler = logListener; | ||
} | ||
|
||
public static AbstractLogHandler getLogHandler() { | ||
return logHandler; | ||
} | ||
|
||
public abstract static class AbstractLogHandler { | ||
|
||
public void log(LogLevel priority, Throwable error, String message) { | ||
if (message != null) { | ||
switch (priority) { | ||
case ERROR: | ||
error(error, message); | ||
break; | ||
case INFO: | ||
info(message); | ||
} | ||
} | ||
} | ||
|
||
public abstract void info(String message); | ||
public abstract void error(Throwable error, String message); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.mparticle.client; | ||
|
||
import com.mparticle.Logger.AbstractLogHandler; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class DefaultLogHandler extends AbstractLogHandler { | ||
|
||
private static final Logger Log = LoggerFactory.getLogger(DefaultLogHandler.class); | ||
@Override | ||
public void info(String message) { | ||
Log.info(message); | ||
|
||
} | ||
|
||
@Override | ||
public void error(Throwable error, String message) { | ||
if (error != null) { | ||
Log.error(error.toString()); | ||
} else { | ||
Log.error(message); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters