Skip to content

Commit 5a11507

Browse files
authored
Cloud logging logback appender (#2045)
Logback support for google-cloud-logging
1 parent 084830c commit 5a11507

File tree

6 files changed

+687
-0
lines changed

6 files changed

+687
-0
lines changed
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
Logback Appender for Google Cloud Logging
2+
=========================================
3+
4+
Logback appender `com.google.cloud.logging.logback.LoggingAppender` for
5+
[Google Cloud Logging](https://cloud.google.com/logging/).
6+
7+
This library allows you to use [Logback](https://logback.qos.ch/) configuration and the [Slf4j](https://www.slf4j.org/) interface to log via Google Cloud logging.
8+
9+
- [Homepage](https://googlecloudplatform.github.io/google-cloud-java/)
10+
- [API Documentation](https://googlecloudplatform.github.io/google-cloud-java/apidocs/index.html?com/google/cloud/logging/logback/LoggingAppender.html)
11+
12+
> Note: This client is a work-in-progress, and may occasionally
13+
> make backwards-incompatible changes.
14+
15+
Quickstart
16+
----------
17+
If you are using Maven, add this to your pom.xml file
18+
```xml
19+
<dependency>
20+
<groupId>com.google.cloud</groupId>
21+
<artifactId>google-cloud-logging-logback</artifactId>
22+
<version>0.18.0-alpha</version>
23+
</dependency>
24+
```
25+
If you are using Gradle, add this to your dependencies
26+
```Groovy
27+
compile 'com.google.cloud:google-cloud-logging-logback:0.18.0-alpha'
28+
```
29+
If you are using SBT, add this to your dependencies
30+
```Scala
31+
libraryDependencies += "com.google.cloud" % "google-cloud-logging-logback" % "0.18.0-alpha"
32+
```
33+
34+
Usage
35+
-----
36+
37+
Add the appender to your [Logback configuration](https://logback.qos.ch/manual/configuration.html) `logback.xml`.
38+
See [Logback filters](https://logback.qos.ch/manual/filters.html#thresholdFilter) for information on filtering log output and
39+
[encoders](https://logback.qos.ch/manual/encoders.html) for information on formatting.
40+
41+
42+
```xml
43+
<configuration>
44+
<appender name="CLOUD" class="com.google.cloud.logging.logback.LoggingAppender">
45+
<!-- Optional : filter logs at or above a level -->
46+
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
47+
<level>INFO</level>
48+
</filter>
49+
<log>application.log</log> <!-- Optional : default java.log -->
50+
<enhancer>com.example.enhancers.TestLoggingEnhancer</enhancer> <!-- Optional -->
51+
<enhancer>com.example.enhancers.AnotherEnhancer</enhancer> <!-- Optional -->
52+
<flushLevel>WARN</flushLevel> <!-- Optional : default ERROR -->
53+
</appender>
54+
55+
<root level="info">
56+
<appender-ref ref="CLOUD" />
57+
</root>
58+
</configuration>
59+
```
60+
61+
In your code :
62+
63+
```java
64+
import org.slf4j.Logger;
65+
import org.slf4j.LoggerFactory;
66+
67+
public class TestLogger {
68+
private final Logger logger = LoggerFactory.getLogger(TestLogger.class);
69+
70+
public void log(String name) {
71+
logger.info("This is a test");
72+
}
73+
74+
public static void main(String[] args) {
75+
TestLogger testLogger = new TestLogger();
76+
testLogger.log("test");
77+
}
78+
}
79+
```
80+
81+
82+
Authentication
83+
--------------
84+
85+
See the [Authentication](https://github.com/GoogleCloudPlatform/google-cloud-java#authentication)
86+
section in the base directory's README.
87+
88+
89+
Limitations
90+
-----------
91+
92+
This library is usable, but not yet complete.
93+
Open issues [here](https://github.com/GoogleCloudPlatform/google-cloud-java/issues?q=is%3Aissue+is%3Aopen+label%3A%22logging-logback%22).
94+
95+
96+
Java Versions
97+
-------------
98+
99+
Java 7 or above is required for using this client.
100+
101+
Versioning
102+
----------
103+
104+
This library follows [Semantic Versioning](http://semver.org/).
105+
106+
It is currently in major version zero (``0.y.z``), which means that anything
107+
may change at any time and the public API should not be considered
108+
stable.
109+
110+
Contributing
111+
------------
112+
113+
Contributions to this library are always welcome and highly encouraged.
114+
115+
See `google-cloud`'s [CONTRIBUTING] documentation and the
116+
[shared documentation](https://github.com/GoogleCloudPlatform/gcloud-common/blob/master/contributing/readme.md#how-to-contribute-to-gcloud)
117+
for more information on how to get started.
118+
119+
Please note that this project is released with a Contributor Code of Conduct.
120+
By participating in this project you agree to abide by its terms. See
121+
[Code of Conduct][code-of-conduct] for more information.
122+
123+
License
124+
-------
125+
Apache 2.0 - See [LICENSE] for more information.
126+
127+
128+
[CONTRIBUTING]:https://github.com/GoogleCloudPlatform/google-cloud-java/blob/master/CONTRIBUTING.md
129+
[code-of-conduct]:https://github.com/GoogleCloudPlatform/google-cloud-java/blob/master/CODE_OF_CONDUCT.md#contributor-code-of-conduct
130+
[LICENSE]: https://github.com/GoogleCloudPlatform/google-cloud-java/blob/master/LICENSE
131+
[TESTING]: https://github.com/GoogleCloudPlatform/google-cloud-java/blob/master/TESTING.md#testing-code-that-uses-storage
132+
[cloud-platform]: https://cloud.google.com/
133+
134+
[cloud-logging]: https://cloud.google.com/logging/
135+
[cloud-logging-docs]: https://cloud.google.com/logging/docs/overview
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<artifactId>google-cloud-logging-logback</artifactId>
8+
<version>0.18.1-alpha-SNAPSHOT</version>
9+
<packaging>jar</packaging>
10+
<name>Google Cloud Logging Logback Appender</name>
11+
<url>https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-contrib/google-cloud-logging-logback</url>
12+
<description>
13+
Logback support for Google Cloud Logging
14+
</description>
15+
16+
<properties>
17+
<logback.version>1.2.3</logback.version>
18+
</properties>
19+
20+
<parent>
21+
<groupId>com.google.cloud</groupId>
22+
<artifactId>google-cloud-contrib</artifactId>
23+
<version>0.18.1-alpha-SNAPSHOT</version>
24+
</parent>
25+
<dependencies>
26+
<dependency>
27+
<groupId>ch.qos.logback</groupId>
28+
<artifactId>logback-classic</artifactId>
29+
<version>${logback.version}</version>
30+
</dependency>
31+
<dependency>
32+
<groupId>com.google.cloud</groupId>
33+
<artifactId>google-cloud-logging</artifactId>
34+
</dependency>
35+
<!-- Test dependencies -->
36+
<dependency>
37+
<groupId>org.easymock</groupId>
38+
<artifactId>easymock</artifactId>
39+
<version>3.4</version>
40+
<scope>test</scope>
41+
</dependency>
42+
<dependency>
43+
<groupId>junit</groupId>
44+
<artifactId>junit</artifactId>
45+
<version>4.12</version>
46+
<scope>test</scope>
47+
</dependency>
48+
</dependencies>
49+
</project>

0 commit comments

Comments
 (0)