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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package plugin
import (
"fmt"
"log"
"strings"
"github.com/hashicorp/go-hclog"
"github.com/mattermost/mattermost-server/mlog"
)
type HclogAdapter struct {
wrappedLogger *mlog.Logger
extrasKey string
}
func (h *HclogAdapter) Trace(msg string, args ...interface{}) {
extras := strings.TrimSpace(fmt.Sprint(args...))
if extras != "" {
h.wrappedLogger.Debug(msg, mlog.String(h.extrasKey, extras))
} else {
h.wrappedLogger.Debug(msg)
}
}
func (h *HclogAdapter) Debug(msg string, args ...interface{}) {
extras := strings.TrimSpace(fmt.Sprint(args...))
if extras != "" {
h.wrappedLogger.Debug(msg, mlog.String(h.extrasKey, extras))
} else {
h.wrappedLogger.Debug(msg)
}
}
func (h *HclogAdapter) Info(msg string, args ...interface{}) {
extras := strings.TrimSpace(fmt.Sprint(args...))
if extras != "" {
h.wrappedLogger.Info(msg, mlog.String(h.extrasKey, extras))
} else {
h.wrappedLogger.Info(msg)
}
}
func (h *HclogAdapter) Warn(msg string, args ...interface{}) {
extras := strings.TrimSpace(fmt.Sprint(args...))
if extras != "" {
h.wrappedLogger.Warn(msg, mlog.String(h.extrasKey, extras))
} else {
h.wrappedLogger.Warn(msg)
}
}
func (h *HclogAdapter) Error(msg string, args ...interface{}) {
extras := strings.TrimSpace(fmt.Sprint(args...))
if extras != "" {
h.wrappedLogger.Error(msg, mlog.String(h.extrasKey, extras))
} else {
h.wrappedLogger.Error(msg)
}
}
func (h *HclogAdapter) IsTrace() bool {
return false
}
func (h *HclogAdapter) IsDebug() bool {
return true
}
func (h *HclogAdapter) IsInfo() bool {
return true
}
func (h *HclogAdapter) IsWarn() bool {
return true
}
func (h *HclogAdapter) IsError() bool {
return true
}
func (h *HclogAdapter) With(args ...interface{}) hclog.Logger {
return h
}
func (h *HclogAdapter) Named(name string) hclog.Logger {
return h
}
func (h *HclogAdapter) ResetNamed(name string) hclog.Logger {
return h
}
func (h *HclogAdapter) StandardLogger(opts *hclog.StandardLoggerOptions) *log.Logger {
return h.wrappedLogger.StdLog()
}
|