Skip to content

Commit c0d7ba6

Browse files
committed
some cleanup of the Logger class
1 parent 133196b commit c0d7ba6

File tree

2 files changed

+48
-44
lines changed

2 files changed

+48
-44
lines changed

doc/CHANGELOG.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
21 Nov 2006 (whalin)
1+
16 Dec 2006 (whalin)
22
-- released as 1.5
3+
-- urlencode keys
4+
5+
21 Nov 2006 (whalin)
36
-- some more fixes for the failover code
47
-- add support for optional healthcheck on checkout (disabled by default)
58

src/com/danga/MemCached/Logger.java

Lines changed: 44 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -46,22 +46,23 @@ public class Logger {
4646
public static final int LEVEL_ERROR = 3;
4747
public static final int LEVEL_FATAL = 4;
4848

49-
private static Map loggers = new Hashtable();
49+
private static Map<String,Logger> loggers =
50+
new HashMap<String,Logger>();
5051

5152
private String name;
5253
private int level;
5354
private boolean initialized = false;
5455

55-
public void setLevel(int level) { this.level = level; }
56+
public void setLevel( int level ) { this.level = level; }
5657
public int getLevel() { return this.level; }
5758

58-
protected Logger(String name, int level) {
59+
protected Logger( String name, int level ) {
5960
this.name = name;
6061
this.level = level;
6162
this.initialized = true;
6263
}
6364

64-
protected Logger(String name) {
65+
protected Logger( String name ) {
6566
this.name = name;
6667
this.level = LEVEL_INFO;
6768
this.initialized = true;
@@ -74,10 +75,10 @@ protected Logger(String name) {
7475
* @param level
7576
* @return
7677
*/
77-
public static Logger getLogger(String name, int level) {
78-
Logger log = getLogger(name);
79-
if (log.getLevel() != level)
80-
log.setLevel(level);
78+
public static synchronized Logger getLogger( String name, int level ) {
79+
Logger log = getLogger( name );
80+
if ( log.getLevel() != level )
81+
log.setLevel( level );
8182

8283
return log;
8384
}
@@ -89,14 +90,14 @@ public static Logger getLogger(String name, int level) {
8990
* @param name
9091
* @return
9192
*/
92-
public static Logger getLogger(String name) {
93+
public static synchronized Logger getLogger( String name ) {
9394

9495
Logger log = null;
95-
if (loggers.containsKey(name)) {
96-
log = (Logger) loggers.get(name);
97-
98-
} else {
99-
log = new Logger(name);
96+
if ( loggers.containsKey( name ) ) {
97+
log = loggers.get( name );
98+
}
99+
else {
100+
log = new Logger( name );
100101
loggers.put( name, log );
101102
}
102103

@@ -109,10 +110,10 @@ public static Logger getLogger(String name) {
109110
* @param mesg
110111
* @param ex
111112
*/
112-
private void log(String mesg, Exception ex) {
113-
System.out.println(name + " " + new Date() + " - " + mesg);
114-
if (ex != null)
115-
ex.printStackTrace(System.out);
113+
private void log( String mesg, Exception ex ) {
114+
System.out.println( name + " " + new Date() + " - " + mesg );
115+
if ( ex != null )
116+
ex.printStackTrace( System.out );
116117
}
117118

118119
/**
@@ -121,15 +122,15 @@ private void log(String mesg, Exception ex) {
121122
* @param mesg
122123
* @param ex
123124
*/
124-
public void debug(String mesg, Exception ex) {
125-
if (this.level > LEVEL_DEBUG)
125+
public void debug( String mesg, Exception ex ) {
126+
if ( this.level > LEVEL_DEBUG )
126127
return;
127128

128-
log(mesg, ex);
129+
log( mesg, ex );
129130
}
130131

131-
public void debug(String mesg) {
132-
debug(mesg, null);
132+
public void debug( String mesg ) {
133+
debug( mesg, null );
133134
}
134135

135136
/**
@@ -138,15 +139,15 @@ public void debug(String mesg) {
138139
* @param mesg
139140
* @param ex
140141
*/
141-
public void info(String mesg, Exception ex) {
142-
if (this.level > LEVEL_INFO)
142+
public void info( String mesg, Exception ex ) {
143+
if ( this.level > LEVEL_INFO )
143144
return;
144145

145-
log(mesg, ex);
146+
log( mesg, ex );
146147
}
147148

148-
public void info(String mesg) {
149-
info(mesg, null);
149+
public void info( String mesg ) {
150+
info( mesg, null );
150151
}
151152

152153
/**
@@ -155,15 +156,15 @@ public void info(String mesg) {
155156
* @param mesg
156157
* @param ex
157158
*/
158-
public void warn(String mesg, Exception ex) {
159-
if (this.level > LEVEL_WARN)
159+
public void warn( String mesg, Exception ex ) {
160+
if ( this.level > LEVEL_WARN )
160161
return;
161162

162-
log(mesg, ex);
163+
log( mesg, ex );
163164
}
164165

165-
public void warn(String mesg) {
166-
warn(mesg, null);
166+
public void warn( String mesg ) {
167+
warn( mesg, null );
167168
}
168169

169170
/**
@@ -172,15 +173,15 @@ public void warn(String mesg) {
172173
* @param mesg
173174
* @param ex
174175
*/
175-
public void error(String mesg, Exception ex) {
176-
if (this.level > LEVEL_ERROR)
176+
public void error( String mesg, Exception ex ) {
177+
if ( this.level > LEVEL_ERROR )
177178
return;
178179

179-
log(mesg, ex);
180+
log( mesg, ex );
180181
}
181182

182-
public void error(String mesg) {
183-
error(mesg, null);
183+
public void error( String mesg ) {
184+
error( mesg, null );
184185
}
185186

186187
/**
@@ -189,14 +190,14 @@ public void error(String mesg) {
189190
* @param mesg
190191
* @param ex
191192
*/
192-
public void fatal(String mesg, Exception ex) {
193-
if (this.level > LEVEL_FATAL)
193+
public void fatal( String mesg, Exception ex ) {
194+
if ( this.level > LEVEL_FATAL )
194195
return;
195196

196-
log(mesg, ex);
197+
log( mesg, ex );
197198
}
198199

199-
public void fatal(String mesg) {
200-
fatal(mesg, null);
200+
public void fatal( String mesg ) {
201+
fatal( mesg, null );
201202
}
202203
}

0 commit comments

Comments
 (0)