1 package cz.cuni.amis.pogamut.base.utils.logging;
2
3 import java.util.logging.Handler;
4 import java.util.logging.LogRecord;
5
6
7
8
9
10
11
12
13
14
15
16 public class LogHandler extends Handler implements Cloneable {
17
18 public static class ConsoleLogHandler extends LogHandler {
19
20 public ConsoleLogHandler() {
21 super(new LogPublisher.ConsolePublisher());
22 }
23
24 }
25
26 protected ILogPublisher publisher = null;
27
28
29
30
31 public LogHandler() {
32 }
33
34 @Override
35 public int hashCode() {
36 return 12345678;
37 }
38
39 public boolean equals(Object obj) {
40 if (obj == null) return false;
41 if (!(obj instanceof LogHandler)) return false;
42 return publisher.equals(((LogHandler)obj).publisher);
43 }
44
45
46
47
48
49 public LogHandler(ILogPublisher publisher) {
50 this.publisher = publisher;
51 }
52
53
54
55
56
57 public synchronized ILogPublisher getPublisher() {
58 return publisher;
59 }
60
61
62
63
64
65 public synchronized void setPublisher(ILogPublisher publisher) {
66 this.publisher = publisher;
67 }
68
69 @Override
70 public synchronized void close() throws SecurityException {
71 ILogPublisher actualPublisher = publisher;
72 if (actualPublisher != null) actualPublisher.close();
73 }
74
75 @Override
76 public synchronized void flush() {
77 ILogPublisher actualPublisher = publisher;
78 if (actualPublisher != null) actualPublisher.flush();
79 }
80
81 @Override
82 public synchronized void publish(LogRecord record) {
83 ILogPublisher actualPublisher = publisher;
84 if (actualPublisher != null) actualPublisher.publish(record);
85 }
86
87 }