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 > LoggingAppenderConstructors
LoggingAppender()
public LoggingAppender()
Methods
addEnhancer(String enhancerClassName)
public void addEnhancer(String enhancerClassName)
Add extra labels using classes that implement LoggingEnhancer.
Name | Description |
enhancerClassName | String |
addLoggingEventEnhancer(String enhancerClassName)
public void addLoggingEventEnhancer(String enhancerClassName)
Name | Description |
enhancerClassName | String |
append(ILoggingEvent e)
protected void append(ILoggingEvent e)
Name | Description |
e | ch.qos.logback.classic.spi.ILoggingEvent |
flush()
public void flush()
Flushes any pending asynchronous logging writes.
getLoggingOptions()
protected LoggingOptions getLoggingOptions()
Gets the LoggingOptions to use for this LoggingAppender.
Type | Description |
com.google.cloud.logging.LoggingOptions |
getWriteSynchronicity()
public Synchronicity getWriteSynchronicity()
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.
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.
Name | Description |
flushLevel | ch.qos.logback.classic.Level Logback log level |
setLog(String log)
public void setLog(String log)
Sets the log filename.
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"
Name | Description |
resourceType | String name of the monitored resource |
setWriteSynchronicity(Synchronicity flag)
public void setWriteSynchronicity(Synchronicity flag)
Define synchronization mode for writing log entries.
Name | Description |
flag | com.google.cloud.logging.Synchronicity to set |
start()
public synchronized void start()
Initialize and configure the cloud logging service.
stop()
public synchronized void stop()