Add log-format option

This commit is contained in:
Julien Riou 2019-02-16 11:47:30 +01:00
commit 24eb4fe203
No known key found for this signature in database
GPG key ID: BA3E15176E45E85D
9 changed files with 61 additions and 44 deletions

View file

@ -1,25 +1,28 @@
package notifier
import (
"github.com/jouir/pgterminate/base"
"github.com/jouir/pgterminate/log"
"os"
"sync"
"time"
"github.com/jouir/pgterminate/base"
"github.com/jouir/pgterminate/log"
)
// File structure for file notifier
type File struct {
handle *os.File
format string
name string
sessions chan *base.Session
mutex sync.Mutex
}
// NewFile creates a file notifier
func NewFile(name string, sessions chan *base.Session) Notifier {
func NewFile(format string, name string, sessions chan *base.Session) Notifier {
return &File{
name: name,
format: format,
sessions: sessions,
}
}
@ -32,7 +35,7 @@ func (f *File) Run() {
for session := range f.sessions {
timestamp := time.Now().Format(time.RFC3339)
_, err := f.handle.WriteString(timestamp + " " + session.String() + "\n")
_, err := f.handle.WriteString(timestamp + " " + session.Format(f.format) + "\n")
base.Panic(err)
}
}