Class AwsLambdaAppender

java.lang.Object
ch.qos.logback.core.spi.ContextAwareBase
ch.qos.logback.core.UnsynchronizedAppenderBase<ch.qos.logback.classic.spi.ILoggingEvent>
com.networknt.aws.lambda.AwsLambdaAppender
All Implemented Interfaces:
ch.qos.logback.core.Appender<ch.qos.logback.classic.spi.ILoggingEvent>, ch.qos.logback.core.spi.ContextAware, ch.qos.logback.core.spi.FilterAttachable<ch.qos.logback.classic.spi.ILoggingEvent>, ch.qos.logback.core.spi.LifeCycle

public class AwsLambdaAppender extends ch.qos.logback.core.UnsynchronizedAppenderBase<ch.qos.logback.classic.spi.ILoggingEvent>
Logback Appender to be used in AWS Lambda applications, targeting CloudWatch Logs.

Instead of writing to the standard output, this Appender passes the messages to LambdaLogger. This allows to avoid issues with exception stacktraces or other messages spanning across multiple lines.

This Appender ensures that Logback's MDC contains the AWSRequestId, which can be added to the log pattern.

Example XML configuration:

<configuration>

     <appender name="awslambda" class="org.jlib.cloud.aws.lambda.logback.AwsLambdaAppender">
         <encoder type="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
             <pattern>[%d{yyyy-MM-dd HH:mm:ss.SSS}] &lt;%-36X{AWSRequestId:-request-id-not-set-by-lambda-runtime}&gt; %-5level %logger{10} - %msg%n</pattern>
         </encoder>
     </appender>

     <root level="INFO">
         <appender-ref ref="awslambda" />
     </root>

 </configuration>
 
  • Field Summary

    Fields inherited from class ch.qos.logback.core.UnsynchronizedAppenderBase

    name, started

    Fields inherited from class ch.qos.logback.core.spi.ContextAwareBase

    context
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    append(ch.qos.logback.classic.spi.ILoggingEvent event)
     
    ch.qos.logback.core.encoder.Encoder<ch.qos.logback.classic.spi.ILoggingEvent>
     
    void
    setEncoder(ch.qos.logback.core.encoder.Encoder<ch.qos.logback.classic.spi.ILoggingEvent> encoder)
     

    Methods inherited from class ch.qos.logback.core.UnsynchronizedAppenderBase

    addFilter, buildReentryGuard, clearAllFilters, doAppend, getCopyOfAttachedFiltersList, getFilterChainDecision, getName, isStarted, setName, start, stop, toString

    Methods inherited from class ch.qos.logback.core.spi.ContextAwareBase

    addError, addError, addInfo, addInfo, addStatus, addWarn, addWarn, getContext, getDeclaredOrigin, getStatusManager, setContext

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

    Methods inherited from interface ch.qos.logback.core.spi.ContextAware

    addError, addError, addInfo, addInfo, addStatus, addWarn, addWarn, getContext, setContext
  • Constructor Details

    • AwsLambdaAppender

      public AwsLambdaAppender()
  • Method Details

    • append

      protected void append(ch.qos.logback.classic.spi.ILoggingEvent event)
      Specified by:
      append in class ch.qos.logback.core.UnsynchronizedAppenderBase<ch.qos.logback.classic.spi.ILoggingEvent>
    • getEncoder

      public ch.qos.logback.core.encoder.Encoder<ch.qos.logback.classic.spi.ILoggingEvent> getEncoder()
    • setEncoder

      public void setEncoder(ch.qos.logback.core.encoder.Encoder<ch.qos.logback.classic.spi.ILoggingEvent> encoder)