Skip to content

Commit b711cbe

Browse files
authored
Do not set location offset in go-plugin (#190)
1 parent 47ada1d commit b711cbe

File tree

1 file changed

+24
-12
lines changed

1 file changed

+24
-12
lines changed

logger/logger.go

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ import (
66
"github.com/hashicorp/go-hclog"
77
)
88

9+
// internalLogger is intended to be called via the public methods of the package.
10+
// So the output line will be the caller of this package.
11+
var internalLogger hclog.Logger
12+
13+
// logger is inteded to be called directly.
14+
// It is mainly assumed to be used by go-plugin.
915
var logger hclog.Logger
1016

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

21-
logger = hclog.New(&hclog.LoggerOptions{
27+
internalLogger = hclog.New(&hclog.LoggerOptions{
2228
Level: hclog.LevelFromString(level),
2329
Output: os.Stderr,
2430
TimeFormat: "15:04:05",
2531
IncludeLocation: true,
2632
AdditionalLocationOffset: 1,
2733
})
34+
logger = hclog.New(&hclog.LoggerOptions{
35+
Level: hclog.LevelFromString(level),
36+
Output: os.Stderr,
37+
TimeFormat: "15:04:05",
38+
IncludeLocation: true,
39+
})
2840
}
2941

30-
// Logger returns hcl.Logger as it is
42+
// Logger returns hcl.Logger
3143
func Logger() hclog.Logger {
3244
return logger
3345
}
3446

3547
// Trace emits a message at the TRACE level
3648
func Trace(msg string, args ...interface{}) {
37-
if logger == nil {
49+
if internalLogger == nil {
3850
return
3951
}
40-
logger.Trace(msg, args...)
52+
internalLogger.Trace(msg, args...)
4153
}
4254

4355
// Debug emits a message at the DEBUG level
4456
func Debug(msg string, args ...interface{}) {
45-
if logger == nil {
57+
if internalLogger == nil {
4658
return
4759
}
48-
logger.Debug(msg, args...)
60+
internalLogger.Debug(msg, args...)
4961
}
5062

5163
// Info emits a message at the INFO level
5264
func Info(msg string, args ...interface{}) {
53-
if logger == nil {
65+
if internalLogger == nil {
5466
return
5567
}
56-
logger.Info(msg, args...)
68+
internalLogger.Info(msg, args...)
5769
}
5870

5971
// Warn emits a message at the WARN level
6072
func Warn(msg string, args ...interface{}) {
61-
if logger == nil {
73+
if internalLogger == nil {
6274
return
6375
}
64-
logger.Warn(msg, args...)
76+
internalLogger.Warn(msg, args...)
6577
}
6678

6779
// Error emits a message at the ERROR level
6880
func Error(msg string, args ...interface{}) {
69-
if logger == nil {
81+
if internalLogger == nil {
7082
return
7183
}
72-
logger.Error(msg, args...)
84+
internalLogger.Error(msg, args...)
7385
}

0 commit comments

Comments
 (0)