Customization

Debug

Echo#Debug can be used to enable / disable debug mode. Debug mode sets the log levelto DEBUG.

Logging

The default format for logging is JSON, which can be changed by modifying the header.

Log Header

Echo#Logger.SetHeader(io.Writer) can be used to set the header forthe logger. Default value:

  1. {"time":"${time_rfc3339_nano}","level":"${level}","prefix":"${prefix}","file":"${short_file}","line":"${line}"}

Example

  1. import "github.com/labstack/gommon/log"
  2. /* ... */
  3. if l, ok := e.Logger.(*log.Logger); ok {
  4. l.SetHeader("${time_rfc3339} ${level}")
  5. }
  1. 2018-05-08T20:30:06-07:00 INFO info

Available Tags

  • time_rfc3339
  • time_rfc3339_nano
  • level
  • prefix
  • long_file
  • short_file
  • line

Log Output

Echo#Logger.SetOutput(io.Writer) can be used to set the output destination forthe logger. Default value is os.Stdout

To completely disable logs use Echo#Logger.SetOutput(ioutil.Discard) or Echo#Logger.SetLevel(log.OFF)

Log Level

Echo#Logger.SetLevel(log.Lvl) can be used to set the log level for the logger.Default value is ERROR. Possible values:

  • DEBUG
  • INFO
  • WARN
  • ERROR
  • OFF

Custom Logger

Logging is implemented using echo.Logger interface which allows you to registera custom logger using Echo#Logger.

Custom Server

Echo#StartServer() can be used to run a custom server.

Example

  1. s := &http.Server{
  2. Addr: ":1323",
  3. ReadTimeout: 20 * time.Minute,
  4. WriteTimeout: 20 * time.Minute,
  5. }
  6. e.Logger.Fatal(e.StartServer(s))

Custom HTTP/2 Cleartext Server

Echo#StartH2CServer() can be used to run a custom HTTP/2 cleartext server.

Example

  1. import "golang.org/x/net/http2"
  2. s := &http2.Server{
  3. MaxConcurrentStreams: 250,
  4. MaxReadFrameSize: 1048576,
  5. IdleTimeout: 10 * time.Second,
  6. }
  7. e.Logger.Fatal(e.StartH2CServer(":1323", s))

Startup Banner

Echo#HideBanner can be used to hide the startup banner.

Custom Listener

Echo#*Listener can be used to run a custom listener.

Example

  1. l, err := net.Listen("tcp", ":1323")
  2. if err != nil {
  3. e.Logger.Fatal(l)
  4. }
  5. e.Listener = l
  6. e.Logger.Fatal(e.Start(""))

Disable HTTP/2

Echo#DisableHTTP2 can be used disable HTTP/2 protocol.

Read Timeout

Echo#*Server#ReadTimeout can be used to set the maximum duration before timing out readof the request.

Write Timeout

Echo#*Server#WriteTimeout can be used to set the maximum duration before timing out writeof the response.

Validator

Echo#Validator can be used to register a validator for performing data validationon request payload.

Learn more

Custom Binder

Echo#Binder can be used to register a custom binder for binding request payload.

Learn more

Renderer

Echo#Renderer can be used to register a renderer for template rendering.

Learn more

HTTP Error Handler

Echo#HTTPErrorHandler can be used to register a custom http error handler.

Learn more