summaryrefslogtreecommitdiff
path: root/Omni
diff options
context:
space:
mode:
authorBen Sima <ben@bsima.me>2025-11-12 21:20:07 -0500
committerBen Sima <ben@bsima.me>2025-11-13 11:20:14 -0500
commitc018d2dd1d7e7f1cc19b25f6ec74b3dec44ae9b9 (patch)
treea8c0748068f00449bd175aa953eb1acd7027fa65 /Omni
parent2ad3efe73fbd5df58ae77ec411121575547f0e11 (diff)
Cleanup some logging setup code
I think the calls to Log.setup() were accidentally creating multiple loggers, hopefully this fixes the problem.
Diffstat (limited to 'Omni')
-rwxr-xr-xOmni/Bild/Example.py6
-rwxr-xr-xOmni/Llamacpp.py5
-rw-r--r--Omni/Log.py6
-rwxr-xr-xOmni/Repl.py5
-rw-r--r--Omni/Test.py3
5 files changed, 14 insertions, 11 deletions
diff --git a/Omni/Bild/Example.py b/Omni/Bild/Example.py
index 7d57890..1b2f61d 100755
--- a/Omni/Bild/Example.py
+++ b/Omni/Bild/Example.py
@@ -8,12 +8,14 @@ Example Python file that also serves as a test case for bild.
# : out example
# : dep cryptography
import cryptography.fernet
+import logging
import Omni.App as App
import Omni.Log as Log
import Omni.Test as Test
import sys
-log = Log.setup()
+logger = logging.getLogger(__name__)
+Log.setup(logger)
def cryptic_hello(name: str) -> str:
@@ -28,7 +30,7 @@ def cryptic_hello(name: str) -> str:
key = cryptography.fernet.Fernet.generate_key()
f = cryptography.fernet.Fernet(key)
token = f.encrypt(hello(name).encode("utf-8"))
- log.info("attempting decryption")
+ logger.info("attempting decryption")
ret = f.decrypt(token).decode("utf-8")
if ret != hello(name):
msg = "en/decryption failed!"
diff --git a/Omni/Llamacpp.py b/Omni/Llamacpp.py
index bf44d5e..c7e9078 100755
--- a/Omni/Llamacpp.py
+++ b/Omni/Llamacpp.py
@@ -9,7 +9,7 @@ sure llama-cpp still works in case I need/want to switch at some point.
# : out llamacpp-test
# : run llama-cpp
-
+import logging
import Omni.App as App
import Omni.Log as Log
import Omni.Test as Test
@@ -29,7 +29,8 @@ class TestLlamaCpp(unittest.TestCase):
def main() -> None:
"""Entrypoint."""
if sys.argv[1] == "test":
- Log.setup()
+ logger = logging.getLogger(__name__)
+ Log.setup(logger)
Test.run(App.Area.Test, [TestLlamaCpp])
else:
sys.exit(0)
diff --git a/Omni/Log.py b/Omni/Log.py
index ee4a050..5b3a618 100644
--- a/Omni/Log.py
+++ b/Omni/Log.py
@@ -13,7 +13,7 @@ class LowerFormatter(logging.Formatter):
return super().format(record)
-def setup(level: int = logging.INFO) -> logging.Logger:
+def setup(logger: logging.Logger, level: int = logging.INFO) -> logging.Logger:
"""Run this in your `main()` function."""
logging.basicConfig(
level=level,
@@ -22,7 +22,6 @@ def setup(level: int = logging.INFO) -> logging.Logger:
logging.addLevelName(logging.DEBUG, "dbug")
logging.addLevelName(logging.ERROR, "fail")
logging.addLevelName(logging.INFO, "info")
- logger = logging.getLogger(__name__)
formatter = LowerFormatter()
handler = logging.StreamHandler()
handler.setFormatter(formatter)
@@ -32,5 +31,6 @@ def setup(level: int = logging.INFO) -> logging.Logger:
def main() -> None:
"""Entrypoint to test that this kinda works."""
- logger = setup()
+ logger = logging.getLogger(__name__)
+ setup(logger)
logger.debug("i am doing testing")
diff --git a/Omni/Repl.py b/Omni/Repl.py
index d7d2fb4..49b6c1e 100755
--- a/Omni/Repl.py
+++ b/Omni/Repl.py
@@ -20,8 +20,8 @@ additional files to load.
import importlib
import importlib.util
import inspect
+import logging
import mypy.api
-import Omni.Log as Log
import os
import pathlib
import pydoc
@@ -33,7 +33,7 @@ import types
import typing
import unittest
-LOG = Log.setup()
+LOG = logging.getLogger(__name__)
class ReplError(Exception):
@@ -246,7 +246,6 @@ def test() -> None:
def move() -> None:
"""Actual entrypoint."""
- Log.setup()
ns = sys.argv[1]
path = sys.argv[2]
editor = os.environ.get("EDITOR", "$EDITOR")
diff --git a/Omni/Test.py b/Omni/Test.py
index 89ef1fa..71ac32a 100644
--- a/Omni/Test.py
+++ b/Omni/Test.py
@@ -15,7 +15,8 @@ class TestError(Exception):
def run(area: App.Area, tests: list[typing.Any]) -> None:
"""Run the given tests with loglevel determined by area."""
- Log.setup(logging.DEBUG if area == App.Area.Test else logging.ERROR)
+ logger = logging.getLogger(__name__)
+ Log.setup(logger, logging.DEBUG if area == App.Area.Test else logging.ERROR)
suite = unittest.TestSuite()
suite.addTests([
unittest.defaultTestLoader.loadTestsFromTestCase(tc) for tc in tests