ginlogger

package module
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2022 License: MIT Imports: 9 Imported by: 0

README

gin-logrus-stackdriver

Installation

Download Go module:

go get -u github.com/r04922101/gin-logrus-stackdriver

How to Use

Import it in your code
import ginlogger "github.com/r04922101/gin-logrus-stackdriver"
Example

Check the example code in example/main.go

Run example/main.go

go run main.go

Send an HTTP POST request to localhost:8080/ping

curl -X POST 'localhost:8080/ping' \
-H 'Content-Type: text/plain' \
-d 'pang'
Result

Check your console, and see the gin log is in stackdriver format

{"message":"2021/12/29 14:20:09.428 - ::1 PostmanRuntime/7.26.8, req: \"HTTP/1.1    POST /ping pang\", res: \"200\", latency: 107.049µs","severity":"INFO","timestamp":{"seconds":1640758809,"nanos":428314000}}

Customize Formatter

Refer to Gin Custom Log Format, write your custom formatter function.
Construct a LoggerConfig with the formatter and pass it to NewLoggerWithConfig function.
You can also find a example snippet of custom formatter in example/main.go.

Customize Logger

If you want to use your own logrus.Logger instance instead of default logger in stackdriver format, just pass your logger to LoggerConfig.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewLogger

func NewLogger() gin.HandlerFunc

NewLogger instances a Logger middleware.

func NewLoggerWithConfig added in v1.1.0

func NewLoggerWithConfig(conf LoggerConfig) func(c *gin.Context)

NewLoggerWithConfig instance a Logger middleware with config.

Types

type LoggerConfig added in v1.1.0

type LoggerConfig struct {
	// Logger is a logrus logger
	Logger *logrus.Logger

	// Optional. Default value is defaultLogFormatter
	Formatter gin.LogFormatter

	// SkipPaths is a url path array which logs are not written
	// Optional
	SkipPaths []string
}

LoggerConfig 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