2
2
package ch .qos .logback .amqp ;
3
3
4
4
5
- import java .io .Serializable ;
6
5
import java .util .concurrent .LinkedBlockingDeque ;
7
6
8
7
import ch .qos .logback .amqp .tools .DefaultBinarySerializer ;
9
8
import ch .qos .logback .amqp .tools .DefaultContextAwareCallbacks ;
9
+ import ch .qos .logback .amqp .tools .DefaultMutator ;
10
+ import ch .qos .logback .amqp .tools .Mutator ;
11
+ import ch .qos .logback .amqp .tools .PubLoggingEventVO ;
10
12
import ch .qos .logback .amqp .tools .Serializer ;
11
13
import ch .qos .logback .classic .PatternLayout ;
12
- import ch .qos .logback .classic .net .LoggingEventPreSerializationTransformer ;
13
14
import ch .qos .logback .classic .spi .ILoggingEvent ;
14
15
import ch .qos .logback .core .Context ;
15
16
import ch .qos .logback .core .UnsynchronizedAppenderBase ;
16
- import ch .qos .logback .core .spi .PreSerializationTransformer ;
17
17
18
18
19
19
public final class AmqpAppender
@@ -22,16 +22,21 @@ public final class AmqpAppender
22
22
public AmqpAppender ()
23
23
{
24
24
super ();
25
- this .preserializer = new LoggingEventPreSerializationTransformer ();
26
25
this .serializer = new DefaultBinarySerializer ();
27
26
this .buffer = new LinkedBlockingDeque <AmqpMessage > ();
28
27
this .exchangeLayout = new PatternLayout ();
29
28
this .routingKeyLayout = new PatternLayout ();
30
29
this .exchangeLayout .setPattern (AmqpAppender .defaultExchangeKeyPattern );
31
30
this .routingKeyLayout .setPattern (AmqpAppender .defaultRoutingKeyPattern );
31
+ this .mutator = new DefaultMutator ();
32
32
this .publisher = null ;
33
33
}
34
34
35
+ public final Mutator getMutator ()
36
+ {
37
+ return (this .mutator );
38
+ }
39
+
35
40
public final boolean isDrained ()
36
41
{
37
42
return (this .buffer .isEmpty ());
@@ -66,6 +71,13 @@ public final void setHost (final String host)
66
71
this .host = host ;
67
72
}
68
73
74
+ public final void setMutator (final Mutator mutator )
75
+ {
76
+ if (this .isStarted ())
77
+ throw (new IllegalStateException ("amqp appender is already started" ));
78
+ this .mutator = mutator ;
79
+ }
80
+
69
81
public final void setPassword (final String password )
70
82
{
71
83
if (this .isStarted ())
@@ -127,19 +139,19 @@ public final void stop ()
127
139
super .stop ();
128
140
}
129
141
130
- protected final void append (final ILoggingEvent event )
142
+ protected final void append (final ILoggingEvent originalEvent )
131
143
{
144
+ final PubLoggingEventVO event = this .prepare (originalEvent );
132
145
byte [] data ;
133
146
try {
134
- final Serializable object = this .preserializer .transform (event );
135
- data = this .serializer .serialize (object );
147
+ data = this .serializer .serialize (event );
136
148
} catch (final Throwable exception ) {
137
149
data = null ;
138
150
this .addError ("amqp appender encountered an error while serializing the event; ignoring!" , exception );
139
151
}
140
152
if (data != null ) {
141
- final String exchange = this .exchangeLayout .doLayout (event );
142
- final String routingKey = this .routingKeyLayout .doLayout (event );
153
+ final String exchange = this .exchangeLayout .doLayout (originalEvent );
154
+ final String routingKey = this .routingKeyLayout .doLayout (originalEvent );
143
155
final AmqpMessage message =
144
156
new AmqpMessage (
145
157
exchange , routingKey , this .serializer .getContentType (), this .serializer .getContentEncoding (),
@@ -148,12 +160,20 @@ protected final void append (final ILoggingEvent event)
148
160
}
149
161
}
150
162
163
+ private final PubLoggingEventVO prepare (final ILoggingEvent originalEvent )
164
+ {
165
+ final PubLoggingEventVO newEvent = PubLoggingEventVO .build (originalEvent );
166
+ if (this .mutator != null )
167
+ this .mutator .mutate (newEvent );
168
+ return (newEvent );
169
+ }
170
+
151
171
private final LinkedBlockingDeque <AmqpMessage > buffer ;
152
172
private final PatternLayout exchangeLayout ;
153
173
private String host ;
174
+ private Mutator mutator ;
154
175
private String password ;
155
176
private Integer port ;
156
- private final PreSerializationTransformer <ILoggingEvent > preserializer ;
157
177
private AmqpPublisher publisher ;
158
178
private final PatternLayout routingKeyLayout ;
159
179
private final Serializer serializer ;
0 commit comments