Skip to content
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

prohibit fluent logger to chocke on its own log messages in case of failure #59

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions src/main/java/org/fluentd/logger/sender/RawSocketSender.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ public class RawSocketSender implements Sender {

private ErrorHandler errorHandler = DEFAULT_ERROR_HANDLER;

private long lastCannotSendLogTimestamp = 0;

public RawSocketSender() {
this("localhost", 24224);
}
Expand Down Expand Up @@ -130,9 +132,7 @@ public boolean emit(String tag, long timestamp, Map<String, Object> data) {
}

protected boolean emit(Event event) {
if (LOG.isTraceEnabled()) {
LOG.trace(String.format("Created %s", new Object[]{event}));
}
LOG.trace("Created {}", event);

byte[] bytes = null;
try {
Expand Down Expand Up @@ -162,7 +162,7 @@ private synchronized boolean send(byte[] bytes) {
// buffering
if (pendings.position() + bytes.length > pendings.capacity()) {
if (!flushBuffer()) {
LOG.error("Cannot send logs to " + server.toString());
logCannotSendMaxOncePerMinute();
return false;
}
}
Expand All @@ -179,6 +179,14 @@ private synchronized boolean send(byte[] bytes) {
return true;
}

private void logCannotSendMaxOncePerMinute() {
// to not choke on our own log message
if(System.currentTimeMillis() + 60 * 1000 > lastCannotSendLogTimestamp) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The suppression time 60 seconds seems too long to me. Could you make this value configurable (default: 10 seconds)?

LOG.error("Cannot send logs to " + server.toString());
lastCannotSendLogTimestamp = System.currentTimeMillis();
}
}

@Override
public synchronized void flush() {
try {
Expand Down