logging_config

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: May 25, 2023 License: Apache-2.0 Imports: 7 Imported by: 0

README

my-logger

Package for logging purpose, currently use in project use echo framework

###Feature

  • Create log file base on configurable properties
  • Capture log to console
  • Standarization log format
  • Available for INFO, DEBUG, FATAL, ERROR, PANIC

###Library :

  • Uber Zap
  • Lumberjack.v2 (gopkg.in/natefinch/lumberjack.v2)
Log Output Examples
{
  "timestamp": "2023-05-16 15:30:26.961",
  "level": "info",
  "message": "Hello From Logger",
  "app_name": "github.com/denysetiawan28/go-log",
  "app_tag": "go-log",
  "app_version": "1.0.0",
  "app_port": 9090,
  "app_request_id": "sEzvRc3FoL2ScgNlC1yz90Iyooh3AyNk",
  "app_journey_id": "",
  "app_req_ip": "::1",
  "app_method": "GET",
  "app_uri": "/api/v1/hello",
  "app_req_body": "eyJhc2QiOiJhc2Rhc2QifQ==",
  "app_additional_data": null
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewZapLogger

func NewZapLogger(conf LogConfig, writers ...io.Writer) (logger *zap.Logger)

NewZapLogger This constructor is to initialize zap logger and create zap instance. You can custom the log output. For default this constructor use stdout and file output to generate logs

func SetContext

func SetContext(ctx context.Context, contextId string, value interface{}) context.Context

SetContext This function use for set logging struct to golang context

Types

type Context

type Context struct {
	RequestTime     time.Time
	ThreadID        string `json:"_app_thread_id"`
	JourneyID       string `json:"_app_journey_id"`
	ServiceName     string `json:"_app_name"`
	ServiceVersion  string `json:"_app_version"`
	IP              string `json:"_IP"`
	ServicePort     int    `json:"_app_port"`
	ReqURI          string `json:"_app_uri"`
	ReqMethod       string `json:"_app_method"`
	SrcIP           string `json:"_src_ip"`
	Header, Request interface{}
	AdditionalData  map[string]interface{} `json:"_app_data,omitempty"`
	ErrorMessage    string
	ResponseCode    string
	Tag             string `json:"_app_tag"`
}

type Field

type Field struct {
	Key string
	Val interface{}
}

type ILogEngine

type ILogEngine interface {
	Debug(ctx context.Context, message string)
	Info(ctx context.Context, message string)
	Warn(ctx context.Context, message string)
	Error(ctx context.Context, message string)
	Fatal(ctx context.Context, message string)
	Panic(ctx context.Context, message string)
	Close() error
}

func NewLogEngine

func NewLogEngine(conf LogConfig) (ILogEngine, error)

type LogConfig

type LogConfig struct {
	Stdout           bool
	File             bool
	Path             string
	MaximumLogSize   int
	MaximumLogAge    int
	MaximumLogBackup int
}

type LogLevel

type LogLevel int8

type SystemLogger

type SystemLogger struct {
	ILogEngine
}

func SetupLogger

func SetupLogger(conf LogConfig) SystemLogger

Jump to

Keyboard shortcuts

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