Manage log destination explicitly
This commit is contained in:
parent
85207e0a77
commit
96ade1c1d7
4 changed files with 14 additions and 6 deletions
|
@ -26,6 +26,7 @@ type Config struct {
|
||||||
ConnectTimeout int `yaml:"connect-timeout"`
|
ConnectTimeout int `yaml:"connect-timeout"`
|
||||||
IdleTimeout float64 `yaml:"idle-timeout"`
|
IdleTimeout float64 `yaml:"idle-timeout"`
|
||||||
ActiveTimeout float64 `yaml:"active-timeout"`
|
ActiveTimeout float64 `yaml:"active-timeout"`
|
||||||
|
LogDestination string `yaml:"log-destination"`
|
||||||
LogFile string `yaml:"log-file"`
|
LogFile string `yaml:"log-file"`
|
||||||
PidFile string `yaml:"pid-file"`
|
PidFile string `yaml:"pid-file"`
|
||||||
SyslogIdent string `yaml:"syslog-ident"`
|
SyslogIdent string `yaml:"syslog-ident"`
|
||||||
|
|
|
@ -35,6 +35,7 @@ func main() {
|
||||||
flag.IntVar(&config.ConnectTimeout, "connect-timeout", 3, "Connection timeout in seconds")
|
flag.IntVar(&config.ConnectTimeout, "connect-timeout", 3, "Connection timeout in seconds")
|
||||||
flag.Float64Var(&config.IdleTimeout, "idle-timeout", 0, "Time for idle connections to be terminated in seconds")
|
flag.Float64Var(&config.IdleTimeout, "idle-timeout", 0, "Time for idle connections to be terminated in seconds")
|
||||||
flag.Float64Var(&config.ActiveTimeout, "active-timeout", 0, "Time for active connections to be terminated in seconds")
|
flag.Float64Var(&config.ActiveTimeout, "active-timeout", 0, "Time for active connections to be terminated in seconds")
|
||||||
|
flag.StringVar(&config.LogDestination, "log-destination", "console", "Log destination between 'console', 'syslog' or 'file'")
|
||||||
flag.StringVar(&config.LogFile, "log-file", "", "Write logs to a file")
|
flag.StringVar(&config.LogFile, "log-file", "", "Write logs to a file")
|
||||||
flag.StringVar(&config.PidFile, "pid-file", "", "Write process id into a file")
|
flag.StringVar(&config.PidFile, "pid-file", "", "Write process id into a file")
|
||||||
flag.StringVar(&config.SyslogIdent, "syslog-ident", "pgterminate", "Define syslog tag")
|
flag.StringVar(&config.SyslogIdent, "syslog-ident", "pgterminate", "Define syslog tag")
|
||||||
|
@ -66,7 +67,11 @@ func main() {
|
||||||
log.Fatalln("Parameter -active-timeout or -idle-timeout required")
|
log.Fatalln("Parameter -active-timeout or -idle-timeout required")
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.SyslogFacility != "" {
|
if config.LogDestination != "console" && config.LogDestination != "file" && config.LogDestination != "syslog" {
|
||||||
|
log.Fatalln("Log destination must be 'console', 'file' or 'syslog'")
|
||||||
|
}
|
||||||
|
|
||||||
|
if config.LogDestination == "syslog" && config.SyslogFacility != "" {
|
||||||
matched, err := regexp.MatchString("^LOCAL[0-7]$", config.SyslogFacility)
|
matched, err := regexp.MatchString("^LOCAL[0-7]$", config.SyslogFacility)
|
||||||
base.Panic(err)
|
base.Panic(err)
|
||||||
if !matched {
|
if !matched {
|
||||||
|
|
|
@ -9,5 +9,6 @@ idle-timeout: 300
|
||||||
active-timeout: 10
|
active-timeout: 10
|
||||||
log-file: /var/log/pgterminate/pgterminate.log
|
log-file: /var/log/pgterminate/pgterminate.log
|
||||||
pid-file: /var/run/pgterminate/pgterminate.pid
|
pid-file: /var/run/pgterminate/pgterminate.pid
|
||||||
|
#log-destination: console|file|syslog
|
||||||
#syslog-ident: pgterminate
|
#syslog-ident: pgterminate
|
||||||
#syslog-facility: LOCAL0
|
#syslog-facility: LOCAL0
|
||||||
|
|
|
@ -10,14 +10,15 @@ type Notifier interface {
|
||||||
Reload()
|
Reload()
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewNotifier looks into Config to create a File or Console notifier and pass it
|
// NewNotifier looks into Config to create a Console, File or Syslog notifier and pass it
|
||||||
// the session channel for consuming sessions structs sent by terminator
|
// the session channel for consuming sessions structs sent by terminator
|
||||||
func NewNotifier(ctx *base.Context) Notifier {
|
func NewNotifier(ctx *base.Context) Notifier {
|
||||||
if ctx.Config.LogFile != "" {
|
switch ctx.Config.LogDestination {
|
||||||
|
case "file":
|
||||||
return NewFile(ctx.Config.LogFile, ctx.Sessions)
|
return NewFile(ctx.Config.LogFile, ctx.Sessions)
|
||||||
}
|
case "syslog":
|
||||||
if ctx.Config.SyslogFacility != "" {
|
|
||||||
return NewSyslog(ctx.Config.SyslogFacility, ctx.Config.SyslogIdent, ctx.Sessions)
|
return NewSyslog(ctx.Config.SyslogFacility, ctx.Config.SyslogIdent, ctx.Sessions)
|
||||||
|
default: // console
|
||||||
|
return NewConsole(ctx.Sessions)
|
||||||
}
|
}
|
||||||
return NewConsole(ctx.Sessions)
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue