import asyncio
import logging
import logging.config
import sys

from .config import ReceptorConfig
from .diagnostics import log_buffer
from .logstash_formatter.logstash import LogstashFormatter

logger = logging.getLogger(__name__)


def main(args=None):

    try:
        config = ReceptorConfig(args)
    except Exception as e:
        logger.error("An error occured while validating the configuration options:\n%s" % (str(e),))
        sys.exit(1)

    logging.config.dictConfig(
        {
            "version": 1,
            "disable_existing_loggers": False,
            "formatters": {
                "simple": {
                    "format": "{levelname} {asctime} {node_id} {module} {message}",
                    "style": "{",
                },
                "structured": {"()": LogstashFormatter},
            },
            "handlers": {
                "console": {
                    "class": "logging.StreamHandler",
                    "formatter": "structured"
                    if config.default_logging_format == "structured"
                    else "simple",
                }
            },
            "loggers": {
                "receptor": {
                    "handlers": ["console"],
                    "level": "DEBUG" if config.default_debug else "WARN",
                }
            },
        }
    )

    def _f(record):
        record.node_id = config.default_node_id
        if record.levelno == logging.ERROR:
            log_buffer.appendleft(record)
        return True

    for h in logging.getLogger("receptor").handlers:
        h.addFilter(_f)

    try:
        config.go()
    except asyncio.CancelledError:
        pass
    except Exception:
        logger.exception("main: an error occured while running receptor")
        sys.exit(1)


if __name__ == "__main__":
    # We were run with python -m
    main()

dd1f4261852ef6057ccdc85daf53835561b56e6b
<mask token>


def main(args=None):
    try:
        config = ReceptorConfig(args)
    except Exception as e:
        logger.error(
            'An error occured while validating the configuration options:\n%s'
             % (str(e),))
        sys.exit(1)
    logging.config.dictConfig({'version': 1, 'disable_existing_loggers': 
        False, 'formatters': {'simple': {'format':
        '{levelname} {asctime} {node_id} {module} {message}', 'style': '{'},
        'structured': {'()': LogstashFormatter}}, 'handlers': {'console': {
        'class': 'logging.StreamHandler', 'formatter': 'structured' if 
        config.default_logging_format == 'structured' else 'simple'}},
        'loggers': {'receptor': {'handlers': ['console'], 'level': 'DEBUG' if
        config.default_debug else 'WARN'}}})

    def _f(record):
        record.node_id = config.default_node_id
        if record.levelno == logging.ERROR:
            log_buffer.appendleft(record)
        return True
    for h in logging.getLogger('receptor').handlers:
        h.addFilter(_f)
    try:
        config.go()
    except asyncio.CancelledError:
        pass
    except Exception:
        logger.exception('main: an error occured while running receptor')
        sys.exit(1)


<mask token>

<mask token>


def main(args=None):
    try:
        config = ReceptorConfig(args)
    except Exception as e:
        logger.error(
            'An error occured while validating the configuration options:\n%s'
             % (str(e),))
        sys.exit(1)
    logging.config.dictConfig({'version': 1, 'disable_existing_loggers': 
        False, 'formatters': {'simple': {'format':
        '{levelname} {asctime} {node_id} {module} {message}', 'style': '{'},
        'structured': {'()': LogstashFormatter}}, 'handlers': {'console': {
        'class': 'logging.StreamHandler', 'formatter': 'structured' if 
        config.default_logging_format == 'structured' else 'simple'}},
        'loggers': {'receptor': {'handlers': ['console'], 'level': 'DEBUG' if
        config.default_debug else 'WARN'}}})

    def _f(record):
        record.node_id = config.default_node_id
        if record.levelno == logging.ERROR:
            log_buffer.appendleft(record)
        return True
    for h in logging.getLogger('receptor').handlers:
        h.addFilter(_f)
    try:
        config.go()
    except asyncio.CancelledError:
        pass
    except Exception:
        logger.exception('main: an error occured while running receptor')
        sys.exit(1)


if __name__ == '__main__':
    main()

<mask token>
logger = logging.getLogger(__name__)


def main(args=None):
    try:
        config = ReceptorConfig(args)
    except Exception as e:
        logger.error(
            'An error occured while validating the configuration options:\n%s'
             % (str(e),))
        sys.exit(1)
    logging.config.dictConfig({'version': 1, 'disable_existing_loggers': 
        False, 'formatters': {'simple': {'format':
        '{levelname} {asctime} {node_id} {module} {message}', 'style': '{'},
        'structured': {'()': LogstashFormatter}}, 'handlers': {'console': {
        'class': 'logging.StreamHandler', 'formatter': 'structured' if 
        config.default_logging_format == 'structured' else 'simple'}},
        'loggers': {'receptor': {'handlers': ['console'], 'level': 'DEBUG' if
        config.default_debug else 'WARN'}}})

    def _f(record):
        record.node_id = config.default_node_id
        if record.levelno == logging.ERROR:
            log_buffer.appendleft(record)
        return True
    for h in logging.getLogger('receptor').handlers:
        h.addFilter(_f)
    try:
        config.go()
    except asyncio.CancelledError:
        pass
    except Exception:
        logger.exception('main: an error occured while running receptor')
        sys.exit(1)


if __name__ == '__main__':
    main()

import asyncio
import logging
import logging.config
import sys
from .config import ReceptorConfig
from .diagnostics import log_buffer
from .logstash_formatter.logstash import LogstashFormatter
logger = logging.getLogger(__name__)


def main(args=None):
    try:
        config = ReceptorConfig(args)
    except Exception as e:
        logger.error(
            'An error occured while validating the configuration options:\n%s'
             % (str(e),))
        sys.exit(1)
    logging.config.dictConfig({'version': 1, 'disable_existing_loggers': 
        False, 'formatters': {'simple': {'format':
        '{levelname} {asctime} {node_id} {module} {message}', 'style': '{'},
        'structured': {'()': LogstashFormatter}}, 'handlers': {'console': {
        'class': 'logging.StreamHandler', 'formatter': 'structured' if 
        config.default_logging_format == 'structured' else 'simple'}},
        'loggers': {'receptor': {'handlers': ['console'], 'level': 'DEBUG' if
        config.default_debug else 'WARN'}}})

    def _f(record):
        record.node_id = config.default_node_id
        if record.levelno == logging.ERROR:
            log_buffer.appendleft(record)
        return True
    for h in logging.getLogger('receptor').handlers:
        h.addFilter(_f)
    try:
        config.go()
    except asyncio.CancelledError:
        pass
    except Exception:
        logger.exception('main: an error occured while running receptor')
        sys.exit(1)


if __name__ == '__main__':
    main()

import asyncio
import logging
import logging.config
import sys

from .config import ReceptorConfig
from .diagnostics import log_buffer
from .logstash_formatter.logstash import LogstashFormatter

logger = logging.getLogger(__name__)


def main(args=None):

    try:
        config = ReceptorConfig(args)
    except Exception as e:
        logger.error("An error occured while validating the configuration options:\n%s" % (str(e),))
        sys.exit(1)

    logging.config.dictConfig(
        {
            "version": 1,
            "disable_existing_loggers": False,
            "formatters": {
                "simple": {
                    "format": "{levelname} {asctime} {node_id} {module} {message}",
                    "style": "{",
                },
                "structured": {"()": LogstashFormatter},
            },
            "handlers": {
                "console": {
                    "class": "logging.StreamHandler",
                    "formatter": "structured"
                    if config.default_logging_format == "structured"
                    else "simple",
                }
            },
            "loggers": {
                "receptor": {
                    "handlers": ["console"],
                    "level": "DEBUG" if config.default_debug else "WARN",
                }
            },
        }
    )

    def _f(record):
        record.node_id = config.default_node_id
        if record.levelno == logging.ERROR:
            log_buffer.appendleft(record)
        return True

    for h in logging.getLogger("receptor").handlers:
        h.addFilter(_f)

    try:
        config.go()
    except asyncio.CancelledError:
        pass
    except Exception:
        logger.exception("main: an error occured while running receptor")
        sys.exit(1)


if __name__ == "__main__":
    # We were run with python -m
    main()
