Changeset View
Changeset View
Standalone View
Standalone View
swh/scheduler/celery_backend/config.py
Show All 17 Lines | |||||
import requests | import requests | ||||
from typing import Any, Dict | from typing import Any, Dict | ||||
from swh.scheduler import CONFIG as SWH_CONFIG | from swh.scheduler import CONFIG as SWH_CONFIG | ||||
from swh.core.config import load_named_config, merge_configs | from swh.core.config import load_named_config, merge_configs | ||||
try: | |||||
from swh.core.logger import JournalHandler | from swh.core.logger import JournalHandler | ||||
except ImportError: | |||||
JournalHandler = None # noqa | |||||
DEFAULT_CONFIG_NAME = 'worker' | DEFAULT_CONFIG_NAME = 'worker' | ||||
CONFIG_NAME_ENVVAR = 'SWH_WORKER_INSTANCE' | CONFIG_NAME_ENVVAR = 'SWH_WORKER_INSTANCE' | ||||
CONFIG_NAME_TEMPLATE = 'worker/%s' | CONFIG_NAME_TEMPLATE = 'worker/%s' | ||||
DEFAULT_CONFIG = { | DEFAULT_CONFIG = { | ||||
'task_broker': ('str', 'amqp://guest@localhost//'), | 'task_broker': ('str', 'amqp://guest@localhost//'), | ||||
'task_modules': ('list[str]', []), | 'task_modules': ('list[str]', []), | ||||
Show All 35 Lines | def setup_log_handler(loglevel=None, logfile=None, format=None, colorize=None, | ||||
if log_console: | if log_console: | ||||
color_formatter = ColorFormatter(format) if colorize else formatter | color_formatter = ColorFormatter(format) if colorize else formatter | ||||
console = logging.StreamHandler() | console = logging.StreamHandler() | ||||
console.setLevel(logging.DEBUG) | console.setLevel(logging.DEBUG) | ||||
console.setFormatter(color_formatter) | console.setFormatter(color_formatter) | ||||
root_logger.addHandler(console) | root_logger.addHandler(console) | ||||
if log_journal: | if log_journal: | ||||
if not JournalHandler: | |||||
root_logger.warning('JournalHandler is not available, skipping. ' | |||||
'Please install swh-core[logging].') | |||||
else: | |||||
systemd_journal = JournalHandler() | systemd_journal = JournalHandler() | ||||
systemd_journal.setLevel(logging.DEBUG) | systemd_journal.setLevel(logging.DEBUG) | ||||
systemd_journal.setFormatter(formatter) | systemd_journal.setFormatter(formatter) | ||||
root_logger.addHandler(systemd_journal) | root_logger.addHandler(systemd_journal) | ||||
logging.getLogger('celery').setLevel(logging.INFO) | logging.getLogger('celery').setLevel(logging.INFO) | ||||
# Silence amqp heartbeat_tick messages | # Silence amqp heartbeat_tick messages | ||||
logger = logging.getLogger('amqp') | logger = logging.getLogger('amqp') | ||||
logger.addFilter(lambda record: not record.msg.startswith( | logger.addFilter(lambda record: not record.msg.startswith( | ||||
'heartbeat_tick')) | 'heartbeat_tick')) | ||||
logger.setLevel(loglevel) | logger.setLevel(loglevel) | ||||
# Silence useless "Starting new HTTP connection" messages | # Silence useless "Starting new HTTP connection" messages | ||||
▲ Show 20 Lines • Show All 195 Lines • Show Last 20 Lines |