Skip to content

Commit

Permalink
stepreporter: Add new StepLogger
Browse files Browse the repository at this point in the history
Signed-off-by: Rouven Czerwinski <[email protected]>
  • Loading branch information
Emantor committed Apr 27, 2023
1 parent 3a05a53 commit 01c826b
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions labgrid/stepreporter.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from logging import getLogger

from .step import steps


Expand Down Expand Up @@ -36,3 +38,27 @@ def notify(event):
step = event.step
indent = ' '*step.level
print(f"{indent}{event}")


class StepLogger:
instance = None

def __init__(self):
self.logger = getLogger("StepLogger")
steps.subscribe(self.notify)

@classmethod
def start(cls):
"""starts the StepLogger"""
assert cls.instance is None
cls.instance = cls()

@classmethod
def stop(cls):
"""stops the StepLogger"""
assert cls.instance is not None
steps.unsubscribe(cls.notify)
cls.instance = None

def notify(self, event):
self.logger.log(15, event)

0 comments on commit 01c826b

Please sign in to comment.