Christian,

By where I mean package/file.go:lineNumber which I have a helper method for 
that:


//-----------------------------------------------------------------------------

var (
    errNotAvailable = errors.New("N/A")
)

// Here .
func Here(skip ...int) (funcName, fileName string, fileLine int, callerErr 
error) {
    sk := 1
    if len(skip) > 0 && skip[0] > 1 {
        sk = skip[0]
    }
    var pc uintptr
    var ok bool
    pc, fileName, fileLine, ok = runtime.Caller(sk)
    if !ok {
        callerErr = errNotAvailable
        return
    }
    fn := runtime.FuncForPC(pc)
    name := fn.Name()
    ix := strings.LastIndex(name, ".")
    if ix > 0 && (ix+1) < len(name) {
        name = name[ix+1:]
    }
    funcName = name
    nd, nf := filepath.Split(fileName)
    fileName = filepath.Join(filepath.Base(nd), nf)
    return
}

//-----------------------------------------------------------------------------

I do not know if it's the best in the class though!

I like the approach that package took to keep track of the source error. 
But never have take a look to those interfaces. And that's my point. There 
is something wrong with being forced to adapt every single package to your 
underlying logger, just to provide logging.

And going back to the my initial concern: There is a need for an interface 
for a logger (whatever it should look like) and the standard log package 
should be able to consume that interface (instead of io.Writer).

On Thursday, August 17, 2017 at 3:43:21 PM UTC+4:30, Christian Joergensen 
wrote:
>
> On Thursday, August 17, 2017 at 11:40:08 AM UTC+2, dc0d wrote:
>>
>> That's a nice package with good design (and I've used it for a while). 
>> But I loose the info about where the error is happening.
>>
>
> What do you mean by where the error is happening?
>
> Have you checked out 
> http://godoc.org/github.com/pkg/errors#hdr-Retrieving_the_stack_trace_of_an_error_or_wrapper
>  
>
> Cheers,
>
> Christian
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to