-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feature-#34 parallel logging #42
Changes from all commits
03c6844
c09f320
939649e
6e362f8
358b1fc
a86c67f
6124a55
aea4d43
dc13646
9d6e879
c2141f1
030ba4f
e2d33a7
0d6329b
1813467
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
Reliable Event Logging Protocol (RELP) Logback plugin | ||
Copyright (C) 2021-2024 Suomen Kanuuna Oy | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
package com.teragrep.jla_01; | ||
|
||
import com.teragrep.rlp_01.pool.Stubable; | ||
|
||
public interface RelpAppender<E> extends Stubable { | ||
|
||
void append(E iLoggingEvent); | ||
void stop(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
Reliable Event Logging Protocol (RELP) Logback plugin | ||
Copyright (C) 2021-2024 Suomen Kanuuna Oy | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
package com.teragrep.jla_01; | ||
|
||
import ch.qos.logback.core.encoder.LayoutWrappingEncoder; | ||
import com.teragrep.jla_01.syslog.*; | ||
import com.teragrep.rlp_01.client.IManagedRelpConnection; | ||
import com.teragrep.rlp_01.pool.Pool; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
|
||
public final class RelpAppenderImpl<E> implements RelpAppender<E> { | ||
|
||
private final Pool<IManagedRelpConnection> relpConnectionPool; | ||
private final String hostname; | ||
private final String appName; | ||
private final String originalHostname; | ||
private final boolean enableEventId48577; | ||
private final LayoutWrappingEncoder<E> encoder; | ||
|
||
public RelpAppenderImpl(Pool<IManagedRelpConnection> relpConnectionPool, String hostname, String appName, String originalHostname, boolean enableEventId48577, LayoutWrappingEncoder<E> encoder) { | ||
this.relpConnectionPool = relpConnectionPool; | ||
this.hostname = hostname; | ||
this.appName = appName; | ||
this.originalHostname = originalHostname; | ||
this.enableEventId48577 = enableEventId48577; | ||
this.encoder = encoder; | ||
} | ||
|
||
@Override | ||
public void append(E iLoggingEvent) { | ||
{ | ||
SyslogRecord syslogRecord = new SyslogRecordConfigured(hostname, appName); | ||
syslogRecord = new SyslogRecordTimestamp(syslogRecord); | ||
syslogRecord = new SyslogRecordOrigin(syslogRecord, originalHostname); | ||
if (enableEventId48577) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. enableEventId48577 boolean seems to configure the behaviour of this method here, so there seems to be use cases where sometimes you want the eventId, sometimes you don't. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please create an issue about this |
||
syslogRecord = new SyslogRecordEventID(syslogRecord, originalHostname); | ||
} | ||
|
||
//syslogRecord = new SyslogRecordMDC(syslogRecord, new HashMap<>()); | ||
StrongestNumber9 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
String payload = encoder.getLayout().doLayout(iLoggingEvent); | ||
syslogRecord = new SyslogRecordPayload(syslogRecord, payload); | ||
|
||
IManagedRelpConnection connection = relpConnectionPool.get(); | ||
|
||
connection.ensureSent(syslogRecord.getRecord().toRfc5424SyslogMessage().getBytes(StandardCharsets.UTF_8)); | ||
relpConnectionPool.offer(connection); | ||
} | ||
} | ||
|
||
@Override | ||
public void stop() { | ||
relpConnectionPool.close(); | ||
} | ||
|
||
@Override | ||
public boolean isStub() { | ||
return false; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
Reliable Event Logging Protocol (RELP) Logback plugin | ||
Copyright (C) 2021-2024 Suomen Kanuuna Oy | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
package com.teragrep.jla_01; | ||
|
||
public final class RelpAppenderStub<E> implements RelpAppender<E> { | ||
@Override | ||
public void append(E iLoggingEvent) { | ||
throw new UnsupportedOperationException("RelpAppenderStub does not support this. Perhaps appender is not started yet."); | ||
} | ||
|
||
@Override | ||
public void stop() { | ||
throw new UnsupportedOperationException("RelpAppenderStub does not support this. Perhaps appender is not started yet."); | ||
} | ||
|
||
@Override | ||
public boolean isStub() { | ||
return true; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
Reliable Event Logging Protocol (RELP) Logback plugin | ||
Copyright (C) 2021-2024 Suomen Kanuuna Oy | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
package com.teragrep.jla_01; | ||
|
||
public final class RelpAppenderSynchronized<E> implements RelpAppender<E> { | ||
|
||
private final RelpAppender<E> appender; | ||
|
||
public RelpAppenderSynchronized(RelpAppender<E> relpAppender) { | ||
this.appender = relpAppender; | ||
} | ||
|
||
@Override | ||
public synchronized void append(E iLoggingEvent) { | ||
appender.append(iLoggingEvent); | ||
} | ||
|
||
@Override | ||
public void stop() { | ||
appender.stop(); | ||
} | ||
|
||
@Override | ||
public boolean isStub() { | ||
return false; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
name ending in -er
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the naming is to reflect the UnsynchronizedAppenderBase naming