File: log.py

package info (click to toggle)
serpento 0.4.1-0.2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 360 kB
  • ctags: 391
  • sloc: python: 1,762; ansic: 669; perl: 157; sh: 127; makefile: 73
file content (25 lines) | stat: -rw-r--r-- 599 bytes parent folder | download | duplicates (2)
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):
        t = time.localtime()
        line = "%s %s\n" % (time.strftime("%Y-%m-%d %H:%M:%S", t), text)
        self.logfile.write(line)
        self.logfile.flush()

    def logr(self, ip, command): # ip, command
        self.log("%s: %s" % (ip, command))
        
    def closelog(self):
        self.logfile.close()

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