Added time display for stdout and stderr

This commit is contained in:
zhaoyafan 2025-02-22 00:46:15 +08:00
parent e72962c951
commit bf8aa6c514
1 changed files with 14 additions and 4 deletions

View File

@ -1624,7 +1624,7 @@ class BrowserManager:
run = BrowserManagerUserRunning(running) run = BrowserManagerUserRunning(running)
run.update_status_running() run.update_status_running()
if run.is_running and run.driver is None: if run.is_running and run.driver is None:
self.user_run(user_id) threading.Thread(target=self.user_run, args=(user_id,)).start()
print('Restoring user control: %s' % (user_id,), file=sys.stderr) print('Restoring user control: %s' % (user_id,), file=sys.stderr)
def load_plugins(self, plugins, is_external=0): def load_plugins(self, plugins, is_external=0):
@ -2247,9 +2247,17 @@ class OutputRedirector:
def __init__(self, sys_fp, new_fp): def __init__(self, sys_fp, new_fp):
self.sys_fp = sys_fp self.sys_fp = sys_fp
self.new_fp = new_fp self.new_fp = new_fp
self.time_format = ''
@staticmethod
def time():
return '[%s]\n' % (time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()),)
def write(self, s): def write(self, s):
self.sys_fp.write(s) self.sys_fp.write(s)
if (self.time_format != self.time()) == 1:
self.time_format = self.time()
self.new_fp.write(self.time_format)
self.new_fp.write(s) self.new_fp.write(s)
self.flush() self.flush()
@ -2315,9 +2323,11 @@ class MainRunner:
def run(self): def run(self):
os.path.exists(self.app_data) or os.makedirs(self.app_data) os.path.exists(self.app_data) or os.makedirs(self.app_data)
if (os.environ.get('PYCHARM_HOSTED') is None) == 1: if (os.environ.get('PYCHARM_HOSTED_ANY_TIME') is None) == 1:
stdout_redirector = OutputRedirector(sys.stdout, open(os.path.join(self.app_data, '%s_stdout.txt' % (time.strftime('%Y%m%d', time.localtime()),)), mode='a')) log_dir = os.path.join(self.app_data, 'log')
stderr_redirector = OutputRedirector(sys.stderr, open(os.path.join(self.app_data, '%s_stderr.txt' % (time.strftime('%Y%m%d', time.localtime()),)), mode='a')) os.path.exists(log_dir) or os.makedirs(log_dir)
stdout_redirector = OutputRedirector(sys.stdout, open(os.path.join(log_dir, '%s_stdout.log' % (time.strftime('%Y%m%d', time.localtime()),)), mode='a'))
stderr_redirector = OutputRedirector(sys.stderr, open(os.path.join(log_dir, '%s_stderr.log' % (time.strftime('%Y%m%d', time.localtime()),)), mode='a'))
sys.stderr = stderr_redirector sys.stderr = stderr_redirector
sys.stdout = stdout_redirector sys.stdout = stdout_redirector
sys.path.append(os.path.join(os.path.dirname(__file__), 'Packages')) sys.path.append(os.path.join(os.path.dirname(__file__), 'Packages'))