Skip to content

Commit c7e035c

Browse files
jabubakechingor13
authored andcommitted
Stackdriver logging samples (JUL, Logback, Client library) (#826)
1 parent 7fe10fe commit c7e035c

File tree

3 files changed

+94
-0
lines changed

3 files changed

+94
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
Copyright 2017 Google Inc.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package com.example.logging.logback;
18+
19+
// [START logback_quickstart]
20+
import org.slf4j.Logger;
21+
import org.slf4j.LoggerFactory;
22+
23+
public class Quickstart {
24+
private static final Logger logger = LoggerFactory.getLogger(Quickstart.class);
25+
26+
public static void main(String[] args) {
27+
logger.info("Logging INFO with Logback");
28+
logger.error("Logging ERROR with Logback");
29+
}
30+
}
31+
// [END logback_quickstart]
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright 2017 Google Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.example.logging.logback.enhancers;
18+
// [START logging_enhancer]
19+
import com.google.cloud.logging.LogEntry;
20+
import com.google.cloud.logging.LoggingEnhancer;
21+
22+
// Add / update additional fields to the log entry
23+
public class ExampleEnhancer implements LoggingEnhancer {
24+
25+
@Override
26+
public void enhanceLogEntry(LogEntry.Builder logEntry) {
27+
// add additional labels
28+
logEntry.addLabel("test-label-1", "test-value-1");
29+
}
30+
}
31+
// [END logging_enhancer]
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<!--
2+
Copyright 2017 Google Inc.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
-->
16+
<!-- [START logback_config] -->
17+
<configuration>
18+
<appender name="CLOUD" class="com.google.cloud.logging.logback.LoggingAppender">
19+
<!-- Optional : filter logs at or above a level -->
20+
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
21+
<level>INFO</level>
22+
</filter>
23+
<log>application.log</log> <!-- Optional : default java.log -->
24+
<enhancer>com.example.logging.logback.enhancers.ExampleEnhancer</enhancer> <!-- Optional -->
25+
<flushLevel>WARN</flushLevel> <!-- Optional : default ERROR -->
26+
</appender>
27+
28+
<root level="info">
29+
<appender-ref ref="CLOUD" />
30+
</root>
31+
</configuration>
32+
<!-- [END logback_config] -->

0 commit comments

Comments
 (0)