cihub/seelog

The line number printed in log is not correct

Opened this issue · 6 comments

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!

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

that's true

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

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
}

line number still wrong

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