py.lib

Yohn Y. 2022-07-17 Parent:b8fc22566efd

30:fe4a96d06243 Go to Latest

py.lib/log/tiny_slog.py

. Используем в логах monotonic вместо time

History
     1.1 --- a/log/tiny_slog.py	Sun Jul 17 22:21:37 2022 +0300
     1.2 +++ b/log/tiny_slog.py	Sun Jul 17 22:26:31 2022 +0300
     1.3 @@ -10,7 +10,7 @@
     1.4    "#": Alert
     1.5  
     1.6  """
     1.7 -from time import time
     1.8 +from time import monotonic
     1.9  from datetime import timedelta
    1.10  
    1.11  import syslog
    1.12 @@ -24,23 +24,23 @@
    1.13              self.prefix = ''
    1.14          else:
    1.15              self.prefix = '%s :: ' % name
    1.16 -        self.tsAll = time()
    1.17 +        self.tsAll = monotonic()
    1.18          self.ts = self.tsAll
    1.19  
    1.20      def getTime(self):
    1.21 -        return time() - self.ts
    1.22 +        return monotonic() - self.ts
    1.23  
    1.24      def reset(self):
    1.25 -        self.ts = time()
    1.26 +        self.ts = monotonic()
    1.27          self.tsAll = self.ts
    1.28  
    1.29      def __str__(self):
    1.30 -        ts = time()
    1.31 +        ts = monotonic()
    1.32          return self.prefix + '%s(%.4f)' % (timedelta(seconds=(ts - self.tsAll)), ts - self.ts)
    1.33  
    1.34      def __call__(self, msg):
    1.35          _buf = '%s | %s' % (self, msg)
    1.36 -        self.ts = time()
    1.37 +        self.ts = monotonic()
    1.38          return _buf
    1.39  
    1.40