inconshreveable / log15

Structured, composable logging for Go
https://godoc.org/github.com/inconshreveable/log15
Other
1.1k stars 145 forks source link

Record.CallPC is too short #102

Open coderwoo opened 8 years ago

coderwoo commented 8 years ago
// A Record is what a Logger asks its handler to write
type Record struct {
    Time     time.Time
    Lvl      Lvl
    Msg      string
    Ctx      []interface{}
    CallPC   [1]uintptr
    KeyNames RecordKeyNames
}

CallPC should by more large for this situation:

import (
     log "gopkg.in/inconshreveable/log15.v2"
)

func Info_wrapper(value interface{}...) {
      // do something here
      log.Info(....)
}
ChrisHines commented 8 years ago

What do you want to do in Info_wrapper that cannot be done by a custom log15.Handler?

coderwoo commented 8 years ago

I have multi tasks to do, each task is a go routine. I want each log have a task id, something like:

DBUG | 08-16 23:00:55 | wrapper_test.go:hello:17 | taskId:20 | debug, a=100 | 
INFO | 08-16 23:00:55 | wrapper_test.go:hello:18 | taskId:10 | waitting | progress:30

I use gls to store the logger interface. I need featch the special logger in Info_wrapper first.

func Info_wrapper(value interface{}...) {
         logger = gls.Get("logger").(log.logger)
        logger.Info(....)
}

func InitLogger(taskId int) {
        logger = log.New("taskId": taskId)
        gls.Set("logger", logger)
        // set custom Format and handler here
}

so, do you have any other idea to implement this? Thanks

coderwoo commented 8 years ago

sorry for my chinglish : )

decibel commented 6 years ago

I've run into this same kind of problem while using pkg/errors: https://github.com/pkg/errors/issues/129.