added better logging and moved config to its own folder

This commit is contained in:
Jake Pullen
2024-08-10 14:10:16 +01:00
parent ad633edefd
commit 296787d7b0
6 changed files with 125 additions and 10 deletions
+26
View File
@@ -0,0 +1,26 @@
entities:
- accounts
- categories
- months
- payees
- transactions
- scheduled_transactions
base_url: https://api.ynab.com/v1/budgets
knowledge_file: data/server_knowledge_cache.json
primary_keys:
accounts:
unique_id: id
categories:
unique_id: id
months:
unique_id: month
payees:
unique_id: id
transactions:
unique_id: id
scheduled_transactions:
unique_id: id
raw_data_path: data/raw
processed_data_path: data/processed
base_data_path: data/base
warehouse_data_path: data/warehouse
+41
View File
@@ -0,0 +1,41 @@
import datetime as dt
import json
import logging
from typing import override
class custom_json_logger(logging.Formatter):
def __init__(
self,
*,
format_keys: dict[str,str] | None = None,
):
super().__init__()
self.format_keys = format_keys if format_keys is not None else {}
@override
def format(self, record: logging.LogRecord) -> str:
record_dict = self._prepare_log_dict(record)
return json.dumps(record_dict, default=str)
def _prepare_log_dict(self, record: logging.LogRecord) -> dict:
always_fields = {
"message" : record.getMessage(),
"timestamp" : dt.datetime.fromtimestamp(
record.created, tz=dt.timezone.utc
).isoformat(),
}
if record.exc_info is not None:
always_fields["exc_info"] = self.formatException(record.exc_info)
if record.stack_info is not None:
always_fields["stack_info"] = self.formatStack(record.stack_info)
message = {
key: msg_val
if (msg_val := always_fields.pop(val, None)) is not None
else getattr(record, val)
for key, val in self.format_keys.items()
}
message.update(always_fields)
return message
+3
View File
@@ -0,0 +1,3 @@
SUCCESS = 0
MISSING_ENV_VARS = 1
MISSING_CONFIG_FILE = 2
+41
View File
@@ -0,0 +1,41 @@
version: 1
disable_existing_loggers: False
formatters:
simple:
format: "%(asctime)s - %(levelname)s - %(module)s - %(funcName)s - %(message)s"
datefmt: "%Y-%m-%d %H:%M:%S%z"
json:
"()": config.custom_json_logger.custom_json_logger
format_keys:
level: levelname
timestamp: timestamp
logger: name
module: module
function: funcName
line: lineno
message: message
thread_name: threadName
handlers:
stderr:
class: logging.StreamHandler
level: INFO
formatter: simple
stream: ext://sys.stdout
file:
class: logging.handlers.RotatingFileHandler
level: DEBUG
formatter: json
filename: logs/dpfy_log.jsonl
maxBytes: 10485760 # 10MB
backupCount: 10
queue_handler:
class: logging.handlers.QueueHandler
handlers:
- stderr
- file
respect_handler_level: True
loggers:
root:
level: DEBUG
handlers:
- queue_handler