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

The line number printed in log is not correct #153

Open
EriconYu opened this issue Jul 6, 2017 · 6 comments
Open

The line number printed in log is not correct #153

EriconYu opened this issue Jul 6, 2017 · 6 comments

Comments

@EriconYu
Copy link

EriconYu commented Jul 6, 2017

The line number printed in log is not correct,eg:

package main

import (
	"fmt"

	"github.com/cihub/seelog"
)

func init() {
	seelogInit()
}

func seelogInit() {
	// Log, err := seelog.LoggerFromConfigAsBytes([]byte(seelogConfig))
	Log, err := seelog.LoggerFromConfigAsFile("seelog.xml")

	if err != nil {
		fmt.Println("seelog init failed!!!")
		panic(err)
	}
	seelog.ReplaceLogger(Log)
	seelog.Info("seelog init success!")
}

Console prints :

2017-07-06 16:04:47 [init.go:23] [INF] seelog init success!

but actual should be :

2017-07-06 16:04:47 [init.go:22] [INF] seelog init success!
@EriconYu
Copy link
Author

EriconYu commented Jul 6, 2017

xml content is :

<seelog type="sync">
    <outputs formatid="main">  
        <filter levels="info,debug,critical,error">    
            <console />
        </filter>
        <filter levels="info,debug,critical,error">
            <file path="log.txt" />    
        </filter>
    </outputs>
    <formats>
        <format id="main" format="%Date %Time [%File:%Line] [%LEV] %Msg%n"/>
    </formats>
</seelog>

go version is

go version go1.8 linux/amd64

@antsbean
Copy link

antsbean commented Jul 6, 2017

that's true

@EriconYu
Copy link
Author

EriconYu commented Jul 7, 2017

@hqy 为啥呢?实际应该是22,但是打印出来是23,我没搞明白是怎么个原因,是因为go版本升级了的问题吗

@nelsonzhu
Copy link

func extractCallerInfo(skip int) (*logContext, error) {

var shortPath string
pc, fullPath, line, ok := runtime.Caller(skip)
if !ok {
return nil, errors.New("error during runtime.Callers")
}

// do we have a cache entry?
stackCacheLock.RLock()
ctx, ok := stackCache[pc]
stackCacheLock.RUnlock()
if ok {
	return ctx, nil
}

@Kurt-Shiwz
Copy link

line number still wrong

@skydroplet
Copy link

use tag v2.6, don't use the master, v2.6 is correct

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants