-
-
Notifications
You must be signed in to change notification settings - Fork 81
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
Add syslog writer #507
Add syslog writer #507
Conversation
Codecov Report
@@ Coverage Diff @@
## v2.7 #507 +/- ##
============================================
- Coverage 94.46% 94.33% -0.14%
- Complexity 2799 2830 +31
============================================
Files 143 149 +6
Lines 5457 5577 +120
Branches 714 722 +8
============================================
+ Hits 5155 5261 +106
- Misses 164 176 +12
- Partials 138 140 +2
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
Thank you for your pull request! I will review it soon. However, your changes looks very good at first sight. :) |
@@ -65,7 +65,7 @@ protected String getFileName() { | |||
* | |||
* @return Configured charset | |||
*/ | |||
protected Charset getCharset() { | |||
protected final Charset getCharset() { |
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.
I think it is not necessary to make this method final. This could break other writers that are not part of tinylog itself.
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.
Updated.
|
||
String protocol = getStringValue("protocol"); | ||
if (protocol == null) { | ||
throw new IllegalArgumentException("Missing protocol"); |
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.
Suggestion (but not a must): What do you think about using the UdpSocketWriter or TcpSocketWriter by default if no protocol is configured instead of throwing an exception?
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.
Updated, used udp protocol as a default.
* @return The formated message. | ||
*/ | ||
public byte[] formatMessage(final LogEntry logEntry) { | ||
|
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.
You can delete this empty line.
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.
Updated.
@Override | ||
public void write(final LogEntry logEntry) throws IOException { | ||
byte[] b = formatMessage(logEntry); | ||
socket.getOutputStream().write(b); |
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.
Could you use a full name for the variable b
like data
for example?
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.
Updated
|
||
@Override | ||
public void write(final LogEntry logEntry) throws IOException { | ||
byte[] b = formatMessage(logEntry); |
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.
Please use here a full name for the variable b
, too.
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.
Updated
import org.tinylog.Level; | ||
import org.tinylog.provider.InternalLogger; | ||
|
||
public class TcpSyslogServer extends Thread { |
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.
Please start and end the body of the class with an empty line.
import org.tinylog.Level; | ||
import org.tinylog.provider.InternalLogger; | ||
|
||
public class UdpSyslogServer extends Thread { |
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.
Please start and end the body of the class with an empty line, too.
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.
Updated
private String getExpectedSyslogMessage(final String message, | ||
final SyslogFacility facility, | ||
final SyslogSeverity severity, | ||
final String identification) { |
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.
Please check the indentation here.
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.
Updated
assertThat(server.getLastMessage()).isEqualTo(getExpectedSyslogMessage(TEST_MESSAGE, facility, SyslogSeverity.WARNING, "")); | ||
server.shutdown(); | ||
} | ||
} |
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.
Please add an empty line at the end of the class body.
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.
Updated
/** | ||
* Tests for {@link SyslogWriter}. | ||
*/ | ||
public final class SyslogWriterTest { |
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.
Two general wishes:
1st: If you split lines, please move the dot from the end of the line to the start of the next line.
Example:
assertThatThrownBy(() -> new SyslogWriter(doubletonMap("protocol", "udp", "facility", "invalid"))
.write(LogEntryBuilder.empty().message(TEST_MESSAGE).create())).hasMessageMatching("(?i).*SyslogFacility.*");
2nd: Please add some blank lines in longer test methods to group the logic. This makes it easier to read and unterstand the logic.
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.
Updated
I'm done with the review. I could find only a few minors. You have written very good and maintainable code :) |
By the way: Would you be able to add some documentation for the tinylog website? Link: |
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.
Thank you very much for your changes. I could find only one minor. Can you add the missing empty line? Afterwards, I will merge your pull request.
builder.append(": "); | ||
builder.append(render(logEntry)); | ||
return builder.toString().getBytes(charset); | ||
} |
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.
Please add an empty line between line 127 and 128.
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.
Ok, done.
Thank you very much for your great pull request! It's really awesome to have a syslog writer in tinylog. |
Description
Linked issue:
#156
Linked website pull request, if the documention of https://tinylog.org/v2/ has to be updated:
tinylog-org/website#000
Definition of Done
mvn verify
)Agreements