fiberlog

package module
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 30, 2020 License: MIT Imports: 6 Imported by: 0

README

fiberlog

godoc

HTTP request/response logger for Fiber using zerolog.

Install
go get -u github.com/gofiber/fiber
go get -u github.com/dre1080/fiberlog
Usage
package main

import (
  "github.com/gofiber/fiber"
  "github.com/dre1080/fiberlog"
)

func main() {
  app := fiber.New()

  // Default
  app.Use(fiberlog.New())

  // Custom Config
  app.Use(fiberlog.New(fiberlog.Config{
    Logger: &zerolog.New(os.Stdout),
    Next: func(ctx *fiber.Ctx) bool {
      // skip if we hit /private
      return ctx.Path() == "/private"
    },
  }))

  app.Listen(3000)
}
Example

Run app server:

$ go run example/main.go

Test request:

$ curl http://localhost:3000/ok
$ curl http://localhost:3000/warn
$ curl http://localhost:3000/err

screen

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(config ...Config) fiber.Handler

New is a zerolog middleware that allows you to pass a Config.

app := fiber.New()

// Without config
app.Use(New())

// With config
app.Use(New(Config{Logger: &zerolog.New(os.Stdout)}))

Types

type Config

type Config struct {
	// Next defines a function to skip this middleware.
	Next func(ctx *fiber.Ctx) bool

	// Logger is a *zerolog.Logger that writes the logs.
	//
	// Default: log.Logger.Output(zerolog.ConsoleWriter{Out: os.Stderr})
	Logger *zerolog.Logger
}

Config defines the config for logger middleware.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL