1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package net.sf.jour.log4j;
22
23 import org.apache.log4j.spi.LoggingEvent;
24 import org.apache.log4j.AppenderSkeleton;
25
26 import java.io.ObjectOutputStream;
27 import java.io.ByteArrayOutputStream;
28
29 /***
30 * A bogus appender which calls the format method of its layout object but does not write the result
31 * anywhere.
32 *
33 */
34 public class NullAppender extends AppenderSkeleton {
35
36 static long eventCnt;
37
38 public NullAppender() {
39 }
40
41 public void close() {
42 System.out.println("Close. evenCtn=" + eventCnt);
43 }
44
45 public void append(LoggingEvent event) {
46 eventCnt ++;
47 if ((eventCnt % 2000) == 0) {
48 Object obj = event.getMessage();
49 String message = obj.toString();
50 String ctn = "Cnt=" + eventCnt + " " + message;
51 if (obj instanceof ProfilerEvent) {
52 printSize(ctn + " ProfilerEvent", obj);
53 } else if (obj instanceof ProfilerEventExt) {
54 printSize(ctn + " ProfilerEventExt", obj);
55 } else {
56 printSize(ctn + " LoggingEvent", event);
57 }
58 }
59 }
60
61 public void printSize(String name, Object obj) {
62 ObjectOutputStream out = null;
63 try {
64 ByteArrayOutputStream baos = new ByteArrayOutputStream();
65 out = new ObjectOutputStream(baos);
66 out.writeObject(obj);
67 System.out.println(name + " size=" + baos.size());
68 } catch (java.io.NotSerializableException ex) {
69 System.out.println(name + " data \"" + ex.getMessage() + "\" is not serializable!");
70 } catch (java.io.IOException e) {
71 System.out.println("Serialization error!");
72 } finally {
73 if (out != null) {
74 try {
75 out.close();
76 } catch (Exception ignore) {
77 }
78 }
79 }
80 }
81
82 public boolean requiresLayout() {
83 return false;
84 }
85 }