sx_log.py 754 B

12345678910111213141516171819202122232425
  1. # coding=utf-8
  2. # Powered by SoaringNova Technology Company
  3. import datetime
  4. import sys
  5. def format_print():
  6. class GeneralWriter:
  7. def __init__(self, *writers):
  8. self.writers = writers
  9. def write(self, buf):
  10. now = datetime.datetime.now()
  11. ts = '{},{}'.format(now.strftime('%Y-%m-%d %H:%M:%S'), '%03d' % (now.microsecond // 1000))
  12. for w in self.writers:
  13. for line in buf.rstrip().splitlines():
  14. msg = line.rstrip()
  15. if len(msg):
  16. w.write('\033[1;32;1m{}| {}\033[0m\n'.format(ts, msg))
  17. def flush(self):
  18. pass
  19. sys.stdout = GeneralWriter(sys.stdout)
  20. sys.stderr = GeneralWriter(sys.stdout)