mirror of
https://github.com/SAP/jenkins-library.git
synced 2024-12-14 11:03:09 +02:00
b88ebdad6c
* Adds inital splunk hook and logCollector * Adds documentation of the Splunk hook * Fixes markdown lint issues and removes comment from telemetry.go file * Fixes markdown lint issues and adds missing generated file * Markdown linting * Changes documentation according to review, adds Splunk token automatically during init * Adds error handling for marshalling hook config * Markdown lint und correct Splunk token in httpclient * Registeres Splunk token as secret and adjusts test cases * Adds missing error handling and removes unnecessary comments * Creates new function readPipelineEnvironment, adds tests * Moves MonitoringData struct, edits defaults for json fields * Adds gitRepository and gitOwner to telemetry information * Simplifies readCommonPipelineEnvironment function, adds more descriptive errors, adds automated adding of Splunk prefix token * Adjusts error handling * Cleaner error logging
41 lines
1.2 KiB
Go
41 lines
1.2 KiB
Go
package log
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
)
|
|
|
|
// logCollectorHook provides a logrus hook which stores details about any logs of each step.
|
|
// This is helpful in order to transfer the logs and error details to an logging system as Splunk
|
|
// and by that make it possible to have a better investigation of any error.
|
|
|
|
type CollectorHook struct {
|
|
CorrelationID string
|
|
Messages []Message
|
|
// TODO: log Levels?
|
|
}
|
|
|
|
// Levels returns the supported log level of the hook.
|
|
func (f *CollectorHook) Levels() []logrus.Level {
|
|
return []logrus.Level{logrus.InfoLevel, logrus.DebugLevel, logrus.WarnLevel, logrus.ErrorLevel, logrus.PanicLevel, logrus.FatalLevel}
|
|
}
|
|
|
|
type Message struct {
|
|
Time time.Time `json:"time,omitempty"`
|
|
Level logrus.Level `json:"level,omitempty"`
|
|
Message string `json:"message,omitempty"`
|
|
Data interface{} `json:"data,omitempty"`
|
|
}
|
|
|
|
// Fire creates a new event from the logrus and stores it in the SplunkHook object
|
|
func (f *CollectorHook) Fire(entry *logrus.Entry) error {
|
|
message := Message{
|
|
Time: entry.Time,
|
|
Data: entry.Data,
|
|
Message: entry.Message,
|
|
}
|
|
f.Messages = append(f.Messages, message)
|
|
return nil
|
|
}
|