forked from phacops/server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogger.go
More file actions
36 lines (29 loc) · 998 Bytes
/
logger.go
File metadata and controls
36 lines (29 loc) · 998 Bytes
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
package server
import (
"fmt"
"log"
)
type Logger interface {
Print(sessionId string, message interface{})
Printf(sessionId string, format string, v ...interface{})
PrintCommand(sessionId string, command string, params string)
PrintResponse(sessionId string, code int, message string)
}
// Use an instance of this to log in a standard format
type StdLogger struct{}
func (logger *StdLogger) Print(sessionId string, message interface{}) {
log.Printf("%s %s", sessionId, message)
}
func (logger *StdLogger) Printf(sessionId string, format string, v ...interface{}) {
logger.Print(sessionId, fmt.Sprintf(format, v...))
}
func (logger *StdLogger) PrintCommand(sessionId string, command string, params string) {
if command == "PASS" {
log.Printf("%s > PASS ****", sessionId)
} else {
log.Printf("%s > %s %s", sessionId, command, params)
}
}
func (logger *StdLogger) PrintResponse(sessionId string, code int, message string) {
log.Printf("%s < %d %s", sessionId, code, message)
}