public class LoggingAppender
extends ch.qos.logback.core.UnsynchronizedAppenderBase<ch.qos.logback.classic.spi.ILoggingEvent>
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: 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>
| Constructor and Description |
|---|
LoggingAppender() |
| Modifier and Type | Method and Description |
|---|---|
void |
addEnhancer(String enhancerClassName)
Add extra labels using classes that implement
LoggingEnhancer. |
void |
addLoggingEventEnhancer(String enhancerClassName) |
protected void |
append(ch.qos.logback.classic.spi.ILoggingEvent e) |
void |
flush()
Flushes any pending asynchronous logging writes.
|
protected com.google.cloud.logging.LoggingOptions |
getLoggingOptions()
Gets the
LoggingOptions to use for this LoggingAppender. |
void |
setCredentialsFile(String credentialsFile)
Sets the credentials file to use to create the
LoggingOptions. |
void |
setFlushLevel(ch.qos.logback.classic.Level flushLevel)
Batched logging requests get immediately flushed for logs at or above this level.
|
void |
setLog(String log)
Sets the log filename.
|
void |
setResourceType(String resourceType)
Sets the name of the monitored resource (Optional).
|
void |
start()
Initialize and configure the cloud logging service.
|
void |
stop() |
addFilter, clearAllFilters, doAppend, getCopyOfAttachedFiltersList, getFilterChainDecision, getName, isStarted, setName, toStringaddError, addError, addInfo, addInfo, addStatus, addWarn, addWarn, getContext, getDeclaredOrigin, getStatusManager, setContextpublic void setFlushLevel(ch.qos.logback.classic.Level flushLevel)
Defaults to Error if not set.
flushLevel - Logback log levelpublic void setLog(String log)
log - filenamepublic void setResourceType(String resourceType)
Must be a supported resource type. gae_app, gce_instance and container are auto-detected.
Defaults to "global"
resourceType - name of the monitored resourcepublic void setCredentialsFile(String credentialsFile)
LoggingOptions. The credentials returned
by GoogleCredentials.getApplicationDefault() will be used if no custom credentials file
has been set.credentialsFile - The credentials file to use.public void addEnhancer(String enhancerClassName)
LoggingEnhancer.public void addLoggingEventEnhancer(String enhancerClassName)
public void start()
start in interface ch.qos.logback.core.spi.LifeCyclestart in class ch.qos.logback.core.UnsynchronizedAppenderBase<ch.qos.logback.classic.spi.ILoggingEvent>protected void append(ch.qos.logback.classic.spi.ILoggingEvent e)
append in class ch.qos.logback.core.UnsynchronizedAppenderBase<ch.qos.logback.classic.spi.ILoggingEvent>public void stop()
stop in interface ch.qos.logback.core.spi.LifeCyclestop in class ch.qos.logback.core.UnsynchronizedAppenderBase<ch.qos.logback.classic.spi.ILoggingEvent>public void flush()
protected com.google.cloud.logging.LoggingOptions getLoggingOptions()
LoggingOptions to use for this LoggingAppender.Copyright © 2020 Google LLC. All rights reserved.