1 | // Copyright (c) 2002 SPY internetworking <dustin@spy.net> |
2 | |
3 | package net.spy.memcached.compat.log; |
4 | |
5 | import java.text.SimpleDateFormat; |
6 | import java.util.Date; |
7 | |
8 | /** |
9 | * Default logger implementation. |
10 | * |
11 | * This logger is really primitive. It just logs everything to stderr if |
12 | * it's higher than INFO. |
13 | */ |
14 | public class DefaultLogger extends AbstractLogger { |
15 | |
16 | private final SimpleDateFormat df; |
17 | |
18 | /** |
19 | * Get an instance of DefaultLogger. |
20 | */ |
21 | public DefaultLogger(String name) { |
22 | super(name); |
23 | df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); |
24 | } |
25 | |
26 | /** |
27 | * False. |
28 | */ |
29 | @Override |
30 | public boolean isDebugEnabled() { |
31 | return(false); |
32 | } |
33 | |
34 | /** |
35 | * True. |
36 | */ |
37 | @Override |
38 | public boolean isInfoEnabled() { |
39 | return(true); |
40 | } |
41 | |
42 | /** |
43 | * @see AbstractLogger |
44 | */ |
45 | @Override |
46 | public synchronized void log(Level level, Object message, Throwable e) { |
47 | if(level == Level.INFO |
48 | || level == Level.WARN |
49 | || level == Level.ERROR |
50 | || level == Level.FATAL) { |
51 | System.err.printf("%s %s %s: %s\n", |
52 | df.format(new Date()), level.name(), getName(), message); |
53 | if(e != null) { |
54 | e.printStackTrace(); |
55 | } |
56 | } |
57 | } |
58 | |
59 | } |