logger.go 1.34 KB
Newer Older
Matt Kasa's avatar
Matt Kasa committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package logger

import (
	"bytes"

	"github.com/sirupsen/logrus"
)

// Logger embedded type
type Logger struct {
	*logrus.Logger
}

var logger = Logger{logrus.New()}

// SetLevel exported method
func SetLevel(level logrus.Level) {
	logger.SetLevel(level)
}

// Debug exported method
func Debug(args ...interface{}) {
	logger.Debug(args...)
}

// Debugln exported method
func Debugln(args ...interface{}) {
	logger.Debugln(args...)
}

// Fatal exported method
func Fatal(args ...interface{}) {
	logger.Fatal(args...)
}

// Info exported method
func Info(args ...interface{}) {
	logger.Info(args...)
}

41
42
43
44
45
// Infof exported method
func Infof(format string, args ...interface{}) {
	logger.Infof(format, args...)
}

Matt Kasa's avatar
Matt Kasa committed
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Warn exported method
func Warn(args ...interface{}) {
	logger.Warn(args...)
}

// Warnf exported method
func Warnf(format string, args ...interface{}) {
	logger.Warnf(format, args...)
}

// WithError exported method
func WithError(err error) *logrus.Entry {
	return logger.WithError(err)
}

// WithField exported method
func WithField(key string, value interface{}) *logrus.Entry {
	return logger.WithField(key, value)
}

// WithTestLogger exported method
func WithTestLogger(block func(logger *Logger)) *bytes.Buffer {
	out := logger.Out
	buffer := new(bytes.Buffer)
	logger.SetOutput(buffer)
	defer logger.SetOutput(out)

	block(&logger)

	return buffer
}