trading debug and ship logs

This commit is contained in:
Richard
2024-01-16 19:13:10 +01:00
parent 560ac056ff
commit 592c628a46
6 changed files with 43 additions and 27 deletions

View File

@@ -1,5 +1,5 @@
from .base import Base
from time import time
from time import time, strftime
from nullptr.util import *
from nullptr.models import Waypoint
import os
@@ -22,15 +22,18 @@ class Ship(Base):
self.frame = ''
self.speed = "CRUISE"
self._log_file = None
self._log_level = 5
def log(self, m):
def log(self, m, l=3):
if self._log_file is None:
fn = os.path.join(self.store.data_dir, f'{self.symbol}.{self.ext()}.log')
self._log_file = open(fn, 'a')
ts = int(time())
ts = strftime('%Y%m%d %H%M%S')
m = m.strip()
self._log_file.write(f'{ts} {m}\n')
self._log_file.flush()
if l <= self._log_level:
print(f'{self} {ts} {m}')
@classmethod
def ext(self):