Skip to content

Commit 2c096e5

Browse files
authored
Verbose logging (#114)
1 parent 489878b commit 2c096e5

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

pyls/__main__.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,20 @@ def add_arguments(parser):
2626
help="Bind to this port"
2727
)
2828

29-
parser.add_argument(
29+
log_group = parser.add_mutually_exclusive_group()
30+
log_group.add_argument(
31+
"--log-config",
32+
help="Path to a JSON file containing Python logging config."
33+
)
34+
log_group.add_argument(
3035
"--log-file",
3136
help="Redirect logs to the given file instead of writing to stderr."
3237
"Has no effect if used with --log-config."
3338
)
39+
3440
parser.add_argument(
35-
"--log-config",
36-
help="Path to a JSON file containing Python logging config."
41+
'-v', '--verbose', action='count', default=0,
42+
help="Increase verbosity of log output, overrides log config file"
3743
)
3844

3945

@@ -46,9 +52,17 @@ def main():
4652
with open(args.log_config, 'r') as f:
4753
logging.config.dictConfig(json.load(f))
4854
elif args.log_file:
49-
logging.basicConfig(filename=args.log_file, level=logging.WARNING, format=LOG_FORMAT)
55+
logging.basicConfig(filename=args.log_file, format=LOG_FORMAT)
5056
else:
51-
logging.basicConfig(level=logging.WARNING, format=LOG_FORMAT)
57+
logging.basicConfig(format=LOG_FORMAT)
58+
59+
if args.verbose == 0:
60+
level = logging.WARNING
61+
elif args.verbose == 1:
62+
level = logging.INFO
63+
elif args.verbose >= 2:
64+
level = logging.DEBUG
65+
logging.getLogger().setLevel(level)
5266

5367
if args.tcp:
5468
language_server.start_tcp_lang_server(args.host, args.port, PythonLanguageServer)

0 commit comments

Comments
 (0)