github.com/trigonella/mattermost-server@v5.11.1+incompatible/plugin/hclog_adapter.go (about) 1 // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. 2 // See LICENSE.txt for license information. 3 4 package plugin 5 6 import ( 7 "fmt" 8 "log" 9 "strings" 10 11 "github.com/hashicorp/go-hclog" 12 "github.com/mattermost/mattermost-server/mlog" 13 ) 14 15 type hclogAdapter struct { 16 wrappedLogger *mlog.Logger 17 extrasKey string 18 } 19 20 func (h *hclogAdapter) Trace(msg string, args ...interface{}) { 21 extras := strings.TrimSpace(fmt.Sprint(args...)) 22 if extras != "" { 23 h.wrappedLogger.Debug(msg, mlog.String(h.extrasKey, extras)) 24 } else { 25 h.wrappedLogger.Debug(msg) 26 } 27 } 28 29 func (h *hclogAdapter) Debug(msg string, args ...interface{}) { 30 extras := strings.TrimSpace(fmt.Sprint(args...)) 31 if extras != "" { 32 h.wrappedLogger.Debug(msg, mlog.String(h.extrasKey, extras)) 33 } else { 34 h.wrappedLogger.Debug(msg) 35 } 36 } 37 38 func (h *hclogAdapter) Info(msg string, args ...interface{}) { 39 extras := strings.TrimSpace(fmt.Sprint(args...)) 40 if extras != "" { 41 h.wrappedLogger.Info(msg, mlog.String(h.extrasKey, extras)) 42 } else { 43 h.wrappedLogger.Info(msg) 44 } 45 } 46 47 func (h *hclogAdapter) Warn(msg string, args ...interface{}) { 48 extras := strings.TrimSpace(fmt.Sprint(args...)) 49 if extras != "" { 50 h.wrappedLogger.Warn(msg, mlog.String(h.extrasKey, extras)) 51 } else { 52 h.wrappedLogger.Warn(msg) 53 } 54 } 55 56 func (h *hclogAdapter) Error(msg string, args ...interface{}) { 57 extras := strings.TrimSpace(fmt.Sprint(args...)) 58 if extras != "" { 59 h.wrappedLogger.Error(msg, mlog.String(h.extrasKey, extras)) 60 } else { 61 h.wrappedLogger.Error(msg) 62 } 63 } 64 65 func (h *hclogAdapter) IsTrace() bool { 66 return false 67 } 68 69 func (h *hclogAdapter) IsDebug() bool { 70 return true 71 } 72 73 func (h *hclogAdapter) IsInfo() bool { 74 return true 75 } 76 77 func (h *hclogAdapter) IsWarn() bool { 78 return true 79 } 80 81 func (h *hclogAdapter) IsError() bool { 82 return true 83 } 84 85 func (h *hclogAdapter) With(args ...interface{}) hclog.Logger { 86 return h 87 } 88 89 func (h *hclogAdapter) Named(name string) hclog.Logger { 90 return h 91 } 92 93 func (h *hclogAdapter) ResetNamed(name string) hclog.Logger { 94 return h 95 } 96 97 func (h *hclogAdapter) StandardLogger(opts *hclog.StandardLoggerOptions) *log.Logger { 98 return h.wrappedLogger.StdLog() 99 } 100 101 func (h *hclogAdapter) SetLevel(hclog.Level) {}