Skip to content

Commit e6e9939

Browse files
Fixes issue #1
1 parent ee4ca07 commit e6e9939

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

src/main/java/com/teragrep/jla_04/RelpHandler.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636
public class RelpHandler extends Handler {
3737
private RelpConnection relpConnection;
38-
private final RelpBatch batch = new RelpBatch();
38+
private RelpBatch batch;
3939
private RelpConfig config;
4040

4141
// No arguments defaults to 'default' logger
@@ -92,6 +92,11 @@ public synchronized void publish(LogRecord logRecord) {
9292
.withSDElement(origin_48577);
9393
}
9494

95+
// Initialize the batch for every set of messages
96+
if(this.batch == null) {
97+
this.batch = new RelpBatch();
98+
}
99+
95100
// Add to batch and send
96101
this.batch.insert(syslog.toRfc5424SyslogMessage().getBytes(StandardCharsets.UTF_8));
97102
flush();
@@ -120,6 +125,8 @@ public synchronized void flush() {
120125
allSent = true;
121126
}
122127
}
128+
// Clean the batch
129+
this.batch = null;
123130
}
124131

125132
private void reconnect() throws IOException, TimeoutException {
@@ -153,8 +160,6 @@ private void connect() {
153160

154161
@Override
155162
public synchronized void close() {
156-
// Flush the batches before disconnecting
157-
flush();
158163
try {
159164
disconnect();
160165
} catch (IOException | TimeoutException e) {

0 commit comments

Comments
 (0)