logger

package module
v0.2.7 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2020 License: MIT Imports: 11 Imported by: 0

README

Logger

Release Discord Test Security Linter

Install
go get -u github.com/gofiber/fiber
go get -u github.com/gofiber/logger
Format

Format defines the logging format with defined variables Default: "${time} ${method} ${path} - ${ip} - ${status} - ${latency}\n"

Possible values: time, ip, ips, url, host, method, path, protocol, route, referer, ua, latency, status, body, error, bytesSent, bytesReceived, header:<key>, query:<key>, form:<key>, cookie:<key>

Example
package main

import (
  "github.com/gofiber/fiber"
  "github.com/gofiber/logger"
)

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

  app.Use(logger.New(logger.Config{
    // Optional
    Format: "${time} ${method} ${path} - ${ip} - ${status} - ${latency}\n",
  }))
  
  app.Get("/", func(c *fiber.Ctx) {
    c.Send("Welcome!")
  })

  app.Listen(3000)
}
Test
curl http://localhost:3000

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(config ...Config) func(*fiber.Ctx)

New ...

Types

type Config

type Config struct {
	// Filter defines a function to skip middleware.
	// Optional. Default: nil
	Filter func(*fiber.Ctx) bool
	// Format defines the logging format with defined variables
	// Optional. Default: "${time} ${method} ${path} - ${ip} - ${status} - ${latency}\n"
	// Possible values:
	// time, ip, ips, url, host, method, path, protocol, route
	// referer, ua, latency, status, body, error, bytesSent, bytesReceived
	// header:<key>, query:<key>, form:<key>, cookie:<key>
	Format string
	// TimeFormat https://programming.guide/go/format-parse-string-time-date-example.html
	// Optional. Default: 15:04:05
	TimeFormat string
	// Output is a writter where logs are written
	// Default: os.Stderr
	Output io.Writer
}

Config ...

Jump to

Keyboard shortcuts

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