fixed price drops/moved logging outside of init_monitor
This commit is contained in:
1 parent
7d070dec40
commit
00d3c12ee0
3 files changed
+98
-27
No files matched your search
+34
-23
@@ -28,34 +28,19 @@ from monitor_utils.sessions import get_base_session, get_tls_session
|
||||
LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
async def init_monitor(
|
||||
monitor_name: str,
|
||||
development_mode: DevelopmentMode,
|
||||
production_proxy_path: str = "proxies.txt",
|
||||
testing_proxy_path: str = "configs/proxies.txt",
|
||||
logging_level=LOGGING_LEVEL,
|
||||
) -> tuple[list[str] | dict[str, str], AsyncIOMotorCollection, AioProxies]:
|
||||
"""Run shared monitor startup and return categories, collection, and proxies.
|
||||
def setup_monitor_logging(monitor_name: str, logging_level=LOGGING_LEVEL):
|
||||
"""Configure JSON logging for a monitor and quiet noisy libraries.
|
||||
|
||||
Configures JSON logging under the monitor's name, applies logger levels,
|
||||
loads the monitor config and Mongo collection, and loads proxies from the
|
||||
production or testing path based on development_mode. Async because the
|
||||
config now lives in Mongo; call it from inside the monitor's event loop
|
||||
(in main), not at module import.
|
||||
Call once at module import, at global scope, before creating module loggers,
|
||||
so logging is configured synchronously at startup rather than inside the
|
||||
async init_monitor. Logs go to logs/latest.log with rotated history keyed by
|
||||
monitor_name.
|
||||
|
||||
Args:
|
||||
monitor_name: Monitor identifier used for logging and config lookup.
|
||||
development_mode: Selects production or testing config, collection,
|
||||
and proxy path.
|
||||
production_proxy_path: Proxy file path used in production mode.
|
||||
testing_proxy_path: Proxy file path used in testing mode.
|
||||
logging_level: Level passed to setup_logging.
|
||||
|
||||
Returns:
|
||||
Tuple of category names, Mongo collection, and loaded proxies.
|
||||
monitor_name: Monitor name used as the rotated-history base.
|
||||
logging_level: Root logging level.
|
||||
"""
|
||||
|
||||
use_production = is_production(development_mode)
|
||||
setup_logging(
|
||||
name="logs/latest.log",
|
||||
history_name=monitor_name,
|
||||
@@ -63,6 +48,32 @@ async def init_monitor(
|
||||
output="json",
|
||||
)
|
||||
set_logger_levels()
|
||||
|
||||
|
||||
async def init_monitor(
|
||||
monitor_name: str,
|
||||
development_mode: DevelopmentMode,
|
||||
production_proxy_path: str = "proxies.txt",
|
||||
testing_proxy_path: str = "configs/proxies.txt",
|
||||
) -> tuple[list[str] | dict[str, str], AsyncIOMotorCollection, AioProxies]:
|
||||
"""Load a monitor's config, collection, and proxies for the mode.
|
||||
|
||||
Async because config now lives in Mongo; call it from inside the monitor's
|
||||
event loop (in main), not at module import. Logging is configured separately
|
||||
by setup_monitor_logging at module scope and is not touched here.
|
||||
|
||||
Args:
|
||||
monitor_name: Monitor identifier used for config and collection lookup.
|
||||
development_mode: Selects production or testing config, collection,
|
||||
and proxy path.
|
||||
production_proxy_path: Proxy file path used in production mode.
|
||||
testing_proxy_path: Proxy file path used in testing mode.
|
||||
|
||||
Returns:
|
||||
Tuple of category names, Mongo collection, and loaded proxies.
|
||||
"""
|
||||
|
||||
use_production = is_production(development_mode)
|
||||
category_names, _, collection = await setup_config(
|
||||
monitor_name=monitor_name, development_mode=development_mode
|
||||
)
|
||||
|
||||
Reference in new issue
Block a user