Search in sources :

Example 1 with LoggingEnhancer

use of com.google.cloud.logging.LoggingEnhancer in project google-cloud-java by GoogleCloudPlatform.

the class LoggingAppender method start.

/**
   * Initialize and configure the cloud logging service.
   */
@Override
public synchronized void start() {
    if (isStarted()) {
        return;
    }
    MonitoredResource resource = getMonitoredResource(getProjectId());
    defaultWriteOptions = new WriteOption[] { WriteOption.logName(getLogName()), WriteOption.resource(resource) };
    getLogging().setFlushSeverity(severityFor(getFlushLevel()));
    loggingEnhancers = new ArrayList<>();
    List<LoggingEnhancer> resourceEnhancers = MonitoredResourceUtil.getResourceEnhancers();
    loggingEnhancers.addAll(resourceEnhancers);
    loggingEnhancers.addAll(getLoggingEnhancers());
    super.start();
}
Also used : LoggingEnhancer(com.google.cloud.logging.LoggingEnhancer) MonitoredResource(com.google.cloud.MonitoredResource)

Example 2 with LoggingEnhancer

use of com.google.cloud.logging.LoggingEnhancer in project google-cloud-java by GoogleCloudPlatform.

the class LoggingAppender method logEntryFor.

private LogEntry logEntryFor(ILoggingEvent e) {
    String payload = e.getFormattedMessage();
    Level level = e.getLevel();
    LogEntry.Builder builder = LogEntry.newBuilder(Payload.StringPayload.of(payload)).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);
        }
    }
    return builder.build();
}
Also used : LoggingEnhancer(com.google.cloud.logging.LoggingEnhancer) Level(ch.qos.logback.classic.Level) LogEntry(com.google.cloud.logging.LogEntry)

Aggregations

LoggingEnhancer (com.google.cloud.logging.LoggingEnhancer)2 Level (ch.qos.logback.classic.Level)1 MonitoredResource (com.google.cloud.MonitoredResource)1 LogEntry (com.google.cloud.logging.LogEntry)1