-
Notifications
You must be signed in to change notification settings - Fork 1
/
logger_basic.go
39 lines (32 loc) · 894 Bytes
/
logger_basic.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package middleware
import (
"log"
"net"
"os"
)
// BasicLogger implements the Logger interface and the NCSA_HTTPd log format.
type BasicLogger struct {
logger *log.Logger
}
// NewBasicLogger returns a new instance of a basic server access logger.
func NewBasicLogger() Logger {
return &BasicLogger{
logger: log.New(os.Stdout, "", log.LstdFlags),
}
}
// ListeningOn implements the ListeningOn method for the Logger interface.
func (l BasicLogger) ListeningOn(addr net.Addr) {
l.logger.Println("listening on", addr)
}
// Shutdown implements the Shutdown method for the Logger interface.
func (l BasicLogger) Shutdown(err error) {
if err != nil {
l.logger.Fatalf("server closed (err=%s)", err)
return
}
l.logger.Println("server closed", "(ok)")
}
// Log implements the Log method for the Logger interface.
func (l BasicLogger) Log(data AccessLog) {
l.logger.Println(data)
}