Tabnine Logo
LogEntry.newBuilder
Code IndexAdd Tabnine to your IDE (free)

How to use
newBuilder
method
in
com.google.cloud.logging.LogEntry

Best Java code snippets using com.google.cloud.logging.LogEntry.newBuilder (Showing top 20 results out of 315)

origin: googleapis/google-cloud-java

/** Creates a {@code LogEntry} object given the entry payload. */
public static LogEntry of(Payload<?> payload) {
 return newBuilder(payload).build();
}
origin: googleapis/google-cloud-java

/**
 * 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();
}
origin: googleapis/google-cloud-java

@Override
LogEntry parse(String... args) throws Exception {
 if (args.length >= 3) {
  if ((args.length & 0x1) != 0x1) {
   throw new IllegalArgumentException("Labels must be a list of key-value pairs.");
  }
  String logName = args[0];
  Severity severity = Severity.valueOf(args[1].toUpperCase());
  String message = args[2];
  Map<String, String> labels = Maps.newHashMapWithExpectedSize((args.length - 3) / 2);
  for (int i = 3; i < args.length; i += 2) {
   labels.put(args[i], args[i + 1]);
  }
  return LogEntry.newBuilder(StringPayload.of(message))
    .setLogName(logName)
    .setSeverity(severity)
    .setLabels(labels)
    .build();
 } else {
  throw new IllegalArgumentException("Missing required arguments.");
 }
}
origin: googleapis/google-cloud-java

private LogEntry logEntryFor(LogRecord record) throws Exception {
 String payload = getFormatter().format(record);
 Level level = record.getLevel();
 LogEntry.Builder builder =
   LogEntry.newBuilder(Payload.StringPayload.of(payload))
     .setTimestamp(record.getMillis())
     .setSeverity(severityFor(level));
 if (!baseLevel.equals(level)) {
  builder
    .addLabel("levelName", level.getName())
    .addLabel("levelValue", String.valueOf(level.intValue()));
 }
 for (LoggingEnhancer enhancer : enhancers) {
  enhancer.enhanceLogEntry(builder);
 }
 return builder.build();
}
origin: googleapis/google-cloud-java

private LogEntry logEntryFor(ILoggingEvent e) {
 StringBuilder payload = new StringBuilder(e.getFormattedMessage()).append('\n');
 writeStack(e.getThrowableProxy(), "", payload);
 Level level = e.getLevel();
 LogEntry.Builder builder =
   LogEntry.newBuilder(Payload.StringPayload.of(payload.toString().trim()))
     .setTimestamp(e.getTimeStamp())
     .setSeverity(severityFor(level));
 builder
   .addLabel(LEVEL_NAME_KEY, level.toString())
   .addLabel(LEVEL_VALUE_KEY, String.valueOf(level.toInt()));
 if (loggingEnhancers != null) {
  for (LoggingEnhancer enhancer : loggingEnhancers) {
   enhancer.enhanceLogEntry(builder);
  }
 }
 if (loggingEventEnhancers != null) {
  for (LoggingEventEnhancer enhancer : loggingEventEnhancers) {
   enhancer.enhanceLogEntry(builder, e);
  }
 }
 return builder.build();
}
origin: googleapis/google-cloud-java

 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);
   }
  }
 }
}
origin: googleapis/google-cloud-java

@Test
public void testFlushLevelConfigUpdatesLoggingFlushSeverity() {
 LogEntry logEntry =
   LogEntry.newBuilder(StringPayload.of("this is a test"))
     .setTimestamp(100000L)
     .setSeverity(Severity.WARNING)
     .setLabels(
       new ImmutableMap.Builder<String, String>()
         .put("levelName", "WARN")
         .put("levelValue", String.valueOf(30000L))
         .build())
     .build();
 logging.setFlushSeverity(Severity.WARNING);
 Capture<Iterable<LogEntry>> capturedArgument = Capture.newInstance();
 logging.write(capture(capturedArgument), (WriteOption) anyObject(), (WriteOption) anyObject());
 replay(logging);
 Timestamp timestamp = Timestamp.ofTimeSecondsAndNanos(100000, 0);
 LoggingEvent loggingEvent = createLoggingEvent(Level.WARN, timestamp.getSeconds());
 // error is the default, updating to warn for test
 loggingAppender.setFlushLevel(Level.WARN);
 loggingAppender.start();
 loggingAppender.doAppend(loggingEvent);
 verify(logging);
 assertThat(capturedArgument.getValue().iterator().hasNext()).isTrue();
 assertThat(capturedArgument.getValue().iterator().next()).isEqualTo(logEntry);
}
origin: googleapis/google-cloud-java

@Test
public void testEnhancersAddCorrectLabelsToLogEntries() {
 LogEntry logEntry =
   LogEntry.newBuilder(StringPayload.of("this is a test"))
     .setTimestamp(100000L)
     .setSeverity(Severity.WARNING)
     .setLabels(
       new ImmutableMap.Builder<String, String>()
         .put("levelName", "WARN")
         .put("levelValue", String.valueOf(30000L))
         .put("test-label-1", "test-value-1")
         .put("test-label-2", "test-value-2")
         .build())
     .build();
 logging.setFlushSeverity(Severity.ERROR);
 Capture<Iterable<LogEntry>> capturedArgument = Capture.newInstance();
 logging.write(capture(capturedArgument), (WriteOption) anyObject(), (WriteOption) anyObject());
 expectLastCall().once();
 replay(logging);
 loggingAppender.addEnhancer("com.example.enhancers.TestLoggingEnhancer");
 loggingAppender.addEnhancer("com.example.enhancers.AnotherTestLoggingEnhancer");
 loggingAppender.start();
 Timestamp timestamp = Timestamp.ofTimeSecondsAndNanos(100000, 0);
 LoggingEvent loggingEvent = createLoggingEvent(Level.WARN, timestamp.getSeconds());
 loggingAppender.doAppend(loggingEvent);
 verify(logging);
 assertThat(capturedArgument.getValue().iterator().hasNext()).isTrue();
 assertThat(capturedArgument.getValue().iterator().next()).isEqualTo(logEntry);
}
origin: googleapis/google-cloud-java

@Test
public void testFilterLogsOnlyLogsAtOrAboveLogLevel() {
 LogEntry logEntry =
   LogEntry.newBuilder(StringPayload.of("this is a test"))
     .setTimestamp(100000L)
     .setSeverity(Severity.ERROR)
origin: googleapis/google-cloud-java

@Test
public void testSyncWrite() {
 expect(options.getProjectId()).andReturn(PROJECT).anyTimes();
 expect(options.getService()).andReturn(logging);
 LogEntry entry =
   LogEntry.newBuilder(Payload.StringPayload.of(MESSAGE))
     .setSeverity(Severity.DEBUG)
     .addLabel("levelName", "FINEST")
     .addLabel("levelValue", String.valueOf(Level.FINEST.intValue()))
     .setTimestamp(123456789L)
     .build();
 logging.setFlushSeverity(Severity.ERROR);
 expectLastCall().once();
 logging.setWriteSynchronicity(Synchronicity.ASYNC);
 expectLastCall().once();
 logging.setWriteSynchronicity(Synchronicity.SYNC);
 expectLastCall().once();
 logging.write(ImmutableList.of(entry), DEFAULT_OPTIONS);
 expectLastCall().once();
 replay(options, logging);
 LoggingHandler handler = new LoggingHandler(LOG_NAME, options, DEFAULT_RESOURCE);
 handler.setLevel(Level.ALL);
 handler.setSynchronicity(Synchronicity.SYNC);
 handler.setFormatter(new TestFormatter());
 LogRecord record = new LogRecord(Level.FINEST, MESSAGE);
 record.setMillis(123456789L);
 handler.publish(record);
}
origin: googleapis/google-cloud-java

static LogEntry fromPb(com.google.logging.v2.LogEntry entryPb) {
 Builder builder = newBuilder(Payload.fromPb(entryPb));
 builder.setLabels(entryPb.getLabelsMap());
 builder.setSeverity(Severity.fromPb(entryPb.getSeverity()));
origin: googleapis/google-cloud-java

StringPayload firstPayload = StringPayload.of("stringPayload");
LogEntry firstEntry =
  LogEntry.newBuilder(firstPayload)
    .addLabel("key1", "value1")
    .setLogName(logId)
  JsonPayload.of(ImmutableMap.<String, Object>of("jsonKey", "jsonValue"));
LogEntry secondEntry =
  LogEntry.newBuilder(secondPayload)
    .addLabel("key2", "value2")
    .setLogName(logId)
origin: GoogleCloudPlatform/java-docs-samples

 /** 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);
 }
}
origin: com.google.cloud/google-cloud-logging

/** Creates a {@code LogEntry} object given the entry payload. */
public static LogEntry of(Payload<?> payload) {
 return newBuilder(payload).build();
}
origin: com.google.cloud/google-cloud-logging

/**
 * 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();
}
origin: googleapis/google-cloud-java

assertEquals(PROTO_PAYLOAD, PROTO_ENTRY.getPayload());
LogEntry logEntry =
  LogEntry.newBuilder(STRING_PAYLOAD)
    .setPayload(StringPayload.of("otherPayload"))
    .setLogName(LOG_NAME)
origin: com.google.cloud/google-cloud-logging

private LogEntry logEntryFor(LogRecord record) throws Exception {
 String payload = getFormatter().format(record);
 Level level = record.getLevel();
 LogEntry.Builder builder =
   LogEntry.newBuilder(Payload.StringPayload.of(payload))
     .setTimestamp(record.getMillis())
     .setSeverity(severityFor(level));
 if (!baseLevel.equals(level)) {
  builder
    .addLabel("levelName", level.getName())
    .addLabel("levelValue", String.valueOf(level.intValue()));
 }
 for (LoggingEnhancer enhancer : enhancers) {
  enhancer.enhanceLogEntry(builder);
 }
 return builder.build();
}
origin: com.google.cloud/google-cloud-logging-logback

private LogEntry logEntryFor(ILoggingEvent e) {
 StringBuilder payload = new StringBuilder(e.getFormattedMessage()).append('\n');
 writeStack(e.getThrowableProxy(), "", payload);
 Level level = e.getLevel();
 LogEntry.Builder builder =
   LogEntry.newBuilder(Payload.StringPayload.of(payload.toString().trim()))
     .setTimestamp(e.getTimeStamp())
     .setSeverity(severityFor(level));
 builder
   .addLabel(LEVEL_NAME_KEY, level.toString())
   .addLabel(LEVEL_VALUE_KEY, String.valueOf(level.toInt()));
 if (loggingEnhancers != null) {
  for (LoggingEnhancer enhancer : loggingEnhancers) {
   enhancer.enhanceLogEntry(builder);
  }
 }
 if (loggingEventEnhancers != null) {
  for (LoggingEventEnhancer enhancer : loggingEventEnhancers) {
   enhancer.enhanceLogEntry(builder, e);
  }
 }
 return builder.build();
}
origin: census-instrumentation/opencensus-java

private static LogEntry getEnhancedLogEntry(LoggingEnhancer loggingEnhancer, Span span) {
 Scope scope = tracer.withSpan(span);
 try {
  LogEntry.Builder builder = LogEntry.newBuilder(null);
  loggingEnhancer.enhanceLogEntry(builder);
  return builder.build();
 } finally {
  scope.close();
 }
}
origin: com.google.cloud/google-cloud-logging

static LogEntry fromPb(com.google.logging.v2.LogEntry entryPb) {
 Builder builder = newBuilder(Payload.fromPb(entryPb));
 builder.setLabels(entryPb.getLabelsMap());
 builder.setSeverity(Severity.fromPb(entryPb.getSeverity()));
com.google.cloud.loggingLogEntrynewBuilder

Javadoc

Returns a builder for LogEntry objects given the entry payload.

Popular methods of LogEntry

  • getSpanId
    Returns the ID of the trace span associated with the log entry, if any.
  • getTrace
    Returns the resource name of the trace associated with the log entry, if any. If it contains a relat
  • fromPb
  • getSeverity
    Returns the severity of the log entry. If not set, Severity#DEFAULT is used.
  • getTimestamp
    Returns the time at which the event described by the log entry occurred, in milliseconds. If omitted
  • getTraceSampled
    Returns the sampling decision of the trace span associated with the log entry, or falseif there is n
  • of
    Creates a LogEntry object given the log name, the monitored resource and the entry payload.
  • toBuilder
    Returns a Builder for this log entry.
  • toPb
  • toPbFunction
  • <init>
  • getHttpRequest
    Returns information about the HTTP request associated with this log entry, if applicable.
  • <init>,
  • getHttpRequest,
  • getInsertId,
  • getLabels,
  • getLocation,
  • getLogName,
  • getOperation,
  • getPayload,
  • getReceiveTimestamp

Popular in Java

  • Finding current android device location
  • getOriginalFilename (MultipartFile)
    Return the original filename in the client's filesystem.This may contain path information depending
  • getResourceAsStream (ClassLoader)
  • notifyDataSetChanged (ArrayAdapter)
  • Container (java.awt)
    A generic Abstract Window Toolkit(AWT) container object is a component that can contain other AWT co
  • File (java.io)
    An "abstract" representation of a file system entity identified by a pathname. The pathname may be a
  • URLConnection (java.net)
    A connection to a URL for reading or writing. For HTTP connections, see HttpURLConnection for docume
  • Charset (java.nio.charset)
    A charset is a named mapping between Unicode characters and byte sequences. Every Charset can decode
  • GregorianCalendar (java.util)
    GregorianCalendar is a concrete subclass of Calendarand provides the standard calendar used by most
  • IsNull (org.hamcrest.core)
    Is the value null?
  • Top Vim plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now