forked from creativein/AndroidTools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LoggerWrapper.java
89 lines (79 loc) · 2.94 KB
/
LoggerWrapper.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package com.soi.modules;
import android.util.Log;
/**
* Created by IntelliJ IDEA.
* Date: 2/16/13
* Time: 9:52 PM
* Author: spirosoikonomakis
* To change this template use File | Settings | File Templates.
*/
public class LoggerWrapper {
private String _tag = "SOIKONOMAKIS";
private static LoggerWrapper _instance ;
public int LOGGER_LEVEL = Log.INFO;
public LoggerWrapper(int LOGGER_LEVEL, String tag) {
this.LOGGER_LEVEL = LOGGER_LEVEL;
this._tag = tag;
}
public static void initInstance(int LOGGER_LEVEL, String tag){
if (_instance == null){
_instance = new LoggerWrapper(LOGGER_LEVEL,tag);
}
}
public static LoggerWrapper getInstance(){
return _instance;
}
/**
* Logs with [INFO][tag] msg
* @param tag The tag which the logger will shown in logcat
* @param msgFormat the format the message will be appeared "Hello %s, isn't %s cool?
* @param args the arguments which you want to use
*/
public void logInfo(String tag, String msgFormat, Object...args) {
Log.i(tag, String.format(msgFormat,args));
}
/**
* Logs with [INFO][_tag] msg
* @param msgFormat the format the message will be appeared "Hello %s, isn't %s cool?
* @param args the arguments which you want to use
*/
public void logInfo(String msgFormat, Object...args) {
Log.i(_tag, String.format(msgFormat,args));
}
/**
* Logs with [DEBUG][tag] msg
* @param tag The tag which the logger will shown in logcat
* @param msgFormat the format the message will be appeared "Hello %s, isn't %s cool?
* @param args the arguments which you want to use
*/
public void logDebug(String tag, String msgFormat, Object...args) {
if(LOGGER_LEVEL <= Log.DEBUG)
Log.d(tag, String.format(msgFormat,args));
}
/**
* Logs with [DEBUG][_tag] msg
* @param msgFormat the format the message will be appeared "Hello %s, isn't %s cool?
* @param args the arguments which you want to use
*/
public void logDebug(String msgFormat, Object...args) {
if(LOGGER_LEVEL <= Log.WARN)
Log.d(_tag, String.format(msgFormat,args));
}
/**
* Logs with [ERROR][tag] msg exception
* @param tag The tag which the logger will shown in logcat
* @param msgFormat the format the message will be appeared "Hello %s, isn't %s cool?
* @param args the arguments which you want to use
*/
public void logError(String tag, String msgFormat, Exception ex, Object...args) {
Log.e(tag, String.format(msgFormat,args),ex);
}
/**
* Logs with [ERROR][tag] msg exception
* @param msgFormat the format the message will be appeared "Hello %s, isn't %s cool?
* @param args the arguments which you want to use
*/
public void logError(String msgFormat, Exception ex, Object...args) {
Log.e(_tag, String.format(msgFormat,args), ex);
}
}