log

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2023 License: Apache-2.0 Imports: 15 Imported by: 0

README

Logger

Logrus based logging.

Configuration example:

log:
  enable: true
  # log level: trace, debug, info, warn, error, fatal
  level: debug
  # log format: TEXT or JSON
  format: text
  caller:
    enable: false
  console:
    enable: true
    # output to stdout or stderr
    stream: stderr
  file:
    enable: false
    path: logs/application.log
    compress: true
    limit:
      # max file size, in megabytes
      size: 50
      # max file backup
      backup: 10
      # max file age, in days
      age: 30

here is logging initializer example, you can put it anywhere at the package

import (
	"github.com/sirupsen/logrus"
	"gitlab.com/watonist/letsgo/log"
	logkey "gitlab.com/watonist/letsgo/log/key"
)

func logFn(fn string) log.Fn {
	return log.LazyLogger(func() *logrus.Entry {
		return log.Logger().WithField(logkey.Module, "client/"+fn)
	})
}

var logger = log.LazyLogger(func() *logrus.Entry {
	return log.Logger().WithField(logkey.Module, "client")
})

and then try to log something out

    logger().
		WithField("status", resp.Status).
		WithField("message", resp.Message).
		WithField("id", resp.Client).
		Debug("Registration response")

Back

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ElapsedTime

func ElapsedTime(logger *logrus.Entry, format string, a ...interface{}) func()

ElapsedTime log process elapsed time

func Logger

func Logger() *logrus.Entry

Logger get logger instance

func PostInit

func PostInit()

PostInit initialize module after load configuration

Types

type Fn

type Fn func() *logrus.Entry

Fn log function

func LazyLogger

func LazyLogger(fn Fn) Fn

LazyLogger lazy instance logger

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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