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();
}
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();
}
Aggregations