From 922e68651287ab2fd9ef3721bf761d00c108b905 Mon Sep 17 00:00:00 2001 From: Nate Finch Date: Mon, 16 Jun 2014 07:19:10 -0400 Subject: [PATCH] add example of rotating in response to sighup --- README.md | 19 +++++++++++++++++++ example_test.go | 27 +++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 example_test.go diff --git a/README.md b/README.md index e837af0..7c30ee1 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/example_test.go b/example_test.go new file mode 100644 index 0000000..0561464 --- /dev/null +++ b/example_test.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() + } + }() +}