add example of rotating in response to sighup
This commit is contained in:
@@ -132,6 +132,25 @@ SIGHUP. After rotating, this initiates a cleanup of old log files according
|
|||||||
to the normal rules.
|
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
|
### func (\*Logger) Write
|
||||||
``` go
|
``` 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()
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user