xref: /unit/test/unit/log.py (revision 1850:839024ce4a6a)
1*1850Smax.romanov@nginx.comUNIT_LOG = 'unit.log'
2*1850Smax.romanov@nginx.com
3*1850Smax.romanov@nginx.com
4*1850Smax.romanov@nginx.comclass Log:
5*1850Smax.romanov@nginx.com    temp_dir = None
6*1850Smax.romanov@nginx.com    pos = {}
7*1850Smax.romanov@nginx.com
8*1850Smax.romanov@nginx.com    def open(name=UNIT_LOG, encoding=None):
9*1850Smax.romanov@nginx.com        f = open(Log.get_path(name), 'r', encoding=encoding, errors='ignore')
10*1850Smax.romanov@nginx.com        f.seek(Log.pos.get(name, 0))
11*1850Smax.romanov@nginx.com
12*1850Smax.romanov@nginx.com        return f
13*1850Smax.romanov@nginx.com
14*1850Smax.romanov@nginx.com    def set_pos(pos, name=UNIT_LOG):
15*1850Smax.romanov@nginx.com        Log.pos[name] = pos
16*1850Smax.romanov@nginx.com
17*1850Smax.romanov@nginx.com    def swap(name):
18*1850Smax.romanov@nginx.com        pos = Log.pos.get(UNIT_LOG, 0)
19*1850Smax.romanov@nginx.com        Log.pos[UNIT_LOG] = Log.pos.get(name, 0)
20*1850Smax.romanov@nginx.com        Log.pos[name] = pos
21*1850Smax.romanov@nginx.com
22*1850Smax.romanov@nginx.com    def get_path(name=UNIT_LOG):
23*1850Smax.romanov@nginx.com        return Log.temp_dir + '/' + name
24