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
NameDescription
enhancerClassNameString

addLoggingEventEnhancer(String enhancerClassName)

public void addLoggingEventEnhancer(String enhancerClassName)
Parameter
NameDescription
enhancerClassNameString

append(ILoggingEvent e)

protected void append(ILoggingEvent e)
Parameter
NameDescription
ech.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
TypeDescription
com.google.cloud.logging.LoggingOptions

getWriteSynchronicity()

public Synchronicity getWriteSynchronicity()
Returns
TypeDescription
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
NameDescription
credentialsFileString

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
NameDescription
flushLevelch.qos.logback.classic.Level

Logback log level

setLog(String log)

public void setLog(String log)

Sets the log filename.

Parameter
NameDescription
logString

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
NameDescription
resourceTypeString

name of the monitored resource

setWriteSynchronicity(Synchronicity flag)

public void setWriteSynchronicity(Synchronicity flag)

Define synchronization mode for writing log entries.

Parameter
NameDescription
flagcom.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()