-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
69 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
--- | ||
major: 2 | ||
minor: 8 | ||
patch: 0 | ||
patch: 1 | ||
entry: runtimepy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
""" | ||
A module implementing a logger-mixin extension. | ||
""" | ||
|
||
# built-in | ||
import logging | ||
|
||
# third-party | ||
from vcorelib.logging import LoggerMixin | ||
|
||
# internal | ||
from runtimepy.channel.environment import ChannelEnvironment | ||
from runtimepy.enum.registry import RuntimeIntEnum | ||
|
||
|
||
class LogLevel(RuntimeIntEnum): | ||
"""A runtime enumeration for log level.""" | ||
|
||
DEBUG = logging.DEBUG | ||
INFO = logging.INFO | ||
WARNING = logging.WARNING | ||
ERROR = logging.ERROR | ||
CRITICAL = logging.CRITICAL | ||
|
||
|
||
class LoggerMixinLevelControl(LoggerMixin): | ||
"""A logger mixin that exposes a runtime-controllable level.""" | ||
|
||
def _log_level_changed(self, _: int, new_value: int) -> None: | ||
"""Handle a change in log level.""" | ||
|
||
self.logger.setLevel(new_value) | ||
self.logger.info("Log level set to '%s'.") | ||
|
||
def setup_level_channel( | ||
self, | ||
env: ChannelEnvironment, | ||
name: str = "log_level", | ||
initial: str = "info", | ||
) -> None: | ||
"""Add a commandable log-level channel to the environment.""" | ||
|
||
chan = env.int_channel( | ||
name, enum=LogLevel.register_enum(env.enums), commandable=True | ||
) | ||
|
||
# Set up change handler. | ||
chan[0].raw.register_callback(self._log_level_changed) | ||
|
||
# Set the initial log level. | ||
env.set(name, initial) | ||
|
||
del chan |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters