-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Sam Lord
authored and
Sam Lord
committed
Jan 22, 2016
1 parent
e74bbe6
commit e3605e0
Showing
4 changed files
with
73 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package chat.haver.server; | ||
|
||
import java.util.Date; | ||
|
||
/** | ||
* Created by azertify on 22/01/2016. | ||
*/ | ||
public class Logger { | ||
|
||
public static void info(String message) { | ||
out(format(message, "info")); | ||
} | ||
|
||
public static void warning(String message) { | ||
err(format(message, "warning")); | ||
} | ||
|
||
public static void sever(String message) { | ||
err(format(message, "sever")); | ||
} | ||
|
||
private static String format(String message, String type) { | ||
Date date = new Date(); | ||
StackTraceElement ste = Thread.currentThread().getStackTrace()[3]; | ||
String[] arr = ste.getClassName().split("\\."); | ||
String classDetails = arr[arr.length] + ":" + ste.getMethodName(); | ||
if (type.equalsIgnoreCase("warning") || type.equalsIgnoreCase("sever")) { | ||
return "[" + date.toString() + "] " + type.toUpperCase() + " (" + classDetails + ") " + message; | ||
} else { | ||
return "[" + date.toString() + "] " + type.toUpperCase() + " " + message; | ||
} | ||
} | ||
|
||
private static void out(String message) { | ||
switch(Main.ENVIRONMENT) { | ||
case DEVELOPMENT: | ||
System.out.println(message); | ||
break; | ||
case TESTING: | ||
System.out.println(message); | ||
break; | ||
case PRODUCTION: | ||
System.out.println(message); // TODO: Sort out production logging | ||
break; | ||
} | ||
} | ||
|
||
private static void err(String message) { | ||
switch(Main.ENVIRONMENT) { | ||
case DEVELOPMENT: | ||
System.err.println(message); | ||
break; | ||
case TESTING: | ||
System.out.println(message); | ||
System.err.println(message); | ||
break; | ||
case PRODUCTION: | ||
System.out.println(message); | ||
System.err.println(message); | ||
break; | ||
} | ||
} | ||
} |
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