forked from hyperledger-archives/aries-framework-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mocklogger.go
76 lines (57 loc) · 2.03 KB
/
mocklogger.go
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
41
42
43
44
45
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
/*
Copyright SecureKey Technologies Inc. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package mocklogger
import (
"fmt"
"github.com/Universal-Health-Chain/aries-framework-go/pkg/common/log"
)
// MockLogger is a mocked logger that can be used for testing.
type MockLogger struct {
AllLogContents string
FatalLogContents string
PanicLogContents string
DebugLogContents string
InfoLogContents string
WarnLogContents string
ErrorLogContents string
}
// Fatalf writes to the mock logger.
func (t *MockLogger) Fatalf(msg string, args ...interface{}) {
t.AllLogContents += fmt.Sprintln(fmt.Sprintf(msg, args...))
t.FatalLogContents += fmt.Sprintln(fmt.Sprintf(msg, args...))
}
// Panicf writes to the mock logger.
func (t *MockLogger) Panicf(msg string, args ...interface{}) {
t.AllLogContents += fmt.Sprintln(fmt.Sprintf(msg, args...))
t.PanicLogContents += fmt.Sprintln(fmt.Sprintf(msg, args...))
}
// Debugf writes to the mock logger.
func (t *MockLogger) Debugf(msg string, args ...interface{}) {
t.AllLogContents += fmt.Sprintln(fmt.Sprintf(msg, args...))
t.DebugLogContents += fmt.Sprintln(fmt.Sprintf(msg, args...))
}
// Infof writes to the mock logger.
func (t *MockLogger) Infof(msg string, args ...interface{}) {
t.AllLogContents += fmt.Sprintln(fmt.Sprintf(msg, args...))
t.InfoLogContents += fmt.Sprintln(fmt.Sprintf(msg, args...))
}
// Warnf writes to the mock logger.
func (t *MockLogger) Warnf(msg string, args ...interface{}) {
t.AllLogContents += fmt.Sprintln(fmt.Sprintf(msg, args...))
t.WarnLogContents += fmt.Sprintln(fmt.Sprintf(msg, args...))
}
// Errorf writes to the mock logger.
func (t *MockLogger) Errorf(msg string, args ...interface{}) {
t.AllLogContents += fmt.Sprintln(fmt.Sprintf(msg, args...))
t.ErrorLogContents += fmt.Sprintln(fmt.Sprintf(msg, args...))
}
// Provider is a mock logger provider that can be used for testing.
type Provider struct {
MockLogger *MockLogger
}
// GetLogger returns the underlying mock logger.
func (p *Provider) GetLogger(string) log.Logger {
return p.MockLogger
}