From 12c9f5f296de6959796b551eb728d39b9e0620cf Mon Sep 17 00:00:00 2001 From: SG Date: Thu, 5 Jun 2025 18:14:35 +0300 Subject: [PATCH] Added logging to stdout --- config.py | 22 ++++++++++++++++++++-- hydrogen.py | 10 +++++++--- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/config.py b/config.py index 38e0a85..4b1a97b 100644 --- a/config.py +++ b/config.py @@ -1,6 +1,24 @@ -import os +import logging, os, sys +# Main config section class Config: + APP_NAME = "hydrogen" MAIN_PAGE_TITLE = "Selected poems" - CONTENT_DIR = os.environ.get('CONTENT_DIR') or 'content' + OUTPUT_DIR = os.environ.get('OUTPUT_DIR') or 'public' HEADER_IMAGE = 'static/header.jpg' + LOG_TO = sys.stdout + LOG_LEVEL = logging.DEBUG + +# Logging config section +logger = logging.getLogger(Config.APP_NAME) +logger.setLevel(Config.LOG_LEVEL) +stdout_handler = logging.StreamHandler(Config.LOG_TO) +stdout_handler.setLevel(Config.LOG_LEVEL) +formatter = logging.Formatter( + '[%(asctime)s] %(name)s: %(levelname)s: %(message)s', + datefmt='%Y-%m-%d %H:%M:%S' +) +stdout_handler.setFormatter(formatter) +if not logger.hasHandlers(): + logger.addHandler(stdout_handler) +logger.propagate = False \ No newline at end of file diff --git a/hydrogen.py b/hydrogen.py index 82324c4..f6294ed 100644 --- a/hydrogen.py +++ b/hydrogen.py @@ -1,13 +1,15 @@ +#!/usr/bin/env python3 + from pathlib import Path import frontmatter import markdown from jinja2 import Environment, FileSystemLoader import shutil -from config import Config +from config import Config, logger content_dir = Path('content') template_dir = Path('templates') -output_dir = Path('public') +output_dir = Path(Config.OUTPUT_DIR) img_dir = Path('public/images') assets_dir = Path('public/assets') assets_css_dir = Path('public/assets/css') @@ -87,4 +89,6 @@ about_content = ContentItemPrototype(Path('static/about.md')) about_content.render_content() # Move 'robots.txt' into output_dir -shutil.copyfile(static_dir / 'robots.txt', output_dir / 'robots.txt') \ No newline at end of file +shutil.copyfile(static_dir / 'robots.txt', output_dir / 'robots.txt') + +logger.info(f"Created {len(content_items)} content items.") \ No newline at end of file