rclone/vendor/goftp.io/server/logger.go

61 lines
1.9 KiB
Go
Raw Normal View History

2018-09-14 18:16:54 +02:00
// 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 server
import (
"fmt"
"log"
)
2020-06-27 16:45:12 +02:00
// Logger represents an interface to record all ftp information and command
2018-09-14 18:16:54 +02:00
type Logger interface {
2020-06-27 16:45:12 +02:00
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)
2018-09-14 18:16:54 +02:00
}
2020-06-27 16:45:12 +02:00
// StdLogger use an instance of this to log in a standard format
2018-09-14 18:16:54 +02:00
type StdLogger struct{}
2020-06-27 16:45:12 +02:00
// Print impelment Logger
func (logger *StdLogger) Print(sessionID string, message interface{}) {
log.Printf("%s %s", sessionID, message)
2018-09-14 18:16:54 +02:00
}
2020-06-27 16:45:12 +02:00
// Printf impelment Logger
func (logger *StdLogger) Printf(sessionID string, format string, v ...interface{}) {
logger.Print(sessionID, fmt.Sprintf(format, v...))
2018-09-14 18:16:54 +02:00
}
2020-06-27 16:45:12 +02:00
// PrintCommand impelment Logger
func (logger *StdLogger) PrintCommand(sessionID string, command string, params string) {
2018-09-14 18:16:54 +02:00
if command == "PASS" {
2020-06-27 16:45:12 +02:00
log.Printf("%s > PASS ****", sessionID)
2018-09-14 18:16:54 +02:00
} else {
2020-06-27 16:45:12 +02:00
log.Printf("%s > %s %s", sessionID, command, params)
2018-09-14 18:16:54 +02:00
}
}
2020-06-27 16:45:12 +02:00
// PrintResponse impelment Logger
func (logger *StdLogger) PrintResponse(sessionID string, code int, message string) {
log.Printf("%s < %d %s", sessionID, code, message)
2018-09-14 18:16:54 +02:00
}
2020-06-27 16:45:12 +02:00
// DiscardLogger represents a silent logger, produces no output
2018-09-14 18:16:54 +02:00
type DiscardLogger struct{}
2020-06-27 16:45:12 +02:00
// Print impelment Logger
func (logger *DiscardLogger) Print(sessionID string, message interface{}) {}
// Printf impelment Logger
func (logger *DiscardLogger) Printf(sessionID string, format string, v ...interface{}) {}
// PrintCommand impelment Logger
func (logger *DiscardLogger) PrintCommand(sessionID string, command string, params string) {}
// PrintResponse impelment Logger
func (logger *DiscardLogger) PrintResponse(sessionID string, code int, message string) {}