Repository: qtile/qtile

Issue:
`qtile --log-level=INFO` no longer works
My `.xsession` runs qtile using `qtile --log-level=INFO`.

This no longer works.

```
qtile: error: unrecognized arguments: --log-level=INFO
```

I'm guessing due to 908b910d00087ece13bb576f672c94bcf9e6fc43?

No big deal, but the changelog says

```
          Running `qtile` without arguments will continue to work for the
          forseeable future, but will be eventually deprecated.
```


Discussion:
Eh, yeah, our backward compatibility with `qtile` without argument is just a hack so that we don't break most people stuff. I don't think we want to add more to it to support `qtile start` arguments as well. :)
I wonder if we shouldn't support --log-level as a global option for
all commands though. Any chance this works:

https://paste.ubuntu.com/p/KTykfFyjbJ/

On Wed, Jan 13, 2021 at 07:15:16AM -0800, Mikel Ward wrote:
> My `.xsession` runs qtile using `qtile --log-level=INFO`.
> 
> This no longer works.
> 
> ```
> qtile: error: unrecognized arguments: --log-level=INFO
> ```
> 
> I'm guessing due to 908b910d00087ece13bb576f672c94bcf9e6fc43?
> 
> No big deal, but the changelog says
> 
> ```
>           Running `qtile` without arguments will continue to work for the
>           forseeable future, but will be eventually deprecated.
> ```
> 
> -- 
> You are receiving this because you are subscribed to this thread.
> Reply to this email directly or view it on GitHub:
> https://github.com/qtile/qtile/issues/2099


Resolving patch:
diff --git a/libqtile/scripts/main.py b/libqtile/scripts/main.py
--- a/libqtile/scripts/main.py
+++ b/libqtile/scripts/main.py
@@ -1,6 +1,8 @@
 import argparse
+import logging
 import sys
 
+from libqtile.log_utils import init_log
 from libqtile.scripts import cmd_obj, run_cmd, shell, start, top
 
 try:
@@ -28,6 +30,14 @@ def main():
         action='version',
         version=VERSION,
     )
+    parser.add_argument(
+        '-l', '--log-level',
+        default='WARNING',
+        dest='log_level',
+        type=str.upper,
+        choices=('DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'),
+        help='Set qtile log level'
+    )
 
     subparsers = parser.add_subparsers()
     start.add_subcommand(subparsers)
@@ -43,4 +53,6 @@ def print_help(options):
     help_.set_defaults(func=print_help)
 
     options = parser.parse_args()
+    log_level = getattr(logging, options.log_level)
+    init_log(log_level=log_level, log_color=sys.stdout.isatty())
     options.func(options)
diff --git a/libqtile/scripts/start.py b/libqtile/scripts/start.py
--- a/libqtile/scripts/start.py
+++ b/libqtile/scripts/start.py
@@ -22,13 +22,12 @@
 # Set the locale before any widgets or anything are imported, so any widget
 # whose defaults depend on a reasonable locale sees something reasonable.
 import locale
-import logging
 from os import getenv, makedirs, path
-from sys import exit, stdout
+from sys import exit
 
 import libqtile.backend
 from libqtile import confreader
-from libqtile.log_utils import init_log, logger
+from libqtile.log_utils import logger
 
 
 def rename_process():
@@ -48,8 +47,6 @@ def rename_process():
 
 
 def make_qtile(options):
-    log_level = getattr(logging, options.log_level)
-    init_log(log_level=log_level, log_color=stdout.isatty())
     kore = libqtile.backend.get_core(options.backend)
 
     if not path.isfile(options.configfile):
@@ -120,13 +117,6 @@ def add_subcommand(subparsers):
         dest="no_spawn",
         help='Avoid spawning apps. (Used for restart)'
     )
-    parser.add_argument(
-        '-l', '--log-level',
-        default='WARNING',
-        dest='log_level',
-        choices=('DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'),
-        help='Set qtile log level'
-    )
     parser.add_argument(
         '--with-state',
         default=None,


Test patch: