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: defaults to ASYNC -->
<writeSynchronicity>SYNC</writeSynchronicity>
<!-- Optional: defaults to true -->
<autoPopulateMetadata>false</autoPopulateMetadata>
<!-- Optional: defaults to false -->
<redirectToStdout>true</redirectToStdout>
<!-- 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: defaults to the project id obtained during authentication process. Project id is also used to construct resource name of the log entries -->
<logDestinationProjectId>String</logDestinationProjectId>
<!-- Optional: add custom labels to log entries using LoggingEnhancer classes -->
<enhancer>com.example.enhancers.TestLoggingEnhancer</enhancer>
<enhancer>com.example.enhancers.AnotherEnhancer</enhancer>
</appender>
| Modifier and Type | Field and Description |
|---|---|
static String |
JAVA_LOGBACK_LIBRARY_NAME |
| 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()
Deprecated.
|
protected com.google.cloud.logging.LoggingOptions |
getLoggingOptions()
Gets the
LoggingOptions to use for this LoggingAppender. |
com.google.cloud.logging.Synchronicity |
getWriteSynchronicity()
Deprecated.
|
void |
setAutoPopulateMetadata(boolean flag)
Sets the automatic population of metadata fields for ingested logs.
|
void |
setCredentialsFile(String credentialsFile)
Sets the path to the https://cloud.google.com/iam/docs/creating-managing-service-account-keys.
|
void |
setFlushLevel(ch.qos.logback.classic.Level flushLevel)
Sets a threshold for log severity level to flush all log entries that were batched so far.
|
void |
setLog(String log)
Sets the LOG_ID part of the https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#FIELDS.log_name
for which the logs are ingested.
|
void |
setLogDestinationProjectId(String projectId)
Sets project ID to be used to customize log destination name for written log entries.
|
void |
setRedirectToStdout(boolean flag)
Sets the redirect of the appender's output to STDOUT instead of ingesting logs to Cloud Logging
using Logging API.
|
void |
setResourceType(String resourceType)
Sets the name of the monitored resource (Optional).
|
void |
setWriteSynchronicity(com.google.cloud.logging.Synchronicity flag)
Sets the log ingestion mode.
|
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 static final String JAVA_LOGBACK_LIBRARY_NAME
public void setFlushLevel(ch.qos.logback.classic.Level flushLevel)
Defaults to Error.
flushLevel - Logback log levelpublic void setLog(String log)
log - LOG_ID part of the namepublic void setResourceType(String resourceType)
Must be a one of the supported resource types.
resourceType - the name of the monitored resource.public void setCredentialsFile(String credentialsFile)
GoogleCredentials.getApplicationDefault() to authenticate.credentialsFile - the path to the credentials file.public void setLogDestinationProjectId(String projectId)
projectId - The project ID to be used to construct the resource destination name for log
entries.public void setWriteSynchronicity(com.google.cloud.logging.Synchronicity flag)
Synchronicity values.
Default to Synchronicity.ASYNC
flag - the new ingestion mode.public void setAutoPopulateMetadata(boolean flag)
Default to true.
flag - the metadata auto-population flag.public void setRedirectToStdout(boolean flag)
Default to false.
flag - the redirect flag.public void addEnhancer(String enhancerClassName)
LoggingEnhancer.public void addLoggingEventEnhancer(String enhancerClassName)
@Deprecated public com.google.cloud.logging.Synchronicity getWriteSynchronicity()
The method is deprecated. Use appender configuration to setup the ingestion
Synchronicity value of the ingestion module.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>@Deprecated public void flush()
protected com.google.cloud.logging.LoggingOptions getLoggingOptions()
LoggingOptions to use for this LoggingAppender.Copyright © 2022 Google LLC. All rights reserved.