Class LoggingAppender

public class LoggingAppender extends UnsynchronizedAppenderBase<ILoggingEvent>

Logback appender for Google Cloud Logging.

Appender configuration in logback.xml:

    <appender name="CLOUD" class="com.google.cloud.logging.logback.LoggingAppender">
         <!-- Optional: filter logs at and above this level -->
         <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
             <level>INFO</level>
         </filter>

         <!-- Optional: defaults to "java.log" -->
         <log>application.log</log>

         <!-- Optional: defaults to "ERROR" -->
         <flushLevel>WARNING</flushLevel>

         <!-- Optional: defaults to ASYNC -->
         <writeSynchronicity>SYNC</writeSynchronicity>

         <!-- Optional: auto detects on App Engine Flex, Standard, GCE and GKE, defaults to "global". See supported resource types -->
         <resourceType></resourceType>

         <!-- Optional: defaults to the default credentials of the environment -->
         <credentialsFile>/path/to/credentials/file</credentialsFile>

         <!-- Optional: add custom labels to log entries using LoggingEnhancer classes -->
         <enhancer>com.example.enhancers.TestLoggingEnhancer</enhancer>
         <enhancer>com.example.enhancers.AnotherEnhancer</enhancer>
     </appender>
 

Inheritance

java.lang.Object > ch.qos.logback.core.spi.ContextAwareBase > ch.qos.logback.core.UnsynchronizedAppenderBase > LoggingAppender

Constructors

LoggingAppender()

public LoggingAppender()

Methods

addEnhancer(String enhancerClassName)

public void addEnhancer(String enhancerClassName)

Add extra labels using classes that implement LoggingEnhancer.

Parameter
Name Description
enhancerClassName String

addLoggingEventEnhancer(String enhancerClassName)

public void addLoggingEventEnhancer(String enhancerClassName)
Parameter
Name Description
enhancerClassName String

append(ILoggingEvent e)

protected void append(ILoggingEvent e)
Parameter
Name Description
e ch.qos.logback.classic.spi.ILoggingEvent
Overrides
ch.qos.logback.core.UnsynchronizedAppenderBase.append(E)

flush()

public void flush()

Flushes any pending asynchronous logging writes.

getLoggingOptions()

protected LoggingOptions getLoggingOptions()

Gets the LoggingOptions to use for this LoggingAppender.

Returns
Type Description
com.google.cloud.logging.LoggingOptions

getWriteSynchronicity()

public Synchronicity getWriteSynchronicity()
Returns
Type Description
com.google.cloud.logging.Synchronicity

setCredentialsFile(String credentialsFile)

public void setCredentialsFile(String credentialsFile)

Sets the credentials file to use to create the LoggingOptions. The credentials returned by GoogleCredentials#getApplicationDefault() will be used if no custom credentials file has been set.

Parameter
Name Description
credentialsFile String

The credentials file to use.

setFlushLevel(Level flushLevel)

public void setFlushLevel(Level flushLevel)

Batched logging requests get immediately flushed for logs at or above this level.

Defaults to Error if not set.

Parameter
Name Description
flushLevel ch.qos.logback.classic.Level

Logback log level

setLog(String log)

public void setLog(String log)

Sets the log filename.

Parameter
Name Description
log String

filename

setResourceType(String resourceType)

public void setResourceType(String resourceType)

Sets the name of the monitored resource (Optional).

Must be a supported resource type. gae_app, gce_instance and container are auto-detected.

Defaults to "global"

Parameter
Name Description
resourceType String

name of the monitored resource

setWriteSynchronicity(Synchronicity flag)

public void setWriteSynchronicity(Synchronicity flag)

Define synchronization mode for writing log entries.

Parameter
Name Description
flag com.google.cloud.logging.Synchronicity

to set Synchronicity value.

start()

public synchronized void start()

Initialize and configure the cloud logging service.

Overrides
ch.qos.logback.core.UnsynchronizedAppenderBase.start()

stop()

public synchronized void stop()
Overrides
ch.qos.logback.core.UnsynchronizedAppenderBase.stop()