Skip to content
This repository was archived by the owner on Dec 12, 2021. It is now read-only.
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
26 changes: 25 additions & 1 deletion src/main/java/com/logentries/logback/LogentriesAppender.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
*/
public class LogentriesAppender extends AppenderBase<ILoggingEvent> {

/**
*
*/
private boolean useExceptionFormatter;
/**
* Asynchronous Background logger
*/
Expand Down Expand Up @@ -53,6 +57,10 @@ public LogentriesAppender(AsyncLogger logger) {
this.le_async = logger;
}

protected AsyncLogger getAsyncLogger() {
return le_async;
}

/*
* Public methods to send logback parameters to AsyncLogger
*/
Expand All @@ -64,6 +72,13 @@ public LogentriesAppender(AsyncLogger logger) {
public void setToken(String token) {
this.le_async.setToken(token);
}

/**
* Set whether to use com.logentries.logback.ExceptionFormatter when creating default layout
*/
public void setUseExceptionFormatter(boolean value) {
this.useExceptionFormatter = value;
}

/**
* Sets the HTTP PUTflag. <p>Send logs via HTTP PUT instead of default Token
Expand Down Expand Up @@ -233,6 +248,15 @@ public Layout<ILoggingEvent> getLayout() {
protected void append(ILoggingEvent event) {
// Render the event according to layout
String formattedEvent = layout.doLayout(event);

// Append stack trace if present
if (useExceptionFormatter) {
IThrowableProxy error = event.getThrowableProxy();
if (error != null) {
formattedEvent += ExceptionFormatter.formatException(error);
}
}

// Prepare to be queued
this.le_async.addLineToQueue(formattedEvent);
}
Expand All @@ -248,12 +272,12 @@ public void stop() {

public Layout<ILoggingEvent> buildLayout() {
PatternLayout l = new PatternLayout();
l.setContext(getContext());
l.getInstanceConverterMap().put("syslogStart", SyslogStartConverter.class.getName());
if (suffixPattern == null) {
suffixPattern = DEFAULT_SUFFIX_PATTERN;
}
l.setPattern(getPrefixPattern() + suffixPattern);
l.setContext(getContext());
l.start();
return l;
}
Expand Down