Skip to content

Instantly share code, notes, and snippets.

@minherz
Created January 20, 2022 14:42
Show Gist options
  • Save minherz/2b06fd94336fd27a77414e2a6d296c12 to your computer and use it in GitHub Desktop.
Save minherz/2b06fd94336fd27a77414e2a6d296c12 to your computer and use it in GitHub Desktop.
<?xml version='1.0' encoding='UTF-8'?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.google.cloud</groupId>
<artifactId>examples-testbed-local</artifactId>
<packaging>jar</packaging>
<version>1.0.0</version>
<name>Test Local Environment Examples</name>
<!--
The parent pom defines common style checks and testing strategies for our samples.
Removing or replacing it should not affect the execution of the samples in anyway.
-->
<!-- <parent>
<groupId>com.google.cloud.samples</groupId>
<artifactId>shared-configuration</artifactId>
<version>1.0.23</version>
</parent> -->
<properties>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<!-- [START logging_install_with_bom] -->
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>libraries-bom</artifactId>
<version>24.2.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-logging</artifactId>
<version>3.6.1</version>
</dependency>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-logging-logback</artifactId>
<version>0.123.0-alpha</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.6</version>
</dependency>
</dependencies>
</project>
package com.example.logging;
import java.io.IOException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import io.grpc.Context.CancellableContext;
public class TestLogback {
private static final Logger logger =
LoggerFactory.getLogger(TestLogback.class.getName());
private static void runCancelled(Runnable runnable){
CancellableContext withCancellation = io.grpc.Context.current().withCancellation();
withCancellation.run(() -> {
withCancellation.cancel(new RuntimeException("Test cancel"));
runnable.run();
});
}
public static void main(String[] args) throws IOException {
System.out.println("STARTING the test of async context cancelation.....");
runCancelled(() -> {
logger.info("Send me within cancellable context");
});
System.out.println("ENDING the test.....");
}
}
<configuration>
<appender name="CLOUD" class="com.google.cloud.logging.logback.LoggingAppender">
</appender>
<root level="info">
<appender-ref ref="CLOUD" />
</root>
</configuration>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment