Add logging control
This commit is contained in:
parent
96ade1c1d7
commit
f0d3cd5bdf
9 changed files with 164 additions and 24 deletions
|
@ -2,7 +2,7 @@ package notifier
|
|||
|
||||
import (
|
||||
"github.com/jouir/pgterminate/base"
|
||||
"log"
|
||||
"github.com/jouir/pgterminate/log"
|
||||
)
|
||||
|
||||
// Console notifier structure
|
||||
|
@ -19,11 +19,13 @@ func NewConsole(sessions chan base.Session) Notifier {
|
|||
|
||||
// Run starts console notifier
|
||||
func (c *Console) Run() {
|
||||
log.Info("Starting console notifier")
|
||||
for session := range c.sessions {
|
||||
log.Printf("%s", session)
|
||||
log.Infof("%s\n", session)
|
||||
}
|
||||
}
|
||||
|
||||
// Reload for handling SIGHUP signals
|
||||
func (c *Console) Reload() {
|
||||
log.Info("Reloading console notifier")
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package notifier
|
|||
import (
|
||||
"fmt"
|
||||
"github.com/jouir/pgterminate/base"
|
||||
"github.com/jouir/pgterminate/log"
|
||||
"log/syslog"
|
||||
)
|
||||
|
||||
|
@ -44,6 +45,7 @@ func NewSyslog(facility string, ident string, sessions chan base.Session) Notifi
|
|||
|
||||
// Run starts syslog notifier
|
||||
func (s *Syslog) Run() {
|
||||
log.Info("Starting syslog notifier")
|
||||
var err error
|
||||
if s.writer, err = syslog.New(s.priority, s.ident); err != nil {
|
||||
base.Panic(err)
|
||||
|
@ -56,7 +58,9 @@ func (s *Syslog) Run() {
|
|||
// Reload disconnect from syslog daemon and re-connect
|
||||
// Executed when receiving SIGHUP signal
|
||||
func (s *Syslog) Reload() {
|
||||
log.Info("Reloading syslog notifier")
|
||||
if s.writer != nil {
|
||||
log.Debug("Re-connecting to syslog daemon")
|
||||
s.disconnect()
|
||||
s.connect()
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue