Skip to content
This repository has been archived by the owner on Apr 13, 2020. It is now read-only.

vicanso/elton-logger

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

elton-logger

The middleware has been archived, please use the middleware of elton.

Build Status

Access logger for elton, it support multiple tags from request and response.

package main

import (
	"bytes"
	"fmt"

	"github.com/vicanso/elton"

	codlogger "github.com/vicanso/elton-logger"
)

func main() {
	d := elton.New()

	d.Use(codlogger.New(codlogger.Config{
		Format: codlogger.CommonFormat,
		OnLog: func(str string, _ *elton.Context) {
			fmt.Println(str)
		},
	}))

	// http://127.0.0.1:7001/?_fields=foo,id
	d.GET("/", func(c *elton.Context) (err error) {
		c.StatusCode = 200
		c.SetHeader(elton.HeaderContentType, elton.MIMEApplicationJSON)
		c.BodyBuffer = bytes.NewBufferString(`{
			"foo": "bar",
			"id": 1,
			"price": 1.21
		}`)
		return
	})

	d.ListenAndServe(":7001")
}