feat: creatives and external channels

This commit is contained in:
Artem Tsyrulnikov
2025-11-10 15:13:38 +03:00
parent 3800c72662
commit cd167fdb43
73 changed files with 3024 additions and 947 deletions

View File

@@ -39,11 +39,33 @@ class ColoredConsoleFormatter(logging.Formatter):
# Add extra fields
extra_parts = []
for key, value in record.__dict__.items():
if key not in ['name', 'msg', 'args', 'created', 'filename', 'funcName', 'levelname',
'levelno', 'lineno', 'module', 'msecs', 'message', 'pathname', 'process',
'processName', 'relativeCreated', 'thread', 'threadName', 'exc_info',
'exc_text', 'stack_info', 'app_name', 'app_version', 'taskName',
'color_message']:
if key not in [
'name',
'msg',
'args',
'created',
'filename',
'funcName',
'levelname',
'levelno',
'lineno',
'module',
'msecs',
'message',
'pathname',
'process',
'processName',
'relativeCreated',
'thread',
'threadName',
'exc_info',
'exc_text',
'stack_info',
'app_name',
'app_version',
'taskName',
'color_message',
]:
value_color = self.RED if key == 'error' else self.DARK_YELLOW
extra_parts.append(f'{self.DARK_CYAN}{key}{self.RESET}={value_color}{value}{self.RESET}')

View File

@@ -11,15 +11,16 @@ class JSONFormatter(logging.Formatter):
'message': record.getMessage(),
'module': record.module,
'package': record.name,
'app_name': record.app_name,
'app_version': record.app_version,
'app_name': getattr(record, 'app_name', 'unknown'),
'app_version': getattr(record, 'app_version', 'unknown'),
}
if record.levelno >= logging.ERROR:
log_data['location'] = f'{record.pathname}:{record.lineno}'
if record.exc_info:
log_data['error_type'] = record.exc_info[0].__name__
exc_type = record.exc_info[0]
log_data['error_type'] = exc_type.__name__ if exc_type else 'Unknown'
log_data['error_message'] = str(record.exc_info[1])
log_data['traceback'] = self.formatException(record.exc_info)

View File

@@ -42,7 +42,7 @@ def init(config: LoggerConfig) -> None:
old_factory = logging.getLogRecordFactory()
def record_factory(*args, **kwargs) -> logging.LogRecord:
def record_factory(*args: object, **kwargs: object) -> logging.LogRecord:
record = old_factory(*args, **kwargs)
record.app_name = config.APP_NAME
record.app_version = config.APP_VERSION
@@ -50,6 +50,4 @@ def init(config: LoggerConfig) -> None:
logging.setLogRecordFactory(record_factory)
logging.info(
'Logger initialized', extra={'app': config.APP_NAME, 'version': config.APP_VERSION}
)
logging.info('Logger initialized', extra={'app': config.APP_NAME, 'version': config.APP_VERSION})