1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2025-01-18 05:18:24 +02:00

Include error in log message (#1535)

* Include error in the log.

In case the default text formatter is used, the error
will be contained in the log, too.

* Avoid stupid nil token printed in error message
This commit is contained in:
Marcus Holl 2020-05-26 11:06:52 +02:00 committed by GitHub
parent 1836bb728b
commit 2879d98502
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -29,13 +29,18 @@ func (formatter *PiperLogFormatter) Format(entry *logrus.Entry) (bytes []byte, e
stepName = "(noStepName)"
}
errorMessage := entry.Data[logrus.ErrorKey]
if errorMessage == nil {
errorMessage = "(noErrorMessage)"
}
switch formatter.logFormat {
case logFormatDefault:
message = fmt.Sprintf("%-5s %-6s - %s\n", entry.Level, stepName, entry.Message)
message = fmt.Sprintf("%-5s %-6s - %s - %s\n", entry.Level, stepName, entry.Message, errorMessage)
case logFormatWithTimestamp:
message = fmt.Sprintf("%s %-5s %-6s - %s\n", entry.Time.Format("15:04:05"), entry.Level, stepName, entry.Message)
message = fmt.Sprintf("%s %-5s %-6s - %s - %s\n", entry.Time.Format("15:04:05"), entry.Level, stepName, entry.Message, errorMessage)
case logFormatPlain:
message = entry.Message + "\n"
message = fmt.Sprintf("%s - %s\n", entry.Message, errorMessage)
default:
formattedMessage, err := formatter.TextFormatter.Format(entry)
if err != nil {