mirror of
https://github.com/onyx-and-iris/bible.git
synced 2026-09-15 07:32:34 +00:00
log levels now configurable. defaults to info.
This commit is contained in:
@@ -53,8 +53,8 @@ Example .env:
|
||||
BIBLE_API_KEY="<api-key>"
|
||||
BIBLE_BIBLE_NAME="New King James Version"
|
||||
BIBLE_BOOK_NAME='Genesis'
|
||||
BIBLE_ENDPOINT='https://rest.api.bible'
|
||||
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]
|
||||
|
||||
@@ -5,6 +5,7 @@ from loguru import logger
|
||||
from typing_extensions import override
|
||||
|
||||
from bible.api import BibleAPI
|
||||
from bible.logging import configure_logging
|
||||
from bible.settings import settings
|
||||
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',
|
||||
group='Connection',
|
||||
)
|
||||
log_level: str = arg(
|
||||
settings.LOG_LEVEL,
|
||||
help='The log level for the Bible CLI',
|
||||
group='Connection',
|
||||
)
|
||||
|
||||
@final
|
||||
@classmethod
|
||||
@@ -34,6 +40,8 @@ class BibleCli(Command):
|
||||
@override
|
||||
async def pre_run_hook(self):
|
||||
"""Hook to run before the main command execution."""
|
||||
|
||||
configure_logging(self.log_level)
|
||||
init_db()
|
||||
|
||||
key = 'bibles:list'
|
||||
|
||||
@@ -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())
|
||||
@@ -8,6 +8,7 @@ class Settings(BaseSettings):
|
||||
API_KEY: str
|
||||
CACHE_EXPIRY_DAYS: int = 30
|
||||
THEME: str = 'dark'
|
||||
LOG_LEVEL: str = 'info'
|
||||
|
||||
model_config = SettingsConfigDict(
|
||||
env_file='.env',
|
||||
|
||||
@@ -9,6 +9,7 @@ from textual.theme import Theme
|
||||
from textual.widgets import Footer, Header, Input, Link, Static
|
||||
|
||||
from bible.api import BibleAPI
|
||||
from bible.logging import configure_logging
|
||||
from bible.render import generate_summary, render_chapter, render_verse
|
||||
from bible.settings import settings
|
||||
from bible.sqlite import cache_json, get_cached, init_db, load_json
|
||||
@@ -305,10 +306,18 @@ class BibleTUI(App):
|
||||
def parse_args() -> argparse.Namespace:
|
||||
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(
|
||||
'--log-level',
|
||||
type=str,
|
||||
help='Specify the log level (e.g., info, debug, warning)',
|
||||
)
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
def main():
|
||||
args = parse_args()
|
||||
|
||||
configure_logging(args.log_level or settings.LOG_LEVEL)
|
||||
|
||||
app = BibleTUI(theme_override=args.theme)
|
||||
app.run()
|
||||
|
||||
Reference in New Issue
Block a user