in galog_cloudlogging.go [241:284]
func (cb *CloudBackend) Log(entry *LogEntry) error {
// If the logger is nil it means the backend is lazy initialized, we return
// an error to indicate that the backend is not yet initialized - the entries
// will be queued.
if cb.logger == nil {
return errCloudLoggingNotInitialized
}
levelMap := map[Level]logging.Severity{
FatalLevel: logging.Critical,
ErrorLevel: logging.Error,
WarningLevel: logging.Warning,
InfoLevel: logging.Info,
DebugLevel: logging.Debug,
}
severity := levelMap[entry.Level]
sourceLocation := &logpb.LogEntrySourceLocation{
File: entry.File,
Line: int64(entry.Line),
Function: entry.Function,
}
format := cb.config.Format(entry.Level)
message, err := entry.Format(format)
if err != nil {
return fmt.Errorf("failed to format log message: %+v", err)
}
payload := &CloudEntryPayload{
Message: message,
LocalTimestamp: entry.When.Format("2006-01-02T15:04:05.0000Z07:00"),
ProgName: cb.opts.ProgramName,
ProgVersion: cb.opts.ProgramVersion,
}
cb.logger.Log(logging.Entry{
Severity: severity,
SourceLocation: sourceLocation,
Payload: payload,
})
return nil
}