/
.readme-partials.yaml
47 lines (39 loc) · 1.64 KB
/
.readme-partials.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
custom_content: |
### Usage
Add the appender to your [Logback configuration](https://logback.qos.ch/manual/configuration.html) `logback.xml`.
See [Logback filters](https://logback.qos.ch/manual/filters.html#thresholdFilter) for information on filtering log output and
[encoders](https://logback.qos.ch/manual/encoders.html) for information on formatting.
```xml
<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 :
```java
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");
}
}
```