gin_logger

package module
v2.0.0-...-3c63b11 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2022 License: Apache-2.0 Imports: 8 Imported by: 0

README

KrakenD GIN Logger

The module enables getting GIN router logs in JSON format.

Setting Up

Clone the KrakenD-CE repository and update the following changes in the router_engine.go file:

import (
+    "github.com/delameter/krakend-gin-logger"
)

// NewEngine creates a new gin engine with some default values and a secure middleware
func NewEngine(cfg config.ServiceConfig, logger logging.Logger, w io.Writer) *gin.Engine {
     if !cfg.Debug {
         gin.SetMode(gin.ReleaseMode)
     }

     engine := gin.New()
-    engine.Use(gin.LoggerWithConfig(gin.LoggerConfig{Output: w}), gin.Recovery())
+    engine.Use(gin_logger.NewLogger(
+	       cfg.ExtraConfig,
+	       logger,
+	       gin.LoggerConfig{Output: w}), gin.Recovery())

In KrakenD's configuration.json file, add the following to the service extra_config:

{
  "extra_config": {
    "github_com/delameter/krakend-gin-logger": {
      "enabled": true
    }
  }
}
Available Config Options

skip_paths: List of endpoint paths which should not be logged.

Example:

{
  "extra_config": {
    "github_com/delameter/krakend-gin-logger": {
      "enabled": true,
      "skip_paths": ["/__health", "/api/ignore"]
    }
  }
}

In the above example configuration, any request to /__health or /api/ignore will not be logged by GIN.

Usage with KrakenD Logstash

The module can also be used with Logstash. Simply enable Logstash in the service extra_config.

{
  "extra_config": {
    "github_com/devopsfaith/krakend-logstash": {
      "enabled": true
    },
    "github_com/devopsfaith/krakend-gologging": {
      "level": "INFO",
      "prefix": "[KRAKEND]",
      "syslog": false,
      "stdout": true,
      "format": "custom",
      "custom_format": "%{message}"
    },
    "github_com/delameter/krakend-gin-logger": {
      "enabled": true
    }
  }
}

Documentation

Index

Constants

View Source
const (
	Namespace = "github_com/delameter/krakend-gin-logger"
)

Variables

This section is empty.

Functions

func ConfigGetter

func ConfigGetter(e config.ExtraConfig) interface{}

func NewLogger

func NewLogger(cfg config.ExtraConfig, logger logging.Logger, loggerConfig gin.LoggerConfig) gin.HandlerFunc

Types

type Config

type Config struct {
	SkipPaths []string
	Logstash  bool
}

type Formatter

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

func (Formatter) DefaultFormatter

func (f Formatter) DefaultFormatter(params gin.LogFormatterParams) string

Jump to

Keyboard shortcuts

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