mirror of
https://github.com/SAP/jenkins-library.git
synced 2025-01-20 05:19:40 +02:00
a46b57e6b4
* Use commonPipelineEnvironment in go binary * Update groovy part incl. tests * Rework structure and naming * Support influx resources in steps * Update tests and some cleanups * Add correct defer handling * Address PR feedback * Fix test * Update resources.go Co-authored-by: Sven Merk <33895725+nevskrem@users.noreply.github.com>
36 lines
855 B
Go
36 lines
855 B
Go
package log
|
|
|
|
import (
|
|
"github.com/sirupsen/logrus"
|
|
)
|
|
|
|
// LibraryRepository that is passed into with -ldflags
|
|
var LibraryRepository string
|
|
var logger *logrus.Entry
|
|
|
|
// Entry returns the logger entry or creates one if none is present.
|
|
func Entry() *logrus.Entry {
|
|
if logger == nil {
|
|
logger = logrus.WithField("library", LibraryRepository)
|
|
}
|
|
return logger
|
|
}
|
|
|
|
// SetVerbose sets the log level with respect to verbose flag.
|
|
func SetVerbose(verbose bool) {
|
|
if verbose {
|
|
//Logger().Debugf("logging set to level: %s", level)
|
|
logrus.SetLevel(logrus.DebugLevel)
|
|
}
|
|
}
|
|
|
|
// SetStepName sets the stepName field.
|
|
func SetStepName(stepName string) {
|
|
logger = Entry().WithField("stepName", stepName)
|
|
}
|
|
|
|
// DeferExitHandler registers a logrus exit handler to allow cleanup activities.
|
|
func DeferExitHandler(handler func()) {
|
|
logrus.DeferExitHandler(handler)
|
|
}
|