ccding / go-logging

the logging package for golang
Apache License 2.0
66 stars 13 forks source link

format log message before sending it to write queue #18

Open emptyhua opened 5 years ago

emptyhua commented 5 years ago
package main

import (
    "github.com/ccding/go-logging/logging"
)

type Resp struct {
    Msg string
}

func main() {
    logger, _ := logging.SimpleLogger("main")

    resp := &Resp{"hello"}
    logger.Errorf("resp=%+v", resp)
    resp.Msg = "world"
    logger.Errorf("resp=%+v", resp)

    logger.Destroy()
}

output:

main [ ERROR]  2018-08-27 16:23:41.796996122 - resp=&{Msg:world}
main [ ERROR]  2018-08-27 16:23:41.797058713 - resp=&{Msg:world}

the first mesage shoud be resp=&{Msg:hello}

ccding commented 5 years ago

in async mode, this is not guaranteed.