File: log.py

package info (click to toggle)
serpento 0.3.6
  • links: PTS
  • area: main
  • in suites: woody
  • size: 292 kB
  • ctags: 381
  • sloc: python: 1,644; ansic: 666; perl: 157; sh: 116; makefile: 72
file content (25 lines) | stat: -rw-r--r-- 569 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
25
import time, sys

class Log:

    def __init__(self, logfile=None):
        if logfile:
            self.logfile = open(logfile, "a")
        else:
            self.logfile = sys.stderr
        
    def log(self, text):
        self.logfile.write(text+"\n")
        self.logfile.flush()

    def logr(self, ip, command): # time, ip, command
        t = time.time()
        line = "%s %s %s" % (time.ctime(t), ip, command)
        self.log(line)
        
    def closelog(self):
        self.logfile.close()

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