cihub / seelog

Seelog is a native Go logging library that provides flexible asynchronous dispatching, filtering, and formatting.
BSD 3-Clause "New" or "Revised" License
1.64k stars 244 forks source link

How to log the original function name when using seelog wrap #149

Closed dungeonsnd closed 7 years ago

dungeonsnd commented 7 years ago

Hello, Following is my seelog wrap. But i've not got the original file name, line number, function name, etc. We all know we can use macros in C/C++/Objective-C. So is there any workaround for this by seelog or go language? Thanks !

`

[20170308 07:53:51.067 +08] [t] StartTcpServer enter.
   [logwrap.go:48] [cacom/logwrap.V]

`

`

package logwrap

import (
    seelog "github.com/cihub/seelog"
)

var logger seelog.LoggerInterface

func Init(cfgFile string) bool {
    l, err := seelog.LoggerFromConfigAsFile(cfgFile)
    if err != nil {
        return true
    }
    logger = l
    seelog.ReplaceLogger(l)
    return true
}

// Call this before app shutdown
func Flush() {
    logger.Flush()
}

// verbose
func V(format string, args ...interface{}) {
    logger.Tracef(format, args...)
}

// debug
func D(format string, args ...interface{}) {
    logger.Debugf(format, args...)
}

// info
func I(format string, args ...interface{}) {
    logger.Infof(format, args...)
}

// warn
func W(format string, args ...interface{}) {
    logger.Warnf(format, args...)
}

// error
func E(format string, args ...interface{}) {
    logger.Errorf(format, args...)
}

// fatal
func F(format string, args ...interface{}) {
    logger.Criticalf(format, args...)
}

`

`

package main

import (
    log "cacom/logwrap"
    "fmt"
)

func main() {
    cfg := "../log.cfg"
    if false == log.Init(cfg) {
        fmt.Println("Load config file failed:", cfg)
        return
    }
    defer log.Flush()
    log.I("Server starting...")

}

`

dungeonsnd commented 7 years ago

I've resolved this.