mirror of
https://github.com/joshuadavidthomas/django-language-server.git
synced 2025-07-22 20:05:02 +00:00
change command handler strat to function decorator (#26)
* change command handler strat to function decorator * add handlers back to agent class
This commit is contained in:
parent
0a6e975ca5
commit
520a2eff59
10 changed files with 279 additions and 447 deletions
44
python/djls/logging.py
Normal file
44
python/djls/logging.py
Normal file
|
@ -0,0 +1,44 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
import sys
|
||||
from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
@dataclass
|
||||
class LogConfig:
|
||||
log_file: Path | str = "/tmp/djls_debug.log"
|
||||
log_level: int = logging.DEBUG
|
||||
console_level: int = logging.DEBUG
|
||||
file_level: int = logging.DEBUG
|
||||
format: str = "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
|
||||
|
||||
|
||||
def configure_logging(config: LogConfig | None = None) -> logging.Logger:
|
||||
if config is None:
|
||||
config = LogConfig()
|
||||
|
||||
logger = logging.getLogger("djls")
|
||||
logger.setLevel(config.log_level)
|
||||
|
||||
# Clear any existing handlers
|
||||
logger.handlers.clear()
|
||||
|
||||
# File handler
|
||||
fh = logging.FileHandler(config.log_file)
|
||||
fh.setLevel(config.file_level)
|
||||
|
||||
# Console handler
|
||||
ch = logging.StreamHandler(sys.stderr)
|
||||
ch.setLevel(config.console_level)
|
||||
|
||||
# Formatter
|
||||
formatter = logging.Formatter(config.format)
|
||||
fh.setFormatter(formatter)
|
||||
ch.setFormatter(formatter)
|
||||
|
||||
logger.addHandler(fh)
|
||||
logger.addHandler(ch)
|
||||
|
||||
return logger
|
Loading…
Add table
Add a link
Reference in a new issue