How to use the coloredlogs.__init__.HostNameFilter.install function in coloredlogs

To help you get started, weā€™ve selected a few coloredlogs 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 xolox / python-coloredlogs / coloredlogs / __init__.py View on Github external
# provide a shortcut to make it easy.
        #
        # [1] https://stackoverflow.com/questions/6290739/python-logging-use-milliseconds-in-time-format
        # [2] https://github.com/xolox/python-coloredlogs/issues/16
        if kw.get('milliseconds'):
            parser = FormatStringParser(style=style)
            if not (parser.contains_field(formatter_options['fmt'], 'msecs')
                    or '%f' in formatter_options['datefmt']):
                pattern = parser.get_pattern('asctime')
                replacements = {'%': '%(msecs)03d', '{': '{msecs:03}', '$': '${msecs}'}
                formatter_options['fmt'] = pattern.sub(
                    r'\g<0>,' + replacements[style],
                    formatter_options['fmt'],
                )
        # Do we need to make %(hostname) available to the formatter?
        HostNameFilter.install(
            fmt=formatter_options['fmt'],
            handler=handler,
            style=style,
            use_chroot=kw.get('use_chroot', True),
        )
        # Do we need to make %(programname) available to the formatter?
        ProgramNameFilter.install(
            fmt=formatter_options['fmt'],
            handler=handler,
            programname=kw.get('programname'),
            style=style,
        )
        # Do we need to make %(username) available to the formatter?
        UserNameFilter.install(
            fmt=formatter_options['fmt'],
            handler=handler,