forked from yob/graval
-
Notifications
You must be signed in to change notification settings - Fork 8
/
ftplogger.go
52 lines (45 loc) · 1023 Bytes
/
ftplogger.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
40
41
42
43
44
45
46
47
48
49
50
51
52
package graval
import (
"fmt"
"log"
"strings"
)
// Use an instance of this to log in a standard format
type ftpLogger struct {
sessionId string
quiet bool
}
func newFtpLogger(id string, quiet bool) *ftpLogger {
l := new(ftpLogger)
l.sessionId = id
l.quiet = quiet
return l
}
func (logger *ftpLogger) Print(message interface{}) {
if logger.quiet {
return
}
log.Printf("%s %s", logger.sessionId, message)
}
func (logger *ftpLogger) Printf(format string, v ...interface{}) {
if logger.quiet {
return
}
logger.Print(fmt.Sprintf(format, v...))
}
func (logger *ftpLogger) PrintCommand(command string, params string) {
if logger.quiet {
return
}
if command == "PASS" {
log.Printf("%s > PASS ****", logger.sessionId)
} else {
log.Printf("%s > %s %s", logger.sessionId, command, params)
}
}
func (logger *ftpLogger) PrintResponse(code int, message string) {
if logger.quiet {
return
}
log.Printf("%s < %d %s", logger.sessionId, code, strings.Replace(message, "\r\n", "\\r\\n", -1))
}