Skip to content
This repository has been archived by the owner on Jul 2, 2024. It is now read-only.

baac-tech/zlogwrap

Repository files navigation

zlogwrap

made-with-Go

zlogwrap is a logging library, which wrapping all common use in My "Go App".

Table of Contents

Installation

  go get -u github.com/baac-tech/zlogwrap

Signatures

func New(conf ...Config) zerologWrapper

zerologWrapper

Interface of functions

type zerologWrapper interface {
  SetField(key string, anything interface{}) zerologWrapper // Set field in logs
  Debug(anything ...interface{})                            // level 0
  Info(anything ...interface{})                             // level 1
  Warn(anything ...interface{})                             // level 2
  Error(anything ...interface{})                            // level 3
  Fatal(anything ...interface{})                            // level 4
  Panic(anything ...interface{})                            // level 5
  GetLogEvent(zerolog.Level) *zerolog.Event                 // With Caller (file:line)
}

Examples

Import the package

import (
  "github.com/baac-tech/zlogwrap"
)

Using with these

logger := zlogwrap.New()
logger.Debug("A Debug Log")

// {"level":"debug","time":"2021-07-27T16:49:59+07:00","message":"A Debug Log"}

Optional: With configuration

logger := zlogwrap.New(zlogwrap.Config{
  ServiceName: "zlogwrap",
})
logger.Debug("A Debug Log")
logger.SetField("key", "value").Debug("A Debug Log")

// {"level":"debug","service":"zlogwrap","time":"2021-08-05T11:14:00+07:00","message":"A Debug Log"}
// {"level":"debug","key":"value","service":"zlogwrap","time":"2021-08-05T11:14:00+07:00","message":"A Debug Log"}

or customize the "Logger" and this library support middleware RequestID

myLogger := zerolog.New(os.Stdout).
  With().
  Str("foo", "bar").
  Float64("money", 10.99).
  Logger()
logger := zlogwrap.New(zlogwrap.Config{
  ServiceName: serviceName,
  Logger:      myLogger,
  Context:     c, // Which type is `*fiber.Ctx`
})
logger.Debug("A Debug Log")

// ps. see the real usage in `example/main.go`
// {"level":"debug","foo":"bar","money":10.99,"service":"zlogwrap","transaction_id":"b91f468c-c608-4729-88d8-9a12c951c31a","url":"/","message":"A Debug Log"}

Config

// Config defines the config for library.
type Config struct {

  // Optional. Default: false
  Hidden bool

  // Optional. Default: ""
  ServiceName string

  // Optional. Default: &fiber.Ctx{}
  Context *fiber.Ctx

  // Optional. Default: log.Logger
  Logger zerolog.Logger
}

Default Config

var ConfigDefault = Config{
  Hidden:      false,
  ServiceName: "",
  Context:     nil,
  Logger:      log.Logger,
}

Dependencies

More Example Usage

Please go to example/main.go

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages