-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.go
33 lines (26 loc) · 809 Bytes
/
server.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package main
import (
"net/http"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
"github.com/labstack/gommon/log"
"github.com/raahii/ecolog"
)
func Hello(c echo.Context) error {
c.Logger().Infof("This is a log in Hello method.")
return c.JSON(http.StatusOK, "Hello, World")
}
func main() {
e := echo.New()
e.HideBanner = true
e.Use(middleware.RequestID())
// Use ecolog middleware.
// See also document of ecolog.AppLoggerConfig.
e.Use(ecolog.AppLoggerWithConfig(ecolog.AppLoggerConfig{
Format: `{"time":"${time_rfc3339}","level": "${level}","id":"${id}","remote_ip":"${remote_ip}",` +
`"host":"${host}","method":"${method}","uri":"${uri}","user_agent":"${user_agent}"}`,
}))
e.GET("/", Hello)
e.Logger.SetLevel(log.INFO)
e.Logger.Fatal(e.Start(":1323"))
}