swaglog.py: respect LOGPRINT env variable (#22950)
* swaglog.py: respect LOGPRINT env variable * only change handler that prints * keep usefull manager prints * only print running list * revert process changes * fix testpull/22969/head
parent
140c7f430c
commit
77b334a698
|
@ -11,6 +11,7 @@ from common.xattr import getxattr
|
|||
|
||||
from selfdrive.loggerd.tests.loggerd_tests_common import UploaderTestCase
|
||||
|
||||
|
||||
class TestLogHandler(logging.Handler):
|
||||
def __init__(self):
|
||||
logging.Handler.__init__(self)
|
||||
|
@ -22,7 +23,7 @@ class TestLogHandler(logging.Handler):
|
|||
|
||||
def emit(self, record):
|
||||
try:
|
||||
j = json.loads(record.message)
|
||||
j = json.loads(record.getMessage())
|
||||
if j["event"] == "upload_success":
|
||||
self.upload_order.append(j["key"])
|
||||
if j["event"] == "upload_ignored":
|
||||
|
@ -33,6 +34,7 @@ class TestLogHandler(logging.Handler):
|
|||
log_handler = TestLogHandler()
|
||||
cloudlog.addHandler(log_handler)
|
||||
|
||||
|
||||
class TestUploader(UploaderTestCase):
|
||||
def setUp(self):
|
||||
super(TestUploader, self).setUp()
|
||||
|
|
|
@ -149,9 +149,10 @@ def manager_thread():
|
|||
|
||||
started_prev = started
|
||||
|
||||
running_list = ["%s%s\u001b[0m" % ("\u001b[32m" if p.proc.is_alive() else "\u001b[31m", p.name)
|
||||
for p in managed_processes.values() if p.proc]
|
||||
cloudlog.debug(' '.join(running_list))
|
||||
running = ' '.join(["%s%s\u001b[0m" % ("\u001b[32m" if p.proc.is_alive() else "\u001b[31m", p.name)
|
||||
for p in managed_processes.values() if p.proc])
|
||||
print(running)
|
||||
cloudlog.debug(running)
|
||||
|
||||
# send managerState
|
||||
msg = messaging.new_message('managerState')
|
||||
|
|
|
@ -106,7 +106,17 @@ def add_file_handler(log):
|
|||
cloudlog = log = SwagLogger()
|
||||
log.setLevel(logging.DEBUG)
|
||||
|
||||
|
||||
outhandler = logging.StreamHandler()
|
||||
|
||||
print_level = os.environ.get('LOGPRINT', 'warning')
|
||||
if print_level == 'debug':
|
||||
outhandler.setLevel(logging.DEBUG)
|
||||
elif print_level == 'info':
|
||||
outhandler.setLevel(logging.INFO)
|
||||
elif print_level == 'warning':
|
||||
outhandler.setLevel(logging.WARNING)
|
||||
|
||||
log.addHandler(outhandler)
|
||||
# logs are sent through IPC before writing to disk to prevent disk I/O blocking
|
||||
log.addHandler(UnixDomainSocketHandler(SwagFormatter(log)))
|
||||
|
|
Loading…
Reference in New Issue