vigil/services/logger.py
Uthman Fatih 312d3e9674 Refactor installation and uninstallation scripts; enhance logging and error handling
- Removed Docker installation instructions from README.md as they are not yet functional.
- Simplified the installation script by removing the upgrade process and directly checking for existing installations.
- Added checks for required dependencies (python3, curl, python3-venv) during installation.
- Improved logging throughout the application, replacing print statements with logger calls.
- Enhanced email validation using regex and added error handling for invalid email addresses.
- Updated the uninstall script to provide options for complete or partial removal of Vigil.
- Created a logger service to handle logging to both console and log files.
- Updated requirements.txt to use newer versions of dependencies.
- Added versioning to the main application and provided a version option in the command line interface.
2025-11-14 22:58:55 +00:00

47 lines
1.3 KiB
Python

# _ __________________
# | | / / _/ ____/ _/ /
# | | / // // / __ / // /
# | |/ // // /_/ // // /___
# |___/___/\____/___/_____/
# © Uthmn 2025 under MIT license
import logging
from logging.handlers import RotatingFileHandler
from os import makedirs
from os.path import exists
# Setup logging once, globally
logger = logging.getLogger('vigil')
# Prevent duplicate setup
if not logger.handlers:
logger.setLevel(logging.INFO)
# Create log directory if it doesn't exist
log_dir = '/var/log/vigil'
if not exists(log_dir):
makedirs(log_dir, exist_ok=True)
# File handler with rotation
file_handler = RotatingFileHandler(
'/var/log/vigil/vigil.log',
maxBytes=10*1024*1024, # 10MB
backupCount=3
)
file_handler.setLevel(logging.INFO)
file_handler.setFormatter(logging.Formatter(
'%(asctime)s [%(levelname)s] %(message)s',
datefmt='%Y-%m-%d %H:%M:%S'
))
# Console handler (for systemd journal)
console_handler = logging.StreamHandler()
console_handler.setLevel(logging.INFO)
console_handler.setFormatter(logging.Formatter(
'%(asctime)s [%(levelname)s] %(message)s',
datefmt='%Y-%m-%d %H:%M:%S'
))
logger.addHandler(file_handler)
logger.addHandler(console_handler)