<commit_before>import logging
from logging.config import dictConfig
import sys
from typing import Any, Dict

from opentrons.config import CONFIG, ARCHITECTURE, SystemArchitecture


def _balena_config(level_value: int) -> Dict[str, Any]:
    serial_log_filename = CONFIG['serial_log_file']
    api_log_filename = CONFIG['api_log_file']
    return {
        'version': 1,
        'formatters': {
            'basic': {
                'format':
                '%(asctime)s %(name)s %(levelname)s [Line %(lineno)s] %(message)s'  # noqa: E501
            },
        },
        'handlers': {
            'debug': {
                'class': 'logging.StreamHandler',
                'formatter': 'basic',
                'level': level_value
            },
            'serial': {
                'class': 'logging.handlers.RotatingFileHandler',
                'formatter': 'basic',
                'filename': serial_log_filename,
                'maxBytes': 5000000,
                'level': logging.DEBUG,
                'backupCount': 3
            },
            'api': {
                'class': 'logging.handlers.RotatingFileHandler',
                'formatter': 'basic',
                'filename': api_log_filename,
                'maxBytes': 1000000,
                'level': logging.DEBUG,
                'backupCount': 5
            }
        },
        'loggers': {
            'opentrons': {
                'handlers': ['debug', 'api'],
                'level': level_value,
            },
            'opentrons.deck_calibration': {
                'handlers': ['debug', 'api'],
                'level': level_value,
            },
            'opentrons.drivers.serial_communication': {
                'handlers': ['serial'],
                'level': logging.DEBUG,
                'propagate': False
            },
            '__main__': {
                'handlers': ['api'],
                'level': level_value
            },
        }
    }


def _buildroot_config(level_value: int) -> Dict[str, Any]:
    # Import systemd.journald here since it is generally unavailble on non
    # linux systems and we probably don't want to use it on linux desktops
    # either
    return {
        'version': 1,
        'formatters': {
            'message_only': {
                'format': '%(message)s'
            },
        },
        'handlers': {
            'api': {
                'class': 'systemd.journal.JournalHandler',
                'level': logging.DEBUG,
                'formatter': 'message_only',
                'SYSLOG_IDENTIFIER': 'opentrons-api',
            },
            'serial': {
                'class': 'systemd.journal.JournalHandler',
                'level': logging.DEBUG,
                'formatter': 'message_only',
                'SYSLOG_IDENTIFIER': 'opentrons-api-serial',
            }
        },
        'loggers': {
            'opentrons.drivers.serial_communication': {
                'handlers': ['serial'],
                'level': logging.DEBUG,
                'propagate': False
            },
            'opentrons': {
                'handlers': ['api'],
                'level': level_value,
            },<commit_msg>fix(api): don't stomp other loggers in log config (#6286)<commit_after>import logging
from logging.config import dictConfig
import sys
from typing import Any, Dict

from opentrons.config import CONFIG, ARCHITECTURE, SystemArchitecture


def _balena_config(level_value: int) -> Dict[str, Any]:
    serial_log_filename = CONFIG['serial_log_file']
    api_log_filename = CONFIG['api_log_file']
    return {
        'version': 1,
        'disable_existing_loggers': False,
        'formatters': {
            'basic': {
                'format':
                '%(asctime)s %(name)s %(levelname)s [Line %(lineno)s] %(message)s'  # noqa: E501
            },
        },
        'handlers': {
            'debug': {
                'class': 'logging.StreamHandler',
                'formatter': 'basic',
                'level': level_value
            },
            'serial': {
                'class': 'logging.handlers.RotatingFileHandler',
                'formatter': 'basic',
                'filename': serial_log_filename,
                'maxBytes': 5000000,
                'level': logging.DEBUG,
                'backupCount': 3
            },
            'api': {
                'class': 'logging.handlers.RotatingFileHandler',
                'formatter': 'basic',
                'filename': api_log_filename,
                'maxBytes': 1000000,
                'level': logging.DEBUG,
                'backupCount': 5
            }
        },
        'loggers': {
            'opentrons': {
                'handlers': ['debug', 'api'],
                'level': level_value,
            },
            'opentrons.deck_calibration': {
                'handlers': ['debug', 'api'],
                'level': level_value,
            },
            'opentrons.drivers.serial_communication': {
                'handlers': ['serial'],
                'level': logging.DEBUG,
                'propagate': False
            },
            '__main__': {
                'handlers': ['api'],
                'level': level_value
            },
        }
    }


def _buildroot_config(level_value: int) -> Dict[str, Any]:
    # Import systemd.journald here since it is generally unavailble on non
    # linux systems and we probably don't want to use it on linux desktops
    # either
    return {
        'version': 1,
        'disable_existing_loggers': False,
        'formatters': {
            'message_only': {
                'format': '%(message)s'
            },
        },
        'handlers': {
            'api': {
                'class': 'systemd.journal.JournalHandler',
                'level': logging.DEBUG,
                'formatter': 'message_only',
                'SYSLOG_IDENTIFIER': 'opentrons-api',
            },
            'serial': {
                'class': 'systemd.journal.JournalHandler',
                'level': logging.DEBUG,
                'formatter': 'message_only',
                'SYSLOG_IDENTIFIER': 'opentrons-api-serial',
            }
        },
        'loggers': {
            'opentrons.drivers.serial_communication': {
                'handlers': ['serial'],
                'level': logging.DEBUG,
                'propagate': False
            },
            'opentrons': {
                'handlers': ['api'],
                'level': level_value,
            },
{'fraction_non_alphanumeric': 0.1289578850292038, 'fraction_numerical': 0.007070396557024286, 'mean_word_length': 1.4055452865064695, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4541202', 'n_tokens_mistral': 1868, 'n_tokens_neox': 1718, 'n_words': 350}