-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
paddy
committed
Mar 19, 2024
1 parent
1797041
commit b7b450b
Showing
5 changed files
with
51 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package util | ||
|
||
import ( | ||
"os" | ||
|
||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
var Logger = logger{} | ||
Check failure on line 9 in util/logger.go GitHub Actions / golangci-lint (1.16)
Check failure on line 9 in util/logger.go GitHub Actions / golangci-lint (1.17)
Check failure on line 9 in util/logger.go GitHub Actions / golangci-lint (1.18)
|
||
|
||
type logger struct { | ||
debug bool | ||
} | ||
|
||
func init() { | ||
// Log as JSON instead of the default ASCII formatter. | ||
log.SetFormatter(&log.TextFormatter{}) | ||
|
||
// Output to stdout instead of the default stderr | ||
// Can be any io.Writer, see below for File example | ||
log.SetOutput(os.Stdout) | ||
|
||
// Only log the warning severity or above. | ||
log.SetLevel(log.DebugLevel) | ||
} | ||
|
||
// SetDebug sets the debug flag | ||
func (r logger) SetDebug(isDebug bool) { | ||
r.debug = isDebug | ||
Check failure on line 29 in util/logger.go GitHub Actions / golangci-lint (1.16)
Check failure on line 29 in util/logger.go GitHub Actions / golangci-lint (1.17)
Check failure on line 29 in util/logger.go GitHub Actions / golangci-lint (1.18)
|
||
} | ||
|
||
// Debugf logs a message at level Debug on the standard logger. | ||
func (r logger) Debugf(format string, args ...interface{}) { | ||
if r.debug { | ||
log.Debugf(format, args...) | ||
} | ||
} | ||
|
||
// Error logs a message at level Error on the standard logger. | ||
func (r logger) Error(args ...interface{}) { | ||
if r.debug { | ||
log.Error(args...) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters