fix: File logging config
This commit is contained in:
parent
dc1ce2ac46
commit
6efd3457ce
3 changed files with 6 additions and 3 deletions
|
|
@ -1,6 +1,6 @@
|
|||
logging:
|
||||
level: "TRACE"
|
||||
path: "logs/karl.log"
|
||||
path: "../../logs/karl.log"
|
||||
app:
|
||||
host: "127.0.0.1"
|
||||
port: 8081
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ from pydantic_settings import BaseSettings, SettingsConfigDict
|
|||
|
||||
class LoggingConfig(BaseModel):
|
||||
level: str = "INFO"
|
||||
path: Path = Path("logs/karl.log")
|
||||
path: Path | None = None
|
||||
|
||||
|
||||
class AppConfig(BaseModel):
|
||||
|
|
|
|||
|
|
@ -68,7 +68,9 @@ class HandlerFactory:
|
|||
|
||||
def file_handler(prefix: str = ''):
|
||||
if not file_path:
|
||||
raise ValueError("File path must be set.")
|
||||
import sys
|
||||
sys.stderr.write("No file path specified, skipping file logging...")
|
||||
return None
|
||||
file_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
file_path.touch(exist_ok=True)
|
||||
handler = TimedRotatingFileHandler(file_path, when='midnight', backupCount=30)
|
||||
|
|
@ -87,4 +89,5 @@ class HandlerFactory:
|
|||
handlers.append(console_handler(handler_prefix))
|
||||
case _:
|
||||
raise ValueError(f"Unknown target: {target}")
|
||||
handlers = [h for h in handlers if h is not None]
|
||||
return handlers
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue