Categorygithub.com/Zbyteio/zlogger-lib
modulepackage
1.3.8
Repository: https://github.com/zbyteio/zlogger-lib.git
Documentation: pkg.go.dev

# README

zlogger-lib

  • logger instances created are of 2 types - [DEBUG]/[RELEASE]
  • instances created depends on gin mode of the code.

Default log levels

  • Error
  • Warn
  • Info
  • Debug

Usage

Fetch the latest version of zlogger-lib

GOPROXY=https://proxy.golang.org GO111MODULE=on go get github.com/Zbyteio/[email protected]

Create an app logger

  • use this logger to log throughout the library
appLogger := zlogger.NewZlogger(gin.DebugMode)

............

ZBlocksAppDebugLogger.Debugf("%s", "success print debug via applogger[DEBUG]")

Create a gin logger

  • use this logger as middleware for gin route logging
ginLogger := zlogger.NewGinLogger(gin.DebugMode)

............
ginEng := gin.New()


ginEng.Use(
    ZBlocksGinDebugLogger.GinRequestLoggerMiddleware(),
)
ginEng.GET("/abc", func(c *gin.Context) {
    c.String(http.StatusOK, "Welcome Gin Server")
})

Create a gorm logger

  • use this for replacing gorm trace logging
  • use this for logging at database level inside code
gormLogger := zlogger.NewGormLogger(gin.DebugMode)

............

ZBlocksGormDebugLogger.SetAsDefault()
db, err := gorm.Open(postgres.Open(dsn), &gorm.Config{
  Logger: ZBlocksGormDebugLogger,
})

Best Practices

[ ] Initialise only once [ ] Use as global variable in each package.

TODO

  • remove setting of gin mode, maintain local state instead
  • Add basic configurability
  • Create a top level logger that init all the loggers
  • Use factory pattern to instantiate the library
  • Gorm Logger release mode not working
  • Add custom log levels if required later

# Packages

No description provided by the author

# Functions

No description provided by the author
No description provided by the author
No description provided by the author
* loggerConfig.loggerType - debug / json * loggerName - name of the logger ("app" :default) */.
NewZloggerForTest returns a new logger and the corresponding observed logs which can be used in unit tests to verify log entries.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Constants

No description provided by the author
No description provided by the author

# Structs

No description provided by the author

# Interfaces

Logger is a logger that supports log levels, context and structured logging.

# Type aliases

No description provided by the author