From d4187366d3d9ebc50ba09246620c8a7e4ab67717 Mon Sep 17 00:00:00 2001 From: Nate Finch Date: Tue, 24 Jun 2014 08:50:20 -0400 Subject: [PATCH] Update example to not use a filename that causes problems on windows and split out rotate example into its own file, since it's the only thing that is linux-only --- example_test.go | 23 +---------------------- rotate_test.go | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 22 deletions(-) create mode 100644 rotate_test.go diff --git a/example_test.go b/example_test.go index d2abe68..d085ac4 100644 --- a/example_test.go +++ b/example_test.go @@ -1,38 +1,17 @@ -// +build linux - package lumberjack_test import ( "log" - "os" - "os/signal" - "syscall" - "time" "github.com/natefinch/lumberjack" ) -// Example of how to rotate in response to SIGHUP. -func ExampleLogger_Rotate() { - l := &lumberjack.Logger{} - log.SetOutput(l) - c := make(chan os.Signal, 1) - signal.Notify(c, syscall.SIGHUP) - - go func() { - for { - <-c - l.Rotate() - } - }() -} - // To use lumberjack with the standard library's log package, just pass it into // the SetOutput function when your application starts. func Example() { log.SetOutput(&lumberjack.Logger{ Dir: "/var/log/myapp/", - NameFormat: time.RFC822 + ".log", + NameFormat: "2006-01-02T15-04-05.000.log", MaxSize: lumberjack.Gigabyte, MaxBackups: 3, MaxAge: 28, diff --git a/rotate_test.go b/rotate_test.go new file mode 100644 index 0000000..0561464 --- /dev/null +++ b/rotate_test.go @@ -0,0 +1,27 @@ +// +build linux + +package lumberjack_test + +import ( + "log" + "os" + "os/signal" + "syscall" + + "github.com/natefinch/lumberjack" +) + +// Example of how to rotate in response to SIGHUP. +func ExampleLogger_Rotate() { + l := &lumberjack.Logger{} + log.SetOutput(l) + c := make(chan os.Signal, 1) + signal.Notify(c, syscall.SIGHUP) + + go func() { + for { + <-c + l.Rotate() + } + }() +}