mirror of
https://github.com/drakkan/sftpgo.git
synced 2025-12-07 14:50:55 +03:00
Refactor the logging system
* created a "Log" function for type "Connection" * created a "log" function for type "Provider" * replace logger calls to Log/log where possible I also renamed PGSSQL to PGSQL, as this seemed to be a typo Signed-off-by: Jo Vandeginste <Jo.Vandeginste@kuleuven.be>
This commit is contained in:
@@ -232,7 +232,7 @@ func (c Configuration) AcceptInboundConnection(conn net.Conn, config *ssh.Server
|
||||
lock: new(sync.Mutex),
|
||||
sshConn: sconn,
|
||||
}
|
||||
logger.Info(logSender, connectionID, "User id: %d, logged in with: %#v, name: %#v, home_dir: %#v",
|
||||
connection.Log(Info, logSender, "User id: %d, logged in with: %#v, name: %#v, home_dir: %#v",
|
||||
user.ID, loginType, user.Username, user.HomeDir)
|
||||
|
||||
go ssh.DiscardRequests(reqs)
|
||||
@@ -241,14 +241,14 @@ func (c Configuration) AcceptInboundConnection(conn net.Conn, config *ssh.Server
|
||||
// If its not a session channel we just move on because its not something we
|
||||
// know how to handle at this point.
|
||||
if newChannel.ChannelType() != "session" {
|
||||
logger.Debug(logSender, connectionID, "received an unknown channel type: %v", newChannel.ChannelType())
|
||||
connection.Log(Debug, logSender, "received an unknown channel type: %v", newChannel.ChannelType())
|
||||
newChannel.Reject(ssh.UnknownChannelType, "unknown channel type")
|
||||
continue
|
||||
}
|
||||
|
||||
channel, requests, err := newChannel.Accept()
|
||||
if err != nil {
|
||||
logger.Warn(logSender, connectionID, "could not accept a channel: %v", err)
|
||||
connection.Log(Warn, logSender, "could not accept a channel: %v", err)
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -270,7 +270,7 @@ func (c Configuration) AcceptInboundConnection(conn net.Conn, config *ssh.Server
|
||||
var msg execMsg
|
||||
if err := ssh.Unmarshal(req.Payload, &msg); err == nil {
|
||||
name, scpArgs, err := parseCommandPayload(msg.Command)
|
||||
logger.Debug(logSender, connectionID, "new exec command: %v args: %v user: %v, error: %v", name, scpArgs,
|
||||
connection.Log(Debug, logSender, "new exec command: %v args: %v user: %v, error: %v", name, scpArgs,
|
||||
connection.User.Username, err)
|
||||
if err == nil && name == "scp" && len(scpArgs) >= 2 {
|
||||
ok = true
|
||||
@@ -300,10 +300,10 @@ func (c Configuration) handleSftpConnection(channel io.ReadWriteCloser, connecti
|
||||
server := sftp.NewRequestServer(channel, handler)
|
||||
|
||||
if err := server.Serve(); err == io.EOF {
|
||||
logger.Debug(logSender, connection.ID, "connection closed")
|
||||
connection.Log(Debug, logSenderSCP, "connection closed")
|
||||
server.Close()
|
||||
} else if err != nil {
|
||||
logger.Error(logSender, connection.ID, "sftp connection closed with error: %v", err)
|
||||
connection.Log(Error, logSenderSCP, "sftp connection closed with error: %v", err)
|
||||
}
|
||||
|
||||
removeConnection(connection.ID)
|
||||
|
||||
Reference in New Issue
Block a user