relogger

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2020 License: MIT Imports: 10 Imported by: 0

README

go-relogger

Go Report Card license

Overview

go-relogger is a logger that supports to reopen logging file when traps signal or is passed a time interval. It can use to the logrotate(current logging file moves to an other logging file with suffix).

Because a logger prints previous logging file until logger reopens.

Getting Started

package main
import (   
   "os"
   "time"
   "github.com/gjbae1212/go-relogger"
)

func main() {
   logger, err := NewReLogger("your-log-path", relogger.WithSignals([]os.Signal{
   	                                           syscall.SIGHUP}), 
                                               relogger.WithRefreshDuration(time.Hour))   
}

LICENSE

This project is following The MIT.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidParams presents an invalid error.
	ErrInvalidParams = errors.New("[err] invalid params")
)

Functions

This section is empty.

Types

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option is to use dependency injection.

type OptionFunc

type OptionFunc func(l *ReLogger)

func WithFileMode

func WithFileMode(mode os.FileMode) OptionFunc

WithFileMode returns the func which sets file mode.

func WithPrintableDebug

func WithPrintableDebug(debug bool) OptionFunc

WithPrintableDebug returns the func which sets bool to check whether debug or not.

func WithRefreshDuration

func WithRefreshDuration(d time.Duration) OptionFunc

WithRefreshDuration returns the func which sets an interval for refreshing logger.

func WithSignals

func WithSignals(signals []os.Signal) OptionFunc

WithSignals returns the func which traps kill signal.

type ReLogger

type ReLogger struct {
	log.Logger
	// contains filtered or unexported fields
}

ReLogger is a custom logger to support refresh file using an interval or signal.

func NewReLogger

func NewReLogger(filepath string, opts ...Option) (*ReLogger, error)

NewReLogger returns a logger.

Jump to

Keyboard shortcuts

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