2
0

add example of rotating in response to sighup

This commit is contained in:
Nate Finch
2014-06-16 07:19:10 -04:00
parent 35a206f7bd
commit 922e686512
2 changed files with 46 additions and 0 deletions
+19
View File
@@ -132,6 +132,25 @@ SIGHUP. After rotating, this initiates a cleanup of old log files according
to the normal rules.
#### Example
Example of how to rotate in response to SIGHUP.
Code:
l := &lumberjack.Logger{}
log.SetOutput(l)
c := make(chan os.Signal, 1)
signal.Notify(c, syscall.SIGHUP)
go func() {
for {
<-c
l.Rotate()
}
}()
### func (\*Logger) Write
``` go
+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()
}
}()
}