aboutsummaryrefslogtreecommitdiff
path: root/releng/__init__.py
diff options
context:
space:
mode:
authorjade <lix@jade.fyi>2024-06-15 02:38:09 +0000
committerGerrit Code Review <gerrit@localhost>2024-06-15 02:38:09 +0000
commite1059bfa34b2f9e780ae2d13021c6bef66f34599 (patch)
tree887869e9cdc90df1eeeec59fb31d93ac36ce39c2 /releng/__init__.py
parent068576042b3b58f8180b24a36c07199a1a3fd380 (diff)
parentd5c670ad0175fe2a9279784f2acacae4ba7b3828 (diff)
Merge changes from topic "releng" into main
* changes: releng: add sha256 for the manual tarball releng: fix upload of multiarch images to forgejo releng: fix git checking releng: fix logging inside interactive xonsh releng: support multiple systems version: update to 2.90.0-rc1
Diffstat (limited to 'releng/__init__.py')
-rw-r--r--releng/__init__.py62
1 files changed, 51 insertions, 11 deletions
diff --git a/releng/__init__.py b/releng/__init__.py
index 59d1709b9..179ea3e2b 100644
--- a/releng/__init__.py
+++ b/releng/__init__.py
@@ -1,8 +1,12 @@
from xonsh.main import setup
+
setup()
del setup
import logging
+import sys
+
+import xonsh.base_shell
from . import environment
from . import create_release
@@ -13,19 +17,55 @@ from . import docker
from . import docker_assemble
from . import gitutils
-rootLogger = logging.getLogger()
-rootLogger.setLevel(logging.DEBUG)
-log = logging.getLogger(__name__)
-log.setLevel(logging.DEBUG)
-fmt = logging.Formatter('{asctime} {levelname} {name}: {message}',
- datefmt='%b %d %H:%M:%S',
- style='{')
+def setup_logging():
+ """
+ Sets up logging to work properly. The following are intended to work:
+ - ipython/xonsh configuration files adding log handlers out of band
+ - Reloading the module in xonsh/ipython not causing Bonus Loggers (which is
+ why we check if there is already a handler. This also helps the previous
+ case)
+ - Importing the releng module from xonsh and poking at it interactively
+ """
+
+ LEVELS = {
+ # Root logger must be DEBUG so that anything else can be DEBUG
+ None: logging.DEBUG,
+ # Everything in releng
+ __name__: logging.DEBUG,
+ # Log spam caused by prompt_toolkit
+ 'asyncio': logging.INFO,
+ }
+
+ for name, level in LEVELS.items():
+ logger = logging.getLogger(name)
+ logger.setLevel(level)
+
+ root_logger = logging.getLogger()
+
+ fmt = logging.Formatter('{asctime} {levelname} {name}: {message}',
+ datefmt='%b %d %H:%M:%S',
+ style='{')
+
+ if not any(
+ isinstance(h, logging.StreamHandler) for h in root_logger.handlers):
+ stderr = sys.stderr
+ # XXX: Horrible hack required by the virtual stderr xonsh uses for each entered
+ # command getting closed after the command is run: we need to pull out
+ # the real stderr because this survives across multiple command runs.
+ #
+ # This only applies when running xonsh in interactive mode and importing releng.
+ if isinstance(sys.stderr, xonsh.base_shell._TeeStd):
+ stderr = stderr.std # type: ignore
+
+ hand = logging.StreamHandler(stream=stderr)
+ hand.set_name('releng root handler')
+ hand.setFormatter(fmt)
+ root_logger.addHandler(hand)
+
+
+setup_logging()
-if not any(isinstance(h, logging.StreamHandler) for h in rootLogger.handlers):
- hand = logging.StreamHandler()
- hand.setFormatter(fmt)
- rootLogger.addHandler(hand)
def reload():
import importlib