log levels now configurable. defaults to info.

This commit is contained in:
2026-09-15 08:23:45 +01:00
parent 6e5fd427f7
commit 8a3647fcb6
5 changed files with 34 additions and 1 deletions
+1 -1
View File
@@ -53,8 +53,8 @@ Example .env:
BIBLE_API_KEY="<api-key>" BIBLE_API_KEY="<api-key>"
BIBLE_BIBLE_NAME="New King James Version" BIBLE_BIBLE_NAME="New King James Version"
BIBLE_BOOK_NAME='Genesis' BIBLE_BOOK_NAME='Genesis'
BIBLE_ENDPOINT='https://rest.api.bible'
BIBLE_THEME="onyx-light" BIBLE_THEME="onyx-light"
BIBLE_LOG_LEVEL="info"
``` ```
> Note, although cache expiry days is configurable it should NOT be set above 30 days, as per the terms and conditions of the API. See [Acceptable Use][acceptable-use] > Note, although cache expiry days is configurable it should NOT be set above 30 days, as per the terms and conditions of the API. See [Acceptable Use][acceptable-use]
+8
View File
@@ -5,6 +5,7 @@ from loguru import logger
from typing_extensions import override from typing_extensions import override
from bible.api import BibleAPI from bible.api import BibleAPI
from bible.logging import configure_logging
from bible.settings import settings from bible.settings import settings
from bible.sqlite import cache_json, get_cached, init_db from bible.sqlite import cache_json, get_cached, init_db
@@ -25,6 +26,11 @@ class BibleCli(Command):
help='The name of the Bible to retrieve books from', help='The name of the Bible to retrieve books from',
group='Connection', group='Connection',
) )
log_level: str = arg(
settings.LOG_LEVEL,
help='The log level for the Bible CLI',
group='Connection',
)
@final @final
@classmethod @classmethod
@@ -34,6 +40,8 @@ class BibleCli(Command):
@override @override
async def pre_run_hook(self): async def pre_run_hook(self):
"""Hook to run before the main command execution.""" """Hook to run before the main command execution."""
configure_logging(self.log_level)
init_db() init_db()
key = 'bibles:list' key = 'bibles:list'
+15
View File
@@ -0,0 +1,15 @@
import sys
from loguru import logger
VALID_LEVELS = {'TRACE', 'DEBUG', 'INFO', 'SUCCESS', 'WARNING', 'ERROR', 'CRITICAL'}
def configure_logging(level: str):
if level.upper() not in VALID_LEVELS:
raise ValueError(
f'Invalid log level: {level}. Valid levels are: {", ".join(VALID_LEVELS)}'
)
logger.remove()
logger.add(sys.stderr, level=level.upper())
+1
View File
@@ -8,6 +8,7 @@ class Settings(BaseSettings):
API_KEY: str API_KEY: str
CACHE_EXPIRY_DAYS: int = 30 CACHE_EXPIRY_DAYS: int = 30
THEME: str = 'dark' THEME: str = 'dark'
LOG_LEVEL: str = 'info'
model_config = SettingsConfigDict( model_config = SettingsConfigDict(
env_file='.env', env_file='.env',
+9
View File
@@ -9,6 +9,7 @@ from textual.theme import Theme
from textual.widgets import Footer, Header, Input, Link, Static from textual.widgets import Footer, Header, Input, Link, Static
from bible.api import BibleAPI from bible.api import BibleAPI
from bible.logging import configure_logging
from bible.render import generate_summary, render_chapter, render_verse from bible.render import generate_summary, render_chapter, render_verse
from bible.settings import settings from bible.settings import settings
from bible.sqlite import cache_json, get_cached, init_db, load_json from bible.sqlite import cache_json, get_cached, init_db, load_json
@@ -305,10 +306,18 @@ class BibleTUI(App):
def parse_args() -> argparse.Namespace: def parse_args() -> argparse.Namespace:
parser = argparse.ArgumentParser(description='Bible TUI — interact with Bible.API') parser = argparse.ArgumentParser(description='Bible TUI — interact with Bible.API')
parser.add_argument('--theme', type=str, help='Specify the theme (light or dark)') parser.add_argument('--theme', type=str, help='Specify the theme (light or dark)')
parser.add_argument(
'--log-level',
type=str,
help='Specify the log level (e.g., info, debug, warning)',
)
return parser.parse_args() return parser.parse_args()
def main(): def main():
args = parse_args() args = parse_args()
configure_logging(args.log_level or settings.LOG_LEVEL)
app = BibleTUI(theme_override=args.theme) app = BibleTUI(theme_override=args.theme)
app.run() app.run()