Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

logger: Do not set location offset in go-plugin #190

Merged
merged 1 commit into from
Sep 5, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 24 additions & 12 deletions logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ import (
"github.com/hashicorp/go-hclog"
)

// internalLogger is intended to be called via the public methods of the package.
// So the output line will be the caller of this package.
var internalLogger hclog.Logger

// logger is inteded to be called directly.
// It is mainly assumed to be used by go-plugin.
var logger hclog.Logger

// Use the init process to set the global logger.
Expand All @@ -18,56 +24,62 @@ func init() {
level = "off"
}

logger = hclog.New(&hclog.LoggerOptions{
internalLogger = hclog.New(&hclog.LoggerOptions{
Level: hclog.LevelFromString(level),
Output: os.Stderr,
TimeFormat: "15:04:05",
IncludeLocation: true,
AdditionalLocationOffset: 1,
})
logger = hclog.New(&hclog.LoggerOptions{
Level: hclog.LevelFromString(level),
Output: os.Stderr,
TimeFormat: "15:04:05",
IncludeLocation: true,
})
}

// Logger returns hcl.Logger as it is
// Logger returns hcl.Logger
func Logger() hclog.Logger {
return logger
}

// Trace emits a message at the TRACE level
func Trace(msg string, args ...interface{}) {
if logger == nil {
if internalLogger == nil {
return
}
logger.Trace(msg, args...)
internalLogger.Trace(msg, args...)
}

// Debug emits a message at the DEBUG level
func Debug(msg string, args ...interface{}) {
if logger == nil {
if internalLogger == nil {
return
}
logger.Debug(msg, args...)
internalLogger.Debug(msg, args...)
}

// Info emits a message at the INFO level
func Info(msg string, args ...interface{}) {
if logger == nil {
if internalLogger == nil {
return
}
logger.Info(msg, args...)
internalLogger.Info(msg, args...)
}

// Warn emits a message at the WARN level
func Warn(msg string, args ...interface{}) {
if logger == nil {
if internalLogger == nil {
return
}
logger.Warn(msg, args...)
internalLogger.Warn(msg, args...)
}

// Error emits a message at the ERROR level
func Error(msg string, args ...interface{}) {
if logger == nil {
if internalLogger == nil {
return
}
logger.Error(msg, args...)
internalLogger.Error(msg, args...)
}