Issue 009: Wrong File/Line from logger.Debug()#11
Open
jrefior wants to merge 1 commit intoian-kent:masterfrom
Open
Issue 009: Wrong File/Line from logger.Debug()#11jrefior wants to merge 1 commit intoian-kent:masterfrom
jrefior wants to merge 1 commit intoian-kent:masterfrom
Conversation
logger.Debug(x) -- or other logger entry function --
calls logger.Log, which
calls logger.Write, which
calls appender.Write, which
calls layout.Format, which
calls layout.getCaller, which
calls runtime.Caller.
Therefore the correct number of stack frames to ascend to get to
the caller of Debug -- or other logger entry function -- is 6.
See ian-kent#9
See also https://golang.org/pkg/runtime/#Caller
This code reproduces the bug:
package main
import(
"github.com/ian-kent/go-log/appenders"
"github.com/ian-kent/go-log/layout"
"github.com/ian-kent/go-log/log"
)
func main() {
logger := log.Logger()
logger.SetLevel(log.Stol("DEBUG"))
appender := appenders.RollingFile("sample.log", true)
appender.MaxFileSize = 1024
appender.SetLayout(layout.Pattern("%p %l %m "))
logger.SetAppender(appender)
logger.Debug("Reading configuration")
}
Result of runtime.Caller(n) in pattern.go for 0 >= n >= 7:
Caller(0): DEBUG layout/pattern.go:50 Reading configuration
Caller(1): DEBUG layout/pattern.go:70 Reading configuration
Caller(2): DEBUG appenders/rollingfile.go:51 Reading configuration
Caller(3): DEBUG logger/logger.go:129 Reading configuration
Caller(4): DEBUG logger/logger.go:154 Reading configuration
Caller(5): DEBUG logger/logger.go:213 Reading configuration
Caller(6): DEBUG go-log/bug009.go:16 Reading configuration
Caller(7): DEBUG runtime/proc.go:185 Reading configuration
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
logger.Debug(x) -- or other logger entry function --
calls logger.Log, which
calls logger.Write, which
calls appender.Write, which
calls layout.Format, which
calls layout.getCaller, which
calls runtime.Caller.
Therefore the correct number of stack frames to ascend to get to
the caller of Debug -- or other logger entry function -- is 6.
See #9
See also https://golang.org/pkg/runtime/#Caller
This code reproduces the bug:
Result of runtime.Caller(n) in pattern.go for 0 >= n >= 7:
Caller(0): DEBUG layout/pattern.go:50 Reading configuration
Caller(1): DEBUG layout/pattern.go:70 Reading configuration
Caller(2): DEBUG appenders/rollingfile.go:51 Reading configuration
Caller(3): DEBUG logger/logger.go:129 Reading configuration
Caller(4): DEBUG logger/logger.go:154 Reading configuration
Caller(5): DEBUG logger/logger.go:213 Reading configuration
Caller(6): DEBUG go-log/bug009.go:16 Reading configuration
Caller(7): DEBUG runtime/proc.go:185 Reading configuration