log15 icon indicating copy to clipboard operation
log15 copied to clipboard

Record.CallPC is too short

Open coderwoo opened this issue 9 years ago • 4 comments

// 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(....)
}

coderwoo avatar Aug 16 '16 06:08 coderwoo

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

ChrisHines avatar Aug 17 '16 01:08 ChrisHines

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 avatar Aug 17 '16 02:08 coderwoo

sorry for my chinglish : )

coderwoo avatar Aug 17 '16 02:08 coderwoo

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

decibel avatar Jan 20 '18 21:01 decibel