logger

package module
v0.0.0-...-cd6ea81 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2019 License: MIT Imports: 5 Imported by: 1

README

bulrush-logger

Provides logging capabilities.

  • EXAMPLE:
// Logger Plugin init
var Logger = &logger.Logger{
	Path: "logs",
	Format: func(p *logger.Payload, ctx *gin.Context) string {
		if p.Type == logger.INT {
			startTime := time.Unix(p.StartUnix, 0).Format("2006/01/02 15:04:05")
			return fmt.Sprintf("[%v bulrush] => %s %6s %s", startTime, p.IP, p.Method, p.URL)
		} else if p.Type == logger.OUT {
			endOfTime := time.Unix(p.EndUnix, 0).Format("2006/01/02 15:04:05")
			latency := float64(time.Unix(p.EndUnix, 0).Sub(time.Unix(p.StartUnix, 0)) / time.Millisecond)
			return fmt.Sprintf("[%v bulrush] <= %.2fms %s %6s %s", endOfTime, latency, p.IP, p.Method, p.URL)
		}
		return "FROMAT ERROR"
	},
}

MIT License

Copyright (c) 2018-2020 Double

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LeftV

func LeftV(left interface{}, right interface{}) interface{}

LeftV -

func Some

func Some(target interface{}, initValue interface{}) interface{}

Some get or a default value

Types

type Logger

type Logger struct {
	Format func(*Payload, *gin.Context) string
	Path   string
}

Logger plugin

func (*Logger) Plugin

func (logger *Logger) Plugin(cfg *bulrush.Config, router *gin.RouterGroup)

Plugin for Recovery

type Payload

type Payload struct {
	StartUnix int64
	EndUnix   int64
	Type      Type
	Latency   float64
	Method    string
	IP        string
	URL       string
}

Payload in request

type Type

type Type int

Type logger type

const (
	// INT logger type
	INT Type = iota + 1
	// OUT logger type
	OUT
)

Jump to

Keyboard shortcuts

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