ziflex / lecho

Zerolog wrapper for Echo framework 🍅
MIT License
99 stars 11 forks source link

Integrating with existing zerologger undefined #24

Closed rrajkowski closed 1 year ago

rrajkowski commented 1 year ago

Hi im using echo v4 and go1.19.3 and docs say to use v2 of lecho:

My code below

package main

import (
    "os"

    "github.com/labstack/echo/v4"
    "github.com/rs/zerolog"
    "github.com/ziflex/lecho/v3"
)

func main() {
    log := zerolog.New(os.Stdout)
    e := echo.New()
    e.Logger = lecho.From(log)

    //write log from context
    e.GET("/", func(c echo.Context) error {
        c.Logger().Print("Echo interface")
    })

}

// Output

lecho.New undefined (type *lecho.Logger has no field or method New)
lecho.New undefined (type *lecho.Logger has no field or method From)

Q: is there another version or am im missing something to integrate with zerolog? I've tried:

import (
"github.com/ziflex/lecho/v3"
"github.com/ziflex/lecho"
)

Thanks in advance

rrajkowski commented 1 year ago

after testing with v3 i got it working by reordering definitions, Thanks!

func main() {
    e := echo.New()
    log := zerolog.New(os.Stdout)

    e.Logger = lecho.From(log)

    //write log from context
    e.GET("/", func(c echo.Context) error {
        c.Logger().Print("Echo interface")
        return nil
    })

}
rrajkowski commented 1 year ago

closed