golog

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2020 License: MIT Imports: 8 Imported by: 0

README

#usage

use standard log

package main

import (
	"log"

	"github.com/astrophor/golog"
)

func main() {
	golog.NewStdLog("./", "test", "", uint64(1)<<20, 1)
	log.Println("this is standard log")
}

use zap

package main

import (
	"github.com/astrophor/golog"
	"go.uber.org/zap"
)

func main() {
	logger := golog.NewZapLog("./", "zap_test", "", uint64(1)<<20, 1)

	logger.Info("this is a info log",
		zap.String("place_id", "test"),
		zap.Int("value", 12))
}

Documentation

Overview

Package golog provides a rolling logger.

golog plays well with any logging package that can write to an io.Writer, including the standard library's log package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewStdLog

func NewStdLog(logPath, logPrefix, logNameTimeFormat string, maxSize uint64, rotateInterval int)

NewStdLog initialize standard log using LogWriter.

func NewZapLog

func NewZapLog(logPath, logPrefix, logNameTimeFormat string, maxSize uint64, rotateInterval int) *zap.Logger

NewZapLog initialize zap log using LogWriter.

Types

type LogWriter

type LogWriter struct {
	// contains filtered or unexported fields
}

LogWriter is an io.WriteCloser that writes logs to rotate files.

func New

func New(logPath, logPrefix, logNameTimeFormat string, maxSize uint64, rotateInterval int) *LogWriter

New returns an initialized LogWriter.

func (*LogWriter) Close

func (l *LogWriter) Close() error

Close implements io.Closer.

func (*LogWriter) Write

func (l *LogWriter) Write(p []byte) (n int, err error)

Write implements io.Writer. if the length of the writes is greater than maxSize, an error is returned if a write would cause the log file to be larger than maxSize, it will rotate to a new file if current time reaches rotate interval, it also will rotate to a new file if compress is set, old file will compress using gzip

Jump to

Keyboard shortcuts

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