Skip to content
This repository has been archived by the owner on Dec 1, 2022. It is now read-only.
/ gzlog Public archive

A logging package that compresses log files when opened or written to if the size exceeds the set max size

License

Notifications You must be signed in to change notification settings

gochan-org/gzlog

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gzlog

A logging package that compresses log files when opened or written to if the size exceeds the set max size

Usage

Creating a new log file

basename := "logs/logfile"
maxSize := 5 * 1000 * 1000 // 5 MB
fileMode := 0644
// do not include the extension in basename, gzlog will create basename.log or
// basename.#.log as necessary if it does not exist, or append new lines to it
// if its size < maxSize
gcl, err := gzlog.OpenFile(basename, maxSize, fileMode)
if err != nil {
	panic(err)
}
defer gzlog.Close()
str, err := gcl.Println("Receiving new HTTP request from", "8.8.8.8")
if err != nil {
	panic(err)
}
fmt.Println(str) // prints "Receiving new HTTP request from 8.8.8.8" (without quotes)
logText, err := gcl.ReadAllString() // contains all the contents of the current log file, including prefixes
if err != nil {
	panic(err)
}
doSomethingWith(logText)

Importing an already existing log file

gcl, err := ImportFile(os.Stdout, "", 0)
if err != nil {
	panic(err)
}

About

A logging package that compresses log files when opened or written to if the size exceeds the set max size

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages