|
|
@ -124,6 +124,25 @@ class Log: |
|
|
|
After each write, ``flush()`` is called as well. |
|
|
|
After each write, ``flush()`` is called as well. |
|
|
|
""" |
|
|
|
""" |
|
|
|
self.indent = 0 |
|
|
|
self.indent = 0 |
|
|
|
|
|
|
|
self._limit = -1 |
|
|
|
|
|
|
|
self.filtered = 0 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def limit(self, log_limit): |
|
|
|
|
|
|
|
class Limiter: |
|
|
|
|
|
|
|
def __init__(self, l): self.l = l |
|
|
|
|
|
|
|
def __enter__(self): self.l.start_limit(log_limit); return self |
|
|
|
|
|
|
|
def __exit__(self, *args): self.l.stop_limit() |
|
|
|
|
|
|
|
return Limiter(self) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def start_limit(self, limit): |
|
|
|
|
|
|
|
self.filtered = 0 |
|
|
|
|
|
|
|
self._limit = limit |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def stop_limit(self): |
|
|
|
|
|
|
|
if self.filtered > 0: |
|
|
|
|
|
|
|
log.info(f'{self.filtered} more messages (filtered).') |
|
|
|
|
|
|
|
self.filtered = 0 |
|
|
|
|
|
|
|
self._limit = -1 |
|
|
|
|
|
|
|
|
|
|
|
def __getstate__(self): |
|
|
|
def __getstate__(self): |
|
|
|
return {'elapsed': time.perf_counter() - self.start} |
|
|
|
return {'elapsed': time.perf_counter() - self.start} |
|
|
@ -146,9 +165,13 @@ class Log: |
|
|
|
def ie(self, n=1): self.indent -= n |
|
|
|
def ie(self, n=1): self.indent -= n |
|
|
|
|
|
|
|
|
|
|
|
def log(self, level, message): |
|
|
|
def log(self, level, message): |
|
|
|
|
|
|
|
if self._limit == 0: |
|
|
|
|
|
|
|
self.filtered += 1 |
|
|
|
|
|
|
|
return |
|
|
|
t = time.perf_counter() - self.start |
|
|
|
t = time.perf_counter() - self.start |
|
|
|
self.logfile.write(f'# {t:011.3f} {level} {message}\n') |
|
|
|
self.logfile.write(f'# {t:011.3f} {level} {message}\n') |
|
|
|
self.logfile.flush() |
|
|
|
self.logfile.flush() |
|
|
|
|
|
|
|
self._limit -= 1 |
|
|
|
|
|
|
|
|
|
|
|
def info(self, message): |
|
|
|
def info(self, message): |
|
|
|
"""Log an informational message.""" |
|
|
|
"""Log an informational message.""" |
|
|
|