How to use the opsdroid.logging.configure_logging function in opsdroid

To help you get started, we’ve selected a few opsdroid examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github opsdroid / opsdroid / tests / test_logging.py View on Github external
def test_configure_file_logging(self):
        config = {
            "logging": {
                "path": os.path.join(self._tmp_dir, "output.log"),
                "console": False,
            }
        }
        opsdroid.configure_logging(config)
        rootlogger = logging.getLogger()
        self.assertEqual(len(rootlogger.handlers), 2)
        self.assertEqual(logging.StreamHandler, type(rootlogger.handlers[0]))
        self.assertEqual(rootlogger.handlers[0].level, logging.CRITICAL)
        self.assertEqual(logging.FileHandler, type(rootlogger.handlers[1]))
        self.assertEqual(rootlogger.handlers[1].level, logging.INFO)
github opsdroid / opsdroid / tests / test_logging.py View on Github external
def test_configure_console_blacklist(self):
        config = {
            "logging": {
                "path": False,
                "level": "error",
                "console": True,
                "filter": {"blacklist": "opsdroid"},
            }
        }
        opsdroid.configure_logging(config)
        rootlogger = logging.getLogger()
        self.assertEqual(len(rootlogger.handlers), 1)
        self.assertEqual(logging.StreamHandler, type(rootlogger.handlers[0]))
        self.assertLogs("_LOGGER", None)
github opsdroid / opsdroid / tests / test_logging.py View on Github external
def test_configure_default_logging(self):
        config = {}
        opsdroid.configure_logging(config)
        rootlogger = logging.getLogger()
        self.assertEqual(len(rootlogger.handlers), 2)
        self.assertEqual(logging.StreamHandler, type(rootlogger.handlers[0]))
        self.assertEqual(rootlogger.handlers[0].level, logging.INFO)
        self.assertEqual(logging.FileHandler, type(rootlogger.handlers[1]))
        self.assertEqual(rootlogger.handlers[1].level, logging.INFO)
        self.assertLogs("_LOGGER", "info")
github opsdroid / opsdroid / tests / test_logging.py View on Github external
def test_configure_extended_logging(self):
        config = {
            "logging": {
                "path": False,
                "level": "error",
                "console": True,
                "extended": True,
            }
        }
        opsdroid.configure_logging(config)
        rootlogger = logging.getLogger()
        self.assertEqual(len(rootlogger.handlers), 1)
        self.assertEqual(logging.StreamHandler, type(rootlogger.handlers[0]))
github opsdroid / opsdroid / tests / test_logging.py View on Github external
def test_configure_no_logging(self):
        config = {"logging": {"path": False, "console": False}}
        opsdroid.configure_logging(config)
        rootlogger = logging.getLogger()
        self.assertEqual(len(rootlogger.handlers), 1)
        self.assertEqual(logging.StreamHandler, type(rootlogger.handlers[0]))
        self.assertEqual(rootlogger.handlers[0].level, logging.CRITICAL)
github opsdroid / opsdroid / tests / test_logging.py View on Github external
def test_configure_file_logging_directory_not_exists(self):
        with mock.patch("logging.getLogger") as logmock:
            mocklogger = mock.MagicMock()
            mocklogger.handlers = [True]
            logmock.return_value = mocklogger
            config = {
                "logging": {
                    "path": os.path.join(
                        self._tmp_dir, "mynonexistingdirectory", "output.log"
                    ),
                    "console": False,
                }
            }
            opsdroid.configure_logging(config)
github opsdroid / opsdroid / tests / test_logging.py View on Github external
def test_configure_file_blacklist(self):
        config = {
            "logging": {
                "path": os.path.join(self._tmp_dir, "output.log"),
                "console": False,
                "filter": {"blacklist": "opsdroid.logging"},
            }
        }
        opsdroid.configure_logging(config)
        rootlogger = logging.getLogger()
        self.assertEqual(len(rootlogger.handlers), 2)
        self.assertEqual(logging.StreamHandler, type(rootlogger.handlers[0]))
        self.assertEqual(rootlogger.handlers[0].level, logging.CRITICAL)
        self.assertEqual(logging.FileHandler, type(rootlogger.handlers[1]))
        self.assertEqual(rootlogger.handlers[1].level, logging.INFO)
        self.assertLogs("_LOGGER", None)
github opsdroid / opsdroid / tests / test_logging.py View on Github external
def test_configure_whitelist_and_blacklist(self):
        opsdroid.configure_logging(self.config)
        self.assertLogs("_LOGGER", "warning")
github opsdroid / opsdroid / opsdroid / cli / start.py View on Github external
def start(path):
    """Start the opsdroid bot.

    If the `-f` flag is used with this command, opsdroid will load the
    configuration specified on that path otherwise it will use the default
    configuration.

    """
    check_dependencies()

    config = load_config_file([path] if path else DEFAULT_CONFIG_LOCATIONS)

    configure_lang(config)
    configure_logging(config)
    welcome_message(config)

    with OpsDroid(config=config) as opsdroid:
        opsdroid.run()
github opsdroid / opsdroid / opsdroid / cli / utils.py View on Github external
Returns:
        int: the exit code. Always returns 0 in this case.

    """
    click.echo("Opsdroid will build modules from config.")
    path = params.get("path")

    with contextlib.suppress(Exception):
        check_dependencies()

        config = load_config_file([path] if path else DEFAULT_CONFIG_LOCATIONS)

        if params["verbose"]:
            config["logging"] = {"level": "debug"}
            configure_logging(config)

        with OpsDroid(config=config) as opsdroid:

            opsdroid.loader.load_modules_from_config(config)

            click.echo(click.style("SUCCESS:", bg="green", bold=True), nl=False)
            click.echo(" Opsdroid modules successfully built from config.")