Add logging control

This commit is contained in:
Julien Riou 2018-06-24 17:49:48 +02:00
commit f0d3cd5bdf
No known key found for this signature in database
GPG key ID: BA3E15176E45E85D
9 changed files with 164 additions and 24 deletions

View file

@ -2,7 +2,7 @@ package notifier
import (
"github.com/jouir/pgterminate/base"
"log"
"github.com/jouir/pgterminate/log"
"os"
"sync"
"time"
@ -26,6 +26,7 @@ func NewFile(name string, sessions chan base.Session) Notifier {
// Run starts the file notifier
func (f *File) Run() {
log.Info("Starting file notifier")
f.open()
defer f.terminate()
@ -45,15 +46,16 @@ func (f *File) open() {
// Reload closes and re-open the file to be compatible with logrotate
func (f *File) Reload() {
log.Info("Reloading file notifier")
f.mutex.Lock()
defer f.mutex.Unlock()
log.Println("Re-opening log file", f.name)
log.Debugf("Re-opening log file %s\n", f.name)
f.handle.Close()
f.open()
}
// terminate closes the file
func (f *File) terminate() {
log.Println("Closing log file", f.name)
log.Debugf("Closing log file %s\n", f.name)
f.handle.Close()
}