]> Cypherpunks.ru repositories - nncp.git/blobdiff - src/log.go
Logging refactoring, no centralized humanizer
[nncp.git] / src / log.go
index 25a494626a9d403e93421b9e36f371fa8076f87d..7bb59a3b97cf798e5c35c01d0c76c19154445ba6 100644 (file)
@@ -94,22 +94,18 @@ func (ctx *Ctx) Log(rec string) {
        fd.Close()          // #nosec G104
 }
 
-func (ctx *Ctx) LogD(who string, les LEs, msg string) {
+func (ctx *Ctx) LogD(who string, les LEs, msg func(LEs) string) {
        if !ctx.Debug {
                return
        }
        les = append(LEs{{"Debug", true}, {"Who", who}}, les...)
-       if msg != "" {
-               les = append(les, LE{"Msg", msg})
-       }
+       les = append(les, LE{"Msg", msg(les)})
        fmt.Fprint(os.Stderr, les.Rec())
 }
 
-func (ctx *Ctx) LogI(who string, les LEs, msg string) {
+func (ctx *Ctx) LogI(who string, les LEs, msg func(LEs) string) {
        les = append(LEs{{"Who", who}}, les...)
-       if msg != "" {
-               les = append(les, LE{"Msg", msg})
-       }
+       les = append(les, LE{"Msg", msg(les)})
        rec := les.Rec()
        if !ctx.Quiet {
                fmt.Fprintln(os.Stderr, ctx.HumanizeRec(rec))
@@ -117,11 +113,9 @@ func (ctx *Ctx) LogI(who string, les LEs, msg string) {
        ctx.Log(rec)
 }
 
-func (ctx *Ctx) LogE(who string, les LEs, err error, msg string) {
+func (ctx *Ctx) LogE(who string, les LEs, err error, msg func(LEs) string) {
        les = append(LEs{{"Err", err.Error()}, {"Who", who}}, les...)
-       if msg != "" {
-               les = append(les, LE{"Msg", msg})
-       }
+       les = append(les, LE{"Msg", msg(les)})
        rec := les.Rec()
        if !ctx.Quiet {
                fmt.Fprintln(os.Stderr, ctx.HumanizeRec(rec))