Пример #1
0
 def test_withSafeLoggingDisabled(self):
     """The filter should be disabled if ``safe_logging`` is disabled."""
     safelog.setSafeLogging(False)
     self.logger.info("%s %s" % (self.s1, self.s2))
     self.logfile.io.flush()
     self.logfile.io.seek(0)
     contents = self.logfile.value()
     self.assertIsNotNone(contents)
Пример #2
0
 def test_withSafeLoggingDisabled(self):
     """The filter should be disabled if ``safe_logging`` is disabled."""
     safelog.setSafeLogging(False)
     self.logger.info("%s %s" % (self.s1, self.s2))
     self.logfile.io.flush()
     self.logfile.io.seek(0)
     contents = self.logfile.value()
     self.assertIsNotNone(contents)
Пример #3
0
 def test_setSafeLogging_on(self):
     """Calls to ``logSafely()`` should return ``"[scrubbed]"`` for any
     arbitrary data when ``safe_logging`` is enabled.
     """
     safelog.setSafeLogging(True)
     self.logger.warn("Got a connection from %s..." %
                      safelog.logSafely(self.sensitiveData))
     contents = self.logfile.value()
     self.assertIsNotNone(contents)
Пример #4
0
 def test_setSafeLogging_off(self):
     """Calls to ``logSafely()`` should return the original data when
     ``safe_logging`` is disabled.
     """
     safelog.setSafeLogging(False)
     self.logger.warn("Got a connection from %s..." %
                      safelog.logSafely(self.sensitiveData))
     contents = self.logfile.value()
     self.assertIsNotNone(contents)
Пример #5
0
 def test_setSafeLogging_on(self):
     """Calls to ``logSafely()`` should return ``"[scrubbed]"`` for any
     arbitrary data when ``safe_logging`` is enabled.
     """
     safelog.setSafeLogging(True)
     self.logger.warn("Got a connection from %s..."
                      % safelog.logSafely(self.sensitiveData))
     contents = self.logfile.value()
     self.assertIsNotNone(contents)
Пример #6
0
 def test_setSafeLogging_off(self):
     """Calls to ``logSafely()`` should return the original data when
     ``safe_logging`` is disabled.
     """
     safelog.setSafeLogging(False)
     self.logger.warn("Got a connection from %s..."
                      % safelog.logSafely(self.sensitiveData))
     contents = self.logfile.value()
     self.assertIsNotNone(contents)
Пример #7
0
    def setUp(self):
        safelog.setSafeLogging(True)
        self.logfile = StringTransport()
        self.handler = safelog.logging.StreamHandler(self.logfile)
        self.logger = safelog.logging.getLogger(self.__class__.__name__)
        self.logger.setLevel(10)
        self.logger.addHandler(self.handler)
        self.filter = safelog.BaseSafelogFilter()
        self.logger.addFilter(self.filter)

        self.logMessage = "testing 1 2 3"
        self.record = safelog.logging.LogRecord('name', 10, __file__, 1337,
                                                self.logMessage, {}, None)
Пример #8
0
    def setUp(self):
        safelog.setSafeLogging(True)
        self.logfile = StringTransport()
        self.handler = safelog.logging.StreamHandler(self.logfile)
        self.logger = safelog.logging.getLogger(self.__class__.__name__)
        self.logger.setLevel(10)
        self.logger.addHandler(self.handler)
        self.filter = safelog.BaseSafelogFilter()
        self.logger.addFilter(self.filter)

        self.logMessage = "testing 1 2 3"
        self.record = safelog.logging.LogRecord('name', 10, __file__, 1337,
                                                self.logMessage, {}, None)
Пример #9
0
def configureLogging(cfg):
    """Set up Python's logging subsystem based on the configuration.

    :type cfg: :class:`~bridgedb.persistent.Conf`
    :param cfg: The current configuration, including any in-memory settings.
    """
    from bridgedb import safelog

    # Turn on safe logging by default:
    safelogging = getattr(cfg, 'SAFELOGGING', True)
    safelog.setSafeLogging(safelogging)

    level = getattr(cfg, 'LOGLEVEL', 'WARNING')
    logLevel = getattr(logging, level, 0)
    logStderr = getattr(cfg, 'LOG_TO_STDERR', False)
    logfileName = getattr(cfg, 'LOGFILE', "bridgedb.log")
    logfileCount = getattr(cfg, 'LOGFILE_COUNT', 3) - 1
    logfileRotateSize = getattr(cfg, 'LOGFILE_ROTATE_SIZE', 10000000)
    logThreads = getattr(cfg, 'LOG_THREADS', False)
    logTrace = getattr(cfg, 'LOG_TRACE', False)
    logTimeFormat = getattr(cfg, 'LOG_TIME_FORMAT', "%H:%M:%S")

    logFilters = []
    if safelogging:
        logFilters = ['safelogEmail', 'safelogIPv4', 'safelogIPv6']

    logConfig = {
        'version': 1,
        'filters': {
            'safelogEmail': {'()': safelog.SafelogEmailFilter},
            'safelogIPv4': {'()': safelog.SafelogIPv4Filter},
            'safelogIPv6': {'()': safelog.SafelogIPv6Filter},
        },
        'formatters': {
            'default': {'()': JustifiedLogFormatter,
                        # These values below are kwargs passed to
                        # :class:`JustifiedFormatter`:
                        'logThreads': logThreads,
                        'logTrace': logTrace,
                        'datefmt': logTimeFormat},
        },
        'handlers': {
            'console': {'class': 'logging.StreamHandler',
                        'level': logLevel,
                        'formatter': 'default',
                        'filters': logFilters},
            'rotating': {'()': _getRotatingFileHandler(logfileName, 'a',
                                                       logfileRotateSize,
                                                       logfileCount),
                         'level': logLevel,
                         'formatter': 'default',
                         'filters': logFilters},
        },
        'root': {
            'handlers': _getLogHandlers(logfileName, logStderr),
            'level': logLevel,
        },
    }

    logging.config.dictConfig(logConfig)

    logging.info("Logger Started.")
    logging.info("Level: %s", logLevel)
    logging.info("Safe Logging: %sabled" % ("En" if safelogging else "Dis"))
Пример #10
0
def configureLogging(cfg):
    """Set up Python's logging subsystem based on the configuration.

    :type cfg: :class:`~bridgedb.persistent.Conf`
    :param cfg: The current configuration, including any in-memory settings.
    """
    from bridgedb import safelog

    # Turn on safe logging by default:
    safelogging = getattr(cfg, 'SAFELOGGING', True)
    safelog.setSafeLogging(safelogging)

    level = getattr(cfg, 'LOGLEVEL', 'WARNING')
    logLevel = getattr(logging, level, 0)
    logStderr = getattr(cfg, 'LOG_TO_STDERR', False)
    logfileName = getattr(cfg, 'LOGFILE', "bridgedb.log")
    logfileCount = getattr(cfg, 'LOGFILE_COUNT', 3) - 1
    logfileRotateSize = getattr(cfg, 'LOGFILE_ROTATE_SIZE', 10000000)
    logThreads = getattr(cfg, 'LOG_THREADS', False)
    logTrace = getattr(cfg, 'LOG_TRACE', False)
    logTimeFormat = getattr(cfg, 'LOG_TIME_FORMAT', "%H:%M:%S")

    logFilters = []
    if safelogging:
        logFilters = ['safelogEmail', 'safelogIPv4', 'safelogIPv6']

    logConfig = {
        'version': 1,
        'filters': {
            'safelogEmail': {
                '()': safelog.SafelogEmailFilter
            },
            'safelogIPv4': {
                '()': safelog.SafelogIPv4Filter
            },
            'safelogIPv6': {
                '()': safelog.SafelogIPv6Filter
            },
        },
        'formatters': {
            'default': {
                '()': JustifiedLogFormatter,
                # These values below are kwargs passed to
                # :class:`JustifiedFormatter`:
                'logThreads': logThreads,
                'logTrace': logTrace,
                'datefmt': logTimeFormat
            },
        },
        'handlers': {
            'console': {
                'class': 'logging.StreamHandler',
                'level': logLevel,
                'formatter': 'default',
                'filters': logFilters
            },
            'rotating': {
                '()':
                _getRotatingFileHandler(logfileName, 'a', logfileRotateSize,
                                        logfileCount),
                'level':
                logLevel,
                'formatter':
                'default',
                'filters':
                logFilters
            },
        },
        'root': {
            'handlers': _getLogHandlers(logfileName, logStderr),
            'level': logLevel,
        },
    }

    logging.config.dictConfig(logConfig)

    logging.info("Logger Started.")
    logging.info("Level: %s", logLevel)
    logging.info("Safe Logging: %sabled" % ("En" if safelogging else "Dis"))
Пример #11
0
def configureLogging(cfg):
    """Set up Python's logging subsystem based on the configuration.

    :type cfg: :class:`~bridgedb.persistent.Conf`
    :param cfg: The current configuration, including any in-memory settings.
    """
    from bridgedb import safelog

    # Turn on safe logging by default:
    safelogging = getattr(cfg, "SAFELOGGING", True)
    safelog.setSafeLogging(safelogging)

    level = getattr(cfg, "LOGLEVEL", "WARNING")
    logLevel = getattr(logging, level, 0)
    logStderr = getattr(cfg, "LOG_TO_STDERR", False)
    logfileName = getattr(cfg, "LOGFILE", "bridgedb.log")
    logfileCount = getattr(cfg, "LOGFILE_COUNT", 3) - 1
    logfileRotateSize = getattr(cfg, "LOGFILE_ROTATE_SIZE", 10000000)
    logThreads = getattr(cfg, "LOG_THREADS", False)
    logTrace = getattr(cfg, "LOG_TRACE", False)
    logTimeFormat = getattr(cfg, "LOG_TIME_FORMAT", "%H:%M:%S")

    logFilters = []
    if safelogging:
        logFilters = ["safelogEmail", "safelogIPv4", "safelogIPv6"]

    logConfig = {
        "version": 1,
        "filters": {
            "safelogEmail": {"()": safelog.SafelogEmailFilter},
            "safelogIPv4": {"()": safelog.SafelogIPv4Filter},
            "safelogIPv6": {"()": safelog.SafelogIPv6Filter},
        },
        "formatters": {
            "default": {
                "()": JustifiedLogFormatter,
                # These values below are kwargs passed to
                # :class:`JustifiedFormatter`:
                "logThreads": logThreads,
                "logTrace": logTrace,
                "datefmt": logTimeFormat,
            }
        },
        "handlers": {
            "console": {
                "class": "logging.StreamHandler",
                "level": logLevel,
                "formatter": "default",
                "filters": logFilters,
            },
            "rotating": {
                "()": _getRotatingFileHandler(logfileName, "a", logfileRotateSize, logfileCount),
                "level": logLevel,
                "formatter": "default",
                "filters": logFilters,
            },
        },
        "root": {"handlers": _getLogHandlers(logfileName, logStderr), "level": logLevel},
    }

    logging.config.dictConfig(logConfig)

    logging.info("Logger Started.")
    logging.info("Level: %s", logLevel)
    logging.info("Safe Logging: %sabled" % ("En" if safelogging else "Dis"))