zaprotatelogger

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 6, 2023 License: MIT Imports: 6 Imported by: 1

README

zap-rotate-logger

Provide an zap logger instance with lumberjack which helps to auto rotate file once it's size breached.

HOW TO USE


package main

import (
	zrl "github.com/pnkj-kmr/zap-rotate-logger"
)

func main() {
	logger := zrl.New(
		zrl.WithFileName("app"),
		zrl.WithMaxSize(1),
		zrl.WithMaxAge(60),
		zrl.WithMaxBackups(30),
		zrl.WithCompress(true),
		zrl.WithDebug(true),
	)

	for i := 0; i < 100; i++ {
		logger.Info("testing...")
	}
}

DESCRIPTION


When you integrate this to into your app, it automatically write to logs into current working directory (path-to-app/log/xyz.log) and rotate the new log file as you configured: No-more file rotation, No-more disk size full. To setup the zap-roate-logger!

To install, simply do a go get:

go get https://github.com/pnkj-kmr/zap-rotate-logger

OPTIONS


WithFileName (DEFAULT: app)

The WithFileName used to define log file name. For example:

  zrl.WithFileName("app_name")
WithMaxSize (DEFAULT: 1)

The WithMaxSize is the maximum size in megabytes of the log file before it gets rotated. It defaults to 1 megabytes.

  zrl.WithMaxSize(1)
WithMaxAge (DEFAULT: 30)

The WithMaxAge is the maximum number of days to retain old log files based on the timestamp encoded in their filename. Note that a day is defined as 24 hours and may not exactly correspond to calendar days due to daylight savings, leap seconds, etc. The default is not to remove old log files based on age.

  zrl.WithMaxAge(30)
WithMaxBackups (DEFAULT: 30)

The WithMaxBackups is the maximum number of old log files to retain. The default is to retain all old log files (though MaxAge may still cause them to get deleted.)

  zrl.WithMaxBackups(30)
WithCompress (DEFAULT: false)

The WithCompress determines if the rotated log files should be compressed using gzip.

  zrl.WithCompress(true)
WithDebug (DEFAULT: false)

The WithDebug is used for application log devel. For example:

  zrl.WithDebug(true)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(options ...option.Option) *zap.Logger

New func returns a zap logger instance along with the lumberjack file log rotator

func WithCompress

func WithCompress(s bool) option.Option

WithCompress determines if the rotated log files should be compressed using gzip. The default is not to perform compression.

func WithDebug

func WithDebug(s bool) option.Option

WithDebug application log devel

func WithFileName

func WithFileName(s string) option.Option

WithFileName is the file to write logs to. Backup log files will be retained in the same directory. It uses <processname>-lumberjack.log in os.TempDir() if empty.

func WithMaxAge

func WithMaxAge(s int) option.Option

WithMaxAge is the maximum number of days to retain old log files based on the timestamp encoded in their filename. Note that a day is defined as 24 hours and may not exactly correspond to calendar days due to daylight savings, leap seconds, etc. The default is not to remove old log files based on age.

func WithMaxBackups

func WithMaxBackups(s int) option.Option

WithMaxBackups is the maximum number of old log files to retain. The default is to retain all old log files (though MaxAge may still cause them to get deleted.)

func WithMaxSize

func WithMaxSize(s int) option.Option

WithMaxSize is the maximum size in megabytes of the log file before it gets rotated. It defaults to 100 megabytes.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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