Documentation ¶
Overview ¶
message from the author:
+--------------------------------------------------------------+ | * * * ░░░░░░░░░░░░░░░░░░░░ Hello ░░░░░░░░░░░░░░░░░░░░░░░░░░| +--------------------------------------------------------------+ | | | ++ ______________________________________ | | ++++ / \ | | ++++ | | | | ++++++++++ | Feel free to contribute to this | | | +++ | | project or contact me on | | | ++ | | manfred.life if you like this | | | + -== ==| | project! | | | ( <*> <*> | | | | | | /| :) | | | | _) / | | | | | +++ / \______________________________________/ | | \ =+ / | | \ + | | |\++++++ | | | ++++ ||// | | ___| |___ _||/__ __| | / --- \ \| ||| __ _ ___ __ __/ /| |/ | | \ \ / / ' \/ _ \/ // / / | || | | | | | /_/_/_/\___/\_,_/_/ | +--------------------------------------------------------------+
Example ¶
package main import ( "fmt" "moul.io/logman" ) func main() { // new log manager manager := logman.Manager{ Path: "./path/to/dir", MaxFiles: 10, } // cleanup old log files for a specific app name err := manager.Flush("my-app") checkErr(err) // cleanup old log files for any app sharing this log directory err = manager.FlushAll() checkErr(err) // list existing log files files, err := manager.Files() checkErr(err) fmt.Println(files) // - create an WriteCloser // - automatically delete old log files if it hits a limit writer, err := manager.New("my-app") checkErr(err) defer writer.Close() writer.Write([]byte("hello world!\n")) } func checkErr(err error) { if err != nil { panic(err) } }
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type File ¶ added in v1.1.0
type File struct { // Full path. Path string // Size in bytes. Size int64 // Provided name when creating the file. Name string // Creation date of the file. Time time.Time // Whether it is the most recent log file for the provided app name or not. Latest bool // If there were errors when trying to get info about this file. Errs error `json:"Errs,omitempty"` }
File defines a log file with metadata.
type Manager ¶ added in v1.1.0
type Manager struct { // Path is the target directory containing the log files. // Default is '.'. Path string // MaxFiles is the maximum number of log files in the directory. // If 0, won't automatically GC based on this criteria. MaxFiles int }
Manager is a configuration object used to create log files with automatic GC rules.
func (Manager) New ¶ added in v1.1.0
func (m Manager) New(name string) (io.WriteCloser, error)
Create a new log file and perform automatic GC of the old log files if needed.
The created log file will looks like:
<path/to/log/dir>/<name>-<time>.log
Depending on the provided configuration of Manager, an automatic GC will be run automatically.
Click to show internal directories.
Click to hide internal directories.