updating with latest changes to CONFIG
This commit is contained in:
@@ -1,12 +1,14 @@
|
||||
from __future__ import annotations
|
||||
from .config.config import Config
|
||||
from .library import set_config
|
||||
from .__header__ import __header__
|
||||
import logging
|
||||
from logging.handlers import RotatingFileHandler
|
||||
import os
|
||||
import sys
|
||||
|
||||
from .config import Config
|
||||
from .library import set_config, process_cached_logs
|
||||
from .__header__ import __header__
|
||||
|
||||
|
||||
# Load User Defined Config
|
||||
DEFAULT_CONFIG_PATH = f'~/.config/{__header__.lower()}'
|
||||
CONFIG_PATH = os.environ.get(f'{__header__}_CONFIG_PATH', DEFAULT_CONFIG_PATH)
|
||||
@@ -23,22 +25,40 @@ set_config(
|
||||
set_config(CONFIG, 'logging.level', 'INFO')
|
||||
loghandler_sys = logging.StreamHandler(sys.stdout)
|
||||
|
||||
# Checking if log path is set
|
||||
if CONFIG.logging_path:
|
||||
CONFIG.logging_path += (
|
||||
f'{__header__}.log'
|
||||
if CONFIG.logging_path[-1] == '/'
|
||||
else f'/{__header__}.log'
|
||||
)
|
||||
# Set default log file options
|
||||
set_config(CONFIG, 'logging.backup_count', 3, int)
|
||||
set_config(CONFIG, 'logging.rotate_bytes', 512000, int)
|
||||
|
||||
# Add to file handler
|
||||
loghandler_file = RotatingFileHandler(
|
||||
os.path.expanduser(CONFIG.logging_path),
|
||||
'a',
|
||||
CONFIG.logging_rotate_bytes,
|
||||
CONFIG.logging_backup_count
|
||||
CONFIG.logging_backup_count,
|
||||
)
|
||||
|
||||
# Set file formatter
|
||||
loghandler_file.setFormatter(logging.Formatter(CONFIG.logging_format))
|
||||
logger.addHandler(loghandler_file)
|
||||
|
||||
# Set stdout formatter
|
||||
loghandler_sys.setFormatter(logging.Formatter(CONFIG.logging_format))
|
||||
logger.addHandler(loghandler_sys)
|
||||
logger.setLevel(CONFIG.logging_level)
|
||||
|
||||
for msg in CONFIG.deferred_messages:
|
||||
logger.info(msg)
|
||||
CONFIG.reset_log()
|
||||
|
||||
# Load Slack environment variables
|
||||
set_config(CONFIG, 'slack.client_id')
|
||||
set_config(CONFIG, 'slack.client_secret')
|
||||
set_config(CONFIG, 'slack.signing_secret')
|
||||
|
||||
|
||||
# Print logged messages
|
||||
process_cached_logs(CONFIG, logger)
|
||||
|
||||
Reference in New Issue
Block a user