Skip to content
This repository has been archived by the owner on Nov 17, 2024. It is now read-only.

cdapio/java-logging-logback

 
 

Repository files navigation

Logback Appender for Google Cloud Logging

Logback appender com.google.cloud.logging.logback.LoggingAppender for Google Cloud Logging.

This library allows you to use Logback configuration and the Slf4j interface to log via Google Cloud logging.

Note: This client is a work-in-progress, and may occasionally make backwards-incompatible changes.

Quickstart

If you are using Maven with a BOM, add this to your pom.xml file.

<dependencyManagement>
 <dependencies>
  <dependency>
    <groupId>com.google.cloud</groupId>
    <artifactId>libraries-bom</artifactId>
    <version>3.0.0</version>
    <type>pom</type>
    <scope>import</scope>
   </dependency>
 </dependencies>
</dependencyManagement>

<dependency>
  <groupId>com.google.cloud</groupId>
  <artifactId>google-cloud-logging-logback</artifactId>
</dependency>

If you are using Maven without a BOM, add this to your dependencies.

<dependency>
  <groupId>com.google.cloud</groupId>
  <artifactId>google-cloud-logging-logback</artifactId>
  <version>0.116.0-alpha</version>
</dependency>

If you are using Gradle, add this to your dependencies

compile 'com.google.cloud:google-cloud-logging-logback:0.116.0-alpha'

If you are using SBT, add this to your dependencies

libraryDependencies += "com.google.cloud" % "google-cloud-logging-logback" % "0.116.0-alpha"

Usage

Add the appender to your Logback configuration logback.xml. See Logback filters for information on filtering log output and encoders for information on formatting.

<configuration>
  <appender name="CLOUD" class="com.google.cloud.logging.logback.LoggingAppender">
    <!-- Optional : filter logs at or above a level -->
    <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
      <level>INFO</level>
    </filter>
    <log>application.log</log> <!-- Optional : default java.log -->
    <!-- Optional : will use the default credentials of the environment if this property is not set -->
    <credentialsFile>/path/to/credentials.json</credentialsFile>
    <enhancer>com.example.enhancers.TestLoggingEnhancer</enhancer> <!-- Optional -->
    <enhancer>com.example.enhancers.AnotherEnhancer</enhancer> <!-- Optional -->
    <flushLevel>WARN</flushLevel> <!-- Optional : default ERROR -->
  </appender>

  <root level="info">
    <appender-ref ref="CLOUD" />
  </root>
</configuration>

In your code :

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
 
public class TestLogger {
    private final Logger logger = LoggerFactory.getLogger(TestLogger.class);
 
    public void log(String name) {
        logger.info("This is a test");
    }

    public static void main(String[] args) {
        TestLogger testLogger = new TestLogger();
        testLogger.log("test");
    }
}

Authentication

See the Authentication section in the base directory's README.

You can also specify custom credentials by setting the optional property credentialsFile in your configuration file.

Limitations

This library is usable, but not yet complete. Open issues here.

Java Versions

Java 7 or above is required for using this client.

Versioning

This library follows Semantic Versioning.

It is currently in major version zero (0.y.z), which means that anything may change at any time and the public API should not be considered stable.

Contributing

Contributions to this library are always welcome and highly encouraged.

See google-cloud's CONTRIBUTING documentation and the shared documentation for more information on how to get started.

Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms. See Code of Conduct for more information.

License

Apache 2.0 - See LICENSE for more information.

About

No description, website, or topics provided.

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 64.9%
  • Shell 33.2%
  • Python 1.6%
  • Batchfile 0.3%