2021-02-10 13:25:07 +00:00
|
|
|
package logger
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
"log"
|
|
|
|
|
|
|
|
"github.com/hashicorp/go-hclog"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
)
|
|
|
|
|
|
|
|
type terraformPluginFormatter struct {
|
|
|
|
logrus.Formatter
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *terraformPluginFormatter) Format(entry *logrus.Entry) ([]byte, error) {
|
|
|
|
entry.Message = "[TerraformPlugin] " + entry.Message
|
|
|
|
return f.Formatter.Format(entry)
|
|
|
|
}
|
|
|
|
|
|
|
|
type TerraformPluginLogger struct {
|
|
|
|
logger *logrus.Logger
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewTerraformPluginLogger() TerraformPluginLogger {
|
|
|
|
config := getConfig()
|
|
|
|
logger := logrus.New()
|
|
|
|
logger.SetLevel(logrus.ErrorLevel)
|
|
|
|
logger.SetReportCaller(false)
|
|
|
|
logger.SetFormatter(&terraformPluginFormatter{Formatter: config.Formatter})
|
|
|
|
|
|
|
|
// Disable terraform provider log if we are not in trace level
|
|
|
|
if config.Level == logrus.TraceLevel {
|
|
|
|
logger.SetLevel(logrus.TraceLevel)
|
|
|
|
}
|
|
|
|
|
|
|
|
return TerraformPluginLogger{logger}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t TerraformPluginLogger) Trace(msg string, args ...interface{}) {
|
|
|
|
t.logger.Trace(msg, args)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t TerraformPluginLogger) Debug(msg string, args ...interface{}) {
|
2021-02-10 16:16:09 +00:00
|
|
|
t.Trace(msg, args)
|
2021-02-10 13:25:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t TerraformPluginLogger) Info(msg string, args ...interface{}) {
|
2021-02-10 16:16:09 +00:00
|
|
|
t.Trace(msg, args)
|
2021-02-10 13:25:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t TerraformPluginLogger) Warn(msg string, args ...interface{}) {
|
2021-02-10 16:16:09 +00:00
|
|
|
t.Trace(msg, args)
|
2021-02-10 13:25:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t TerraformPluginLogger) Error(msg string, args ...interface{}) {
|
2021-02-10 16:16:09 +00:00
|
|
|
t.Trace(msg, args)
|
2021-02-10 13:25:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t TerraformPluginLogger) IsTrace() bool {
|
2021-02-10 16:16:09 +00:00
|
|
|
return true
|
2021-02-10 13:25:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t TerraformPluginLogger) IsDebug() bool {
|
2021-02-10 16:16:09 +00:00
|
|
|
return false
|
2021-02-10 13:25:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t TerraformPluginLogger) IsInfo() bool {
|
2021-02-10 16:16:09 +00:00
|
|
|
return false
|
2021-02-10 13:25:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t TerraformPluginLogger) IsWarn() bool {
|
2021-02-10 16:16:09 +00:00
|
|
|
return false
|
2021-02-10 13:25:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t TerraformPluginLogger) IsError() bool {
|
2021-02-10 16:16:09 +00:00
|
|
|
return false
|
2021-02-10 13:25:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t TerraformPluginLogger) With(args ...interface{}) hclog.Logger {
|
|
|
|
return t
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t TerraformPluginLogger) Named(name string) hclog.Logger {
|
|
|
|
return t
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t TerraformPluginLogger) ResetNamed(name string) hclog.Logger {
|
|
|
|
return t
|
|
|
|
}
|
|
|
|
|
2021-02-10 16:16:09 +00:00
|
|
|
func (t TerraformPluginLogger) SetLevel(level hclog.Level) {}
|
2021-02-10 13:25:07 +00:00
|
|
|
|
|
|
|
func (t TerraformPluginLogger) StandardLogger(opts *hclog.StandardLoggerOptions) *log.Logger {
|
|
|
|
stdLogger := log.New(t.logger.Writer(), "", log.Flags())
|
|
|
|
stdLogger.SetOutput(t.logger.Writer())
|
|
|
|
return stdLogger
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t TerraformPluginLogger) StandardWriter(opts *hclog.StandardLoggerOptions) io.Writer {
|
|
|
|
return t.logger.Writer()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t TerraformPluginLogger) Log(level hclog.Level, msg string, args ...interface{}) {
|
2021-02-10 16:16:09 +00:00
|
|
|
t.logger.Log(logrus.TraceLevel, msg, args)
|
2021-02-10 13:25:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t TerraformPluginLogger) ImpliedArgs() []interface{} {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t TerraformPluginLogger) Name() string {
|
|
|
|
return "TerraformPlugin"
|
|
|
|
}
|