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:
parent
1836bb728b
commit
2879d98502
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user