func buildError(desc string, fullText string, wrapped error, cause Error) *structured { e := &structured{ data: make(context.Map), // We capture the current context to allow it to propagate to higher layers. context: ops.AsMap(nil, false), wrapped: wrapped, cause: cause, } e.save() errorType := "errors.Error" if wrapped != nil { op, goType, wrappedDesc, extra := parseError(wrapped) if desc == "" { desc = wrappedDesc } e.Op(op) errorType = goType if extra != nil { for key, value := range extra { e.data[key] = value } } } cleanedDesc := hidden.Clean(desc) e.data["error"] = cleanedDesc if fullText != "" { e.data["error_text"] = hidden.Clean(fullText) } else { e.data["error_text"] = cleanedDesc } e.data["error_type"] = errorType return e }
func (l *logger) print(out io.Writer, skipFrames int, severity string, arg interface{}) string { buf := bufferPool.Get() defer bufferPool.Put(buf) linePrefix := l.linePrefix(skipFrames) writeHeader := func() { buf.WriteString(severity) buf.WriteString(" ") buf.WriteString(linePrefix) } if arg != nil { ml, isMultiline := arg.(MultiLine) if !isMultiline { writeHeader() fmt.Fprintf(buf, "%v", arg) printContext(buf, arg) buf.WriteByte('\n') } else { mlp := ml.MultiLinePrinter() first := true for { writeHeader() more := mlp(buf) if first { printContext(buf, arg) first = false } buf.WriteByte('\n') if !more { break } } } } b := []byte(hidden.Clean(buf.String())) _, err := out.Write(b) if err != nil { errorOnLogging(err) } if l.printStack { l.doPrintStack() } return linePrefix }
func (l *logger) printf(out io.Writer, skipFrames int, severity string, err error, message string, args ...interface{}) string { buf := bufferPool.Get() defer bufferPool.Put(buf) linePrefix := l.linePrefix(skipFrames) buf.WriteString(severity) buf.WriteString(" ") buf.WriteString(linePrefix) fmt.Fprintf(buf, message, args...) printContext(buf, err) buf.WriteByte('\n') b := []byte(hidden.Clean(buf.String())) _, err2 := out.Write(b) if err2 != nil { errorOnLogging(err) } if l.printStack { l.doPrintStack() } return linePrefix }