Skip to content
This repository was archived by the owner on Feb 19, 2019. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion filelog.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (w *FileLogWriter) LogWrite(rec *LogRecord) {

func (w *FileLogWriter) Close() {
close(w.rec)
w.file.Sync()
w.file.Sync() //The file can be closed properly, this is not necessary
}

// NewFileLogWriter creates a new LogWriter which writes to the given file and
Expand Down Expand Up @@ -81,6 +81,7 @@ func NewFileLogWriter(fname string, rotate bool) *FileLogWriter {
fmt.Fprint(w.file, FormatLogRecord(w.trailer, &LogRecord{Created: time.Now()}))
w.file.Close()
}
wg.Done()
}()

for {
Expand Down
4 changes: 4 additions & 0 deletions log4go.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import (
"runtime"
"strings"
"time"
"sync"
)

// Version information
Expand Down Expand Up @@ -81,6 +82,7 @@ const (
// Logging level strings
var (
levelStrings = [...]string{"FNST", "FINE", "DEBG", "TRAC", "INFO", "WARN", "EROR", "CRIT"}
wg sync.WaitGroup
)

func (l Level) String() string {
Expand Down Expand Up @@ -165,10 +167,12 @@ func NewDefaultLogger(lvl Level) Logger {
// all filters (and thus all LogWriters) from the logger.
func (log Logger) Close() {
// Close all open loggers
wg.Add(len(log))
for name, filt := range log {
filt.Close()
delete(log, name)
}
wg.Wait()
}

// Add a new LogWriter to the Logger which will only log messages at lvl or
Expand Down
1 change: 1 addition & 0 deletions pattlog.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ func (w FormatLogWriter) run(out io.Writer, format string) {
for rec := range w {
fmt.Fprint(out, FormatLogRecord(format, rec))
}
wg.Done()
}

// This is the FormatLogWriter's output method. This will block if the output
Expand Down
1 change: 1 addition & 0 deletions socklog.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func NewSocketLogWriter(proto, hostport string) SocketLogWriter {
if sock != nil && proto == "tcp" {
sock.Close()
}
wg.Done()
}()

for rec := range w {
Expand Down
2 changes: 1 addition & 1 deletion termlog.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func (c *ConsoleLogWriter) run(out io.Writer) {
for rec := range c.w {
fmt.Fprint(out, FormatLogRecord(c.format, rec))
}
wg.Done()
}

// This is the ConsoleLogWriter's output method. This will block if the output
Expand All @@ -45,5 +46,4 @@ func (c *ConsoleLogWriter) LogWrite(rec *LogRecord) {
// send log messages to this logger after a Close have undefined behavior.
func (c *ConsoleLogWriter) Close() {
close(c.w)
time.Sleep(50 * time.Millisecond) // Try to give console I/O time to complete
}