Repository: borgbackup/borg

Issue:
crash: logging not yet set up in preprocess_args
current git master:

```
$ borg list --list-format '{formatkeys}{LF}' repo::1
Traceback (most recent call last):
  File "/home/tw/w/borg-env/bin/borg", line 9, in <module>
    load_entry_point('borgbackup==1.1.dev333-ngd5edaa5', 'console_scripts', 'borg')()
  File "/home/tw/w/borg/src/borg/archiver.py", line 2359, in main
    args = archiver.get_args(sys.argv, os.environ.get('SSH_ORIGINAL_COMMAND'))
  File "/home/tw/w/borg/src/borg/archiver.py", line 2243, in get_args
    result = self.parse_args(argv[1:])
  File "/home/tw/w/borg/src/borg/archiver.py", line 2259, in parse_args
    args = self.preprocess_args(args)
  File "/home/tw/w/borg/src/borg/archiver.py", line 1254, in preprocess_args
    self.print_warning(warning)
  File "/home/tw/w/borg/src/borg/archiver.py", line 127, in print_warning
    logger.warning(msg)
  File "/home/tw/w/borg/src/borg/logger.py", line 175, in warning
    return self.__logger.warning(*args, **kw)
  File "/home/tw/w/borg/src/borg/logger.py", line 150, in __logger
    raise Exception("tried to call a logger before setup_logging() was called")
Exception: tried to call a logger before setup_logging() was called
```



Discussion:
notes:
- maybe --list-format (borg 1.0) is not valid or deprecated now (in master/1.1 it is --format).
- also borg list --help is enough to get to know the supported format keys, no need for the `{formatkeys}` hack


Resolving patch:
diff --git a/src/borg/archiver.py b/src/borg/archiver.py
--- a/src/borg/archiver.py
+++ b/src/borg/archiver.py
@@ -793,7 +793,7 @@ def write(bytestring):
                 archive = Archive(repository, key, manifest, args.location.archive, cache=cache,
                                   consider_part_files=args.consider_part_files)
 
-                if args.format:
+                if args.format is not None:
                     format = args.format
                 elif args.short:
                     format = "{path}{NL}"
@@ -804,7 +804,7 @@ def write(bytestring):
                 for item in archive.iter_items(lambda item: matcher.match(item.path)):
                     write(safe_encode(formatter.format_item(item)))
         else:
-            if args.format:
+            if args.format is not None:
                 format = args.format
             elif args.short:
                 format = "{archive}{NL}"
@@ -1247,7 +1247,7 @@ def preprocess_args(self, args):
             for old_name, new_name, warning in deprecations:
                 if arg.startswith(old_name):
                     args[i] = arg.replace(old_name, new_name)
-                    self.print_warning(warning)
+                    print(warning, file=sys.stderr)
         return args
 
     def build_parser(self, prog=None):
diff --git a/src/borg/testsuite/archiver.py b/src/borg/testsuite/archiver.py
--- a/src/borg/testsuite/archiver.py
+++ b/src/borg/testsuite/archiver.py
@@ -1203,7 +1203,7 @@ def test_list_format(self):
         self.cmd('init', self.repository_location)
         test_archive = self.repository_location + '::test'
         self.cmd('create', test_archive, src_dir)
-        self.cmd('list', '--list-format', '-', test_archive, exit_code=1)
+        self.cmd('list', '--list-format', '-', test_archive)
         self.archiver.exit_code = 0  # reset exit code for following tests
         output_1 = self.cmd('list', test_archive)
         output_2 = self.cmd('list', '--format', '{mode} {user:6} {group:6} {size:8d} {isomtime} {path}{extra}{NEWLINE}', test_archive)


Test patch: