Ejemplo n.º 1
0
    def __init__(self, argv, stdin, stdout, stderr, no_logfile=False):
        """Create a command line UI.

        This UI logs to ~/.cache/lmirror/log for level 3 and up by default,
        and level 5 and up to the console.

        :param argv: Arguments from the process invocation.
        :param stdin: The stream for stdin.
        :param stdout: The stream for stdout.
        :param stderr: The stream for stderr.
        ;param no_logfile: Disable default ~/.cache/lmirror/log logfile.
        """
        self._argv = argv
        self._stdin = stdin
        self._stdout = stdout
        self._stderr = stderr
        if no_logfile:
            args = [None]
        else:
            args = []
        self._c_log, self._f_log, self._log_formatter = \
            logging_support.configure_logging(self._stdout, *args)
        self._c_log.setLevel(5)
        if self._f_log is not None:
            self._f_log.setLevel(3) # log more than the UI, but not everything.
        self._min_log_level = 0
Ejemplo n.º 2
0
 def test_configure_logging_sets_converter(self):
     out = StringIO()
     c_log, f_log, formatter = logging_support.configure_logging(out)
     self.assertEqual(c_log, logging.root.handlers[0])
     self.assertEqual(f_log, logging.root.handlers[1])
     self.assertEqual(None, c_log.formatter)
     self.assertEqual(formatter, f_log.formatter)
     self.assertEqual(time.gmtime, formatter.converter)
     self.assertEqual("%Y-%m-%d %H:%M:%SZ", formatter.datefmt)
     self.assertEqual(logging.StreamHandler, c_log.__class__)
     self.assertEqual(out, c_log.stream)
     self.assertEqual(logging.FileHandler, f_log.__class__)
     self.assertEqual(os.path.expanduser("~/.cache/lmirror/log"), f_log.baseFilename)
Ejemplo n.º 3
0
 def test_can_supply_filename_None(self):
     out = StringIO()
     c_log, f_log, formatter = logging_support.configure_logging(out, None)
     self.assertEqual(None, f_log)