2
0

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

This commit is contained in:
Nate Finch
2014-06-24 08:50:20 -04:00
parent 8ec9c6b748
commit d4187366d3
2 changed files with 28 additions and 22 deletions
+1 -22
View File
@@ -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,
+27
View File
@@ -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()
}
}()
}