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:
+1
-22
@@ -1,38 +1,17 @@
|
|||||||
// +build linux
|
|
||||||
|
|
||||||
package lumberjack_test
|
package lumberjack_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
"os"
|
|
||||||
"os/signal"
|
|
||||||
"syscall"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/natefinch/lumberjack"
|
"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
|
// To use lumberjack with the standard library's log package, just pass it into
|
||||||
// the SetOutput function when your application starts.
|
// the SetOutput function when your application starts.
|
||||||
func Example() {
|
func Example() {
|
||||||
log.SetOutput(&lumberjack.Logger{
|
log.SetOutput(&lumberjack.Logger{
|
||||||
Dir: "/var/log/myapp/",
|
Dir: "/var/log/myapp/",
|
||||||
NameFormat: time.RFC822 + ".log",
|
NameFormat: "2006-01-02T15-04-05.000.log",
|
||||||
MaxSize: lumberjack.Gigabyte,
|
MaxSize: lumberjack.Gigabyte,
|
||||||
MaxBackups: 3,
|
MaxBackups: 3,
|
||||||
MaxAge: 28,
|
MaxAge: 28,
|
||||||
|
|||||||
@@ -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()
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user