github.com/v2pro/plz@v0.0.0-20221028024117-e5f9aec5b631/countlog/output/lumberjack/rotate_test.go (about)

     1  // +build linux
     2  
     3  package lumberjack_test
     4  
     5  import (
     6  	"log"
     7  	"os"
     8  	"os/signal"
     9  	"syscall"
    10  
    11  	"gopkg.in/natefinch/lumberjack.v2"
    12  )
    13  
    14  // Example of how to rotate in response to SIGHUP.
    15  func ExampleLogger_Rotate() {
    16  	l := &lumberjack.Logger{}
    17  	log.SetOutput(l)
    18  	c := make(chan os.Signal, 1)
    19  	signal.Notify(c, syscall.SIGHUP)
    20  
    21  	go func() {
    22  		for {
    23  			<-c
    24  			l.Rotate()
    25  		}
    26  	}()
    27  }