Skip to content

ephemeralsnow/go-file-rotatelogs

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-file-rotatelogs

Build Status

Port of File::RotateLogs from Perl to Go.

When you integrate this to to you app, it automatically write to logs that are rotated from within the app: No more disk-full alerts because you forgot to setup logrotate!

To install, simply issue a go get:

go get github.com/lestrrat/go-file-rotatelogs

It's normally expected that this library is used with the built-in log library, so that everything your app produces goes through this library:

import(
    "log"
    "github.com/lestrrat/go-file-rotatelogs"
)
  
func main() {
    rl := rotatelogs.NewRotateLogs(
        "/path/to/access_log.%Y%m%d%H%M",
    )

    // Optional fields must be set afterwards
    rl.LinkName     = "/path/to/access_log"
    rl.RotationTime = 3600 * time.Second
    rl.MaxAge       = 86400 * time.Second
    rl.Offset       = 0

    log.SetOutput(rl)

    /* elsewhere ... */
    log.Printf("Hello, World!")
}

OPTIONS

LogFile (Required)

The pattern used to generate actual log file names. You should use patterns using the strftime (3) format. For example:

"/var/log/myapp/log.%Y%m%d"

LinkName

Path where a symlink for the actual log file is placed. This allows you to always check at the same location for log files even if the logs were rotated

rl.LinkName = "/var/log/myapp/current"

// Else where
$ tail -f /var/log/myapp/current

RotationTime (default: 86400 sec)

Interval between file rotation. By default logs are rotated every 86400 seconds. Note: Remember to use time.Duration values. 86400 seconds must be written as:

rl.RotationTime = 86400 * time.Second

MaxAge (default: 0)

Time to wait until old logs are purged. By default no logs are purged, which certainly isn't what you want. Note: Remember to use time.Duration values. 86400 seconds must be written as:

rl.MaxAge = 86400 * time.Second

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 100.0%