ginlog

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package ginlog is gin server logger middleware.

Example
package main

import (
	"github.com/boxgo/box/pkg/logger"
	"github.com/boxgo/box/pkg/server/ginserver"
	"github.com/boxgo/box/pkg/server/ginserver/mid/ginlog"
	"github.com/gin-gonic/gin"
)

func main() {
	ginserver.Use(ginlog.Logger())
	ginserver.GET("/ping", func(ctx *gin.Context) {
		ctx.Data(200, "text/plain", []byte("pong"))
	})

	if err := ginserver.Run(); err != nil {
		logger.Fatal(err)
	}
}
Output:

Index

Examples

Constants

View Source
const (
	LogRequestUA int = 1 << iota
	LogRequestIP
	LogRequestHeader
	LogRequestQuery
	LogRequestBody
	LogResponseBody
)

Variables

View Source
var (
	Default = StdConfig("default").Build()
)

Functions

func Logger

func Logger() func(ctx *gin.Context)

Types

type Config

type Config struct {
	Skips         []string       `config:"skips" desc:"skip urls"`
	Urls          map[string]int `config:"urls" desc:"urls level log control"`
	RequestUA     bool           `config:"requestUA" desc:"log user-agent"`
	RequestIP     bool           `config:"requestIp" desc:"log request ip"`
	RequestHeader bool           `config:"requestHeader" desc:"log request header"`
	RequestQuery  bool           `config:"requestQuery" desc:"log request query"`
	RequestBody   bool           `config:"requestBody" desc:"log request body"`
	ResponseBody  bool           `config:"responseBody" desc:"log response body"`
	// contains filtered or unexported fields
}

Config 配置

func DefaultConfig

func DefaultConfig(key string) *Config

DefaultConfig 默认配置

func StdConfig

func StdConfig(key string, optionFunc ...OptionFunc) *Config

StdConfig 标准配置

func (*Config) Build

func (c *Config) Build() *GinLog

Build 构建实例

func (*Config) Path

func (c *Config) Path() string

Path 实例配置目录

type GinLog

type GinLog struct {
	// contains filtered or unexported fields
}

func (*GinLog) Logger

func (log *GinLog) Logger() func(ctx *gin.Context)

type OptionFunc

type OptionFunc func(*Config)

OptionFunc 选项信息

Jump to

Keyboard shortcuts

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