summaryrefslogtreecommitdiff
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
parent2ad3efe73fbd5df58ae77ec411121575547f0e11 (diff)
Cleanup some logging setup code
I think the calls to Log.setup() were accidentally creating multiple loggers, hopefully this fixes the problem.
-rw-r--r--Biz/PodcastItLater/Billing.py4
-rw-r--r--Biz/PodcastItLater/Core.py4
-rw-r--r--Biz/PodcastItLater/Web.py4
-rw-r--r--Biz/PodcastItLater/Worker.py4
-rwxr-xr-xBiz/Storybook.py3
-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
10 files changed, 27 insertions, 17 deletions
diff --git a/Biz/PodcastItLater/Billing.py b/Biz/PodcastItLater/Billing.py
index de3540b..7746f79 100644
--- a/Biz/PodcastItLater/Billing.py
+++ b/Biz/PodcastItLater/Billing.py
@@ -10,6 +10,7 @@ Stripe subscription management and usage enforcement.
# : dep pytest-mock
import Biz.PodcastItLater.Core as Core
import json
+import logging
import Omni.App as App
import Omni.Log as Log
import Omni.Test as Test
@@ -20,7 +21,8 @@ import typing
from datetime import datetime
from datetime import timezone
-logger = Log.setup()
+logger = logging.getLogger(__name__)
+Log.setup(logger)
# Stripe configuration
stripe.api_key = os.getenv("STRIPE_SECRET_KEY", "")
diff --git a/Biz/PodcastItLater/Core.py b/Biz/PodcastItLater/Core.py
index 42a4df2..1339a7d 100644
--- a/Biz/PodcastItLater/Core.py
+++ b/Biz/PodcastItLater/Core.py
@@ -10,8 +10,8 @@ Includes:
# : dep pytest
# : dep pytest-asyncio
# : dep pytest-mock
+import logging
import Omni.App as App
-import Omni.Log as Log
import Omni.Test as Test
import os
import pathlib
@@ -25,7 +25,7 @@ from collections.abc import Iterator
from contextlib import contextmanager
from typing import Any
-logger = Log.setup()
+logger = logging.getLogger(__name__)
CODEROOT = pathlib.Path(os.getenv("CODEROOT", "."))
diff --git a/Biz/PodcastItLater/Web.py b/Biz/PodcastItLater/Web.py
index 697b92c..5ae2571 100644
--- a/Biz/PodcastItLater/Web.py
+++ b/Biz/PodcastItLater/Web.py
@@ -23,6 +23,7 @@ import Biz.PodcastItLater.Core as Core
import Biz.PodcastItLater.UI as UI
import html as html_module
import httpx
+import logging
import ludic.html as html
import Omni.App as App
import Omni.Log as Log
@@ -51,7 +52,8 @@ from starlette.responses import RedirectResponse
from starlette.testclient import TestClient
from typing import override
-logger = Log.setup()
+logger = logging.getLogger(__name__)
+Log.setup(logger)
# Configuration
diff --git a/Biz/PodcastItLater/Worker.py b/Biz/PodcastItLater/Worker.py
index 2807e8a..202e512 100644
--- a/Biz/PodcastItLater/Worker.py
+++ b/Biz/PodcastItLater/Worker.py
@@ -16,6 +16,7 @@ import boto3 # type: ignore[import-untyped]
import concurrent.futures
import io
import json
+import logging
import Omni.App as App
import Omni.Log as Log
import Omni.Test as Test
@@ -40,7 +41,8 @@ from pathlib import Path
from pydub import AudioSegment # type: ignore[import-untyped]
from typing import Any
-logger = Log.setup()
+logger = logging.getLogger(__name__)
+Log.setup(logger)
# Configuration from environment variables
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
diff --git a/Biz/Storybook.py b/Biz/Storybook.py
index 57b84c6..164e845 100755
--- a/Biz/Storybook.py
+++ b/Biz/Storybook.py
@@ -56,7 +56,8 @@ PORT = int(os.environ.get("PORT", "3000"))
area = App.from_env()
app = ludic.web.LudicApp(debug=area == App.Area.Test)
-log = Log.setup(logging.DEBUG if area == App.Area.Test else logging.ERROR)
+log = logging.getLogger(__name__)
+Log.setup(log, logging.DEBUG if area == App.Area.Test else logging.ERROR)
Sqids = sqids.Sqids()
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