1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package com.xley.lfosc.util;
23
24 import com.xley.lfosc.OSCProxy;
25 import org.apache.log4j.Level;
26 import org.apache.log4j.Logger;
27
28 import java.util.Map;
29 import java.util.concurrent.ConcurrentHashMap;
30
31 public class LogUtil {
32
33
34
35
36
37 private static Map<Class, Logger> loggerMap = new ConcurrentHashMap<>();
38 private static Level level = null;
39
40 public static void trace(Object message) {
41 getLogger(OSCProxy.class).trace(message);
42 }
43
44 public static void debug(Object message) {
45 getLogger(OSCProxy.class).debug(message);
46 }
47
48 public static void info(Object message) {
49 getLogger(OSCProxy.class).info(message);
50 }
51
52 public static void warn(Object message) {
53 getLogger(OSCProxy.class).warn(message);
54 }
55
56 public static void error(Object message) {
57 getLogger(OSCProxy.class).error(message);
58 }
59
60 public static void error(Object message, Throwable throwable) {
61 getLogger(OSCProxy.class).error(message, throwable);
62 }
63
64 public static void fatal(Object message) {
65 getLogger(OSCProxy.class).fatal(message);
66 }
67
68 public static void fatal(Object message, Throwable throwable) {
69 getLogger(OSCProxy.class).fatal(message, throwable);
70 }
71
72 public static void trace(Class clazz, Object message) {
73 getLogger(clazz).trace(message);
74 }
75
76 public static void debug(Class clazz, Object message) {
77 getLogger(clazz).debug(message);
78 }
79
80 public static void info(Class clazz, Object message) {
81 getLogger(clazz).info(message);
82 }
83
84 public static void warn(Class clazz, Object message) {
85 getLogger(clazz).warn(message);
86 }
87
88 public static void error(Class clazz, Object message) {
89 getLogger(clazz).error(message);
90 }
91
92 public static void error(Class clazz, Object message, Throwable throwable) {
93 getLogger(clazz).error(message, throwable);
94 }
95
96 public static void fatal(Class clazz, Object message) {
97 getLogger(clazz).fatal(message);
98 }
99
100 public static void fatal(Class clazz, Object message, Throwable throwable) {
101 getLogger(clazz).fatal(message, throwable);
102 }
103
104 private static Logger getLogger(Class clazz) {
105 Logger log = Logger.getLogger(clazz);
106 if (level != null && !loggerMap.containsKey(clazz)) {
107 log.setLevel(level);
108 }
109 loggerMap.put(clazz, log);
110 return log;
111 }
112
113 public static void setLevel(Level logLevel) {
114 level = logLevel;
115 for (Logger log : loggerMap.values()) {
116 log.setLevel(level);
117 }
118 }
119 }
120