-
Notifications
You must be signed in to change notification settings - Fork 0
/
cloud_logging.sc
40 lines (32 loc) · 1.21 KB
/
cloud_logging.sc
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
import $ivy.`com.google.cloud:google-cloud-logging:1.66.0`
import com.google.cloud.MonitoredResource;
import scala.collection.JavaConverters._
import com.google.cloud.logging.LogEntry;
import com.google.cloud.logging.Logging;
import com.google.cloud.logging.LoggingOptions;
import com.google.cloud.logging.Payload.JsonPayload;
import com.google.cloud.logging.Severity;
import java.util.Collections;
// Instantiates a client
val logging = LoggingOptions.getDefaultInstance().getService();
// The name of the log to write to
val logName = "my-log";
// The data to write to the log
val text = "Hello, world!";
val entry = LogEntry.newBuilder(JsonPayload.of(Map("entry" -> text).asJava))
.setSeverity(Severity.ERROR)
.setLogName(logName)
//.setResource(MonitoredResource.newBuilder("global").build())
.setResource(MonitoredResource.of("generic_task",
Map(
"project_id" -> "broad-dsde-cromwell-dev",
"location" -> "us-east4-c",
"namespace" -> "danb-test-namespace",
"job" -> "danb-test-logging",
"task-id" -> "2"
).asJava
))
.build();
// Writes the log entry asynchronously
logging.write(Collections.singleton(entry));
System.out.printf("Logged: %s%n", text);