8000 GitHub - 0x676e67/vlog at v1.0.1
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

0x676e67/vlog

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

vlog

vlog implements io.Writer to roll and compress log file time every day, and encapsulate the use of Golang native log library

Overview

  • implements io.Writer. You can easily use in golang log, GORM, grpclog etc.
  • daily roll log, you can specific the log file name's prefix, default is process name
  • compress to gz for old file

Getting Started

Example

To use vlog, you can:

go get github.com/zf1976/vlog@latest

and import like this:

package main

import (
	"github.com/zf1976/vlog"
	"github.com/zf1976/vlog/timewriter"
)

func main() {
	timeWriter := &timewriter.TimeWriter{
		Dir:           "./logs",
		Compress:      true,
		ReserveDay:    30,
		LogFilePrefix: "vlog",
	}
	log := vlog.New(timeWriter)
	log.Info("hello vlog")
}

If you need to set the output globally:

package main

import (
	"github.com/zf1976/vlog"
	"github.com/zf1976/vlog/timewriter"
	"io"
	"os"
)

func main() {
	timeWriter := &timewriter.TimeWriter{
		Dir:           "./logs",
		Compress:      true,
		ReserveDay:    30,
		LogFilePrefix: "vlog",
	}
	w := io.MultiWriter(os.Stdout, timeWriter)
	vlog.SetOutput(w)
	// global settings
	logger := vlog.Default()
	logger.Info("hello vlog")
}

If you need to set the output globally and synchronize to the default log library:

package main

import (
	"github.com/zf1976/vlog"
	"github.com/zf1976/vlog/timewriter"
	"io"
	"log"
	"os"
)

func main() {
	timeWriter := &timewriter.TimeWriter{
		Dir:           "./logs",
		Compress:      true,
		ReserveDay:    30,
		LogFilePrefix: "vlog",
	}
	w := io.MultiWriter(os.Stdout, timeWriter)
	// global settings
	vlog.SetSyncOutput(true)
	vlog.SetOutput(w)
	logger := vlog.Default()
	logger.Info("hello vlog")
	log.Println("hello vlog")
}

Reference

About

Golang log library Encapsulation

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

0