/** * Example of writing log entries and providing a default log name and monitored resource. Logging * writes are asynchronous by default. {@link Logging#setWriteSynchronicity(Synchronicity)} can be * used to update the synchronicity. */ // [TARGET write(Iterable, WriteOption...)] // [VARIABLE "my_log_name"] public void write(String logName) { // [START logging_write_log_entry] List<LogEntry> entries = new ArrayList<>(); entries.add(LogEntry.of(StringPayload.of("Entry payload"))); Map<String, Object> jsonMap = new HashMap<>(); jsonMap.put("key", "value"); entries.add(LogEntry.of(JsonPayload.of(jsonMap))); logging.write( entries, WriteOption.logName(logName), WriteOption.resource(MonitoredResource.newBuilder("global").build())); // [END logging_write_log_entry] }
.build(); JsonPayload secondPayload = JsonPayload.of(ImmutableMap.<String, Object>of("jsonKey", "jsonValue")); LogEntry secondEntry = LogEntry.newBuilder(secondPayload)
super.setPayload(JsonPayload.of(map));
static JsonPayload fromPb(com.google.logging.v2.LogEntry entryPb) { return JsonPayload.of(entryPb.getJsonPayload()); } }
@Test public void testOf() { assertEquals(Type.STRING, STRING_PAYLOAD.getType()); assertEquals(STRING_DATA, STRING_PAYLOAD.getData()); assertEquals(Type.JSON, JSON_PAYLOAD.getType()); assertEquals(STRUCT_DATA, JSON_PAYLOAD.getData()); assertEquals(JSON_DATA, JSON_PAYLOAD.getDataAsMap()); assertEquals(Type.PROTO, PROTO_PAYLOAD.getType()); assertEquals(PROTO_DATA, PROTO_PAYLOAD.getData()); JsonPayload jsonPayload = JsonPayload.of(STRUCT_DATA); assertEquals(Type.JSON, jsonPayload.getType()); assertEquals(STRUCT_DATA, jsonPayload.getData()); assertEquals(JSON_DATA, jsonPayload.getDataAsMap()); }
static JsonPayload fromPb(com.google.logging.v2.LogEntry entryPb) { return JsonPayload.of(entryPb.getJsonPayload()); } }