@Override public void run(Logging logging, LogEntry entry) { MonitoredResource resource = MonitoredResource.newBuilder("global") .addLabel("project_id", logging.getOptions().getProjectId()) .build(); LogEntry entryWithResource = entry.toBuilder().setResource(resource).build(); logging.write(Collections.singleton(entryWithResource)); System.out.printf("Written entry %s%n", entryWithResource); }
public static void main(String... args) throws Exception { // Create a service object // Credentials are inferred from the environment LoggingOptions options = LoggingOptions.getDefaultInstance(); try (Logging logging = options.getService()) { // Create a log entry LogEntry firstEntry = LogEntry.newBuilder(StringPayload.of("message")) .setLogName("test-log") .setResource( MonitoredResource.newBuilder("global") .addLabel("project_id", options.getProjectId()) .build()) .build(); logging.write(Collections.singleton(firstEntry)); // List log entries Page<LogEntry> entries = logging.listLogEntries( EntryListOption.filter( "logName=projects/" + options.getProjectId() + "/logs/test-log")); for (LogEntry logEntry : entries.iterateAll()) { System.out.println(logEntry); } } } }
.setLogName(logId) .setHttpRequest(HttpRequest.newBuilder().setStatus(500).build()) .setResource(MonitoredResource.newBuilder("global").build()) .build(); JsonPayload secondPayload = .setLogName(logId) .setOperation(Operation.of("operationId", "operationProducer")) .setResource(MonitoredResource.newBuilder("cloudsql_database").build()) .build(); logging().write(ImmutableList.of(firstEntry));
builder.setResource(MonitoredResource.fromPb(entryPb.getResource()));
/** * Creates a {@code LogEntry} object given the log name, the monitored resource and the entry * payload. */ public static LogEntry of(String logName, MonitoredResource resource, Payload<?> payload) { return newBuilder(payload).setLogName(logName).setResource(resource).build(); }
/** Expects a new or existing Stackdriver log name as the first argument.*/ public static void main(String... args) throws Exception { // Instantiates a client Logging logging = LoggingOptions.getDefaultInstance().getService(); // The name of the log to write to String logName = args[0]; // "my-log"; // The data to write to the log String text = "Hello, world!"; LogEntry entry = LogEntry.newBuilder(StringPayload.of(text)) .setSeverity(Severity.ERROR) .setLogName(logName) .setResource(MonitoredResource.newBuilder("global").build()) .build(); // Writes the log entry asynchronously logging.write(Collections.singleton(entry)); System.out.printf("Logged: %s%n", text); } }
.setPayload(StringPayload.of("otherPayload")) .setLogName(LOG_NAME) .setResource(RESOURCE) .setTimestamp(TIMESTAMP) .setReceiveTimestamp(RECEIVE_TIMESTAMP)
.setPayload(StringPayload.of("otherPayload")) .setLogName("otherLogName") .setResource(MonitoredResource.newBuilder("global").build()) .setTimestamp(43) .setReceiveTimestamp(34) .setPayload(STRING_PAYLOAD) .setLogName(LOG_NAME) .setResource(RESOURCE) .setTimestamp(TIMESTAMP) .setReceiveTimestamp(RECEIVE_TIMESTAMP)
builder.setResource(MonitoredResource.fromPb(entryPb.getResource()));
/** * Creates a {@code LogEntry} object given the log name, the monitored resource and the entry * payload. */ public static LogEntry of(String logName, MonitoredResource resource, Payload<?> payload) { return newBuilder(payload).setLogName(logName).setResource(resource).build(); }