File: log_simple_module.py

package info (click to toggle)
pyftpd 0.8.1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 524 kB
  • ctags: 448
  • sloc: python: 2,748; sh: 80; makefile: 43
file content (24 lines) | stat: -rw-r--r-- 661 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import time, sys

class Log:

    def openlog(self):
        from log_simple_config import *
        if not logfile:
            if sys.platform[:3] == 'win':
                logfile = "c:/pyftpd.log"
            else:
                logfile = "/tmp/pyftpd.log"
        self.logfile = open(logfile, "a")
        
    def log(self, t, user, ip, command, boe): # time, who, ip, command, beginning=0 or end=1
        line = "%s %s@%s %s %i\n" % (time.ctime(t), user, ip, command, boe)
        self.logfile.write(line)
        self.logfile.flush()

    def closelog(self):
        self.logfile.close()

    def __del__(self):
        self.logfile.close()