-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogger.go
60 lines (47 loc) · 1.89 KB
/
logger.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
53
54
55
56
57
58
59
60
// Copyright 2018 The goftp Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package ftp
import (
"fmt"
"log"
)
// Logger represents an interface to record all ftp information and command
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)
}
// StdLogger use an instance of this to log in a standard format
type StdLogger struct{}
// Print implements Logger
func (logger *StdLogger) Print(sessionID string, message interface{}) {
log.Printf("%s %s", sessionID, message)
}
// Printf implements Logger
func (logger *StdLogger) Printf(sessionID string, format string, v ...interface{}) {
logger.Print(sessionID, fmt.Sprintf(format, v...))
}
// PrintCommand implements Logger
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)
}
}
// PrintResponse implements Logger
func (logger *StdLogger) PrintResponse(sessionID string, code int, message string) {
log.Printf("%s < %d %s", sessionID, code, message)
}
// DiscardLogger represents a silent logger, produces no output
type DiscardLogger struct{}
// Print implements Logger
func (logger *DiscardLogger) Print(sessionID string, message interface{}) {}
// Printf implements Logger
func (logger *DiscardLogger) Printf(sessionID string, format string, v ...interface{}) {}
// PrintCommand implements Logger
func (logger *DiscardLogger) PrintCommand(sessionID string, command string, params string) {}
// PrintResponse implements Logger
func (logger *DiscardLogger) PrintResponse(sessionID string, code int, message string) {}