Skip to content

Commit 7b110cd

Browse files
committed
Fixes bug where debug log was not created
1 parent cb78f87 commit 7b110cd

File tree

1 file changed

+17
-18
lines changed

1 file changed

+17
-18
lines changed

fortls/langserver.py

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -186,14 +186,8 @@ def serve_initialize(self, request: dict):
186186
params.get("rootUri") or params.get("rootPath") or ""
187187
)
188188
self.source_dirs.add(self.root_path)
189-
logging.basicConfig(
190-
format="[%(levelname)-.4s - %(asctime)s] %(message)s",
191-
datefmt="%H:%M:%S",
192-
level=logging.INFO,
193-
)
194-
self._config_logger(request)
195-
init_debug_log = self._load_config_file()
196-
if init_debug_log:
189+
190+
self._load_config_file()
197191
self._config_logger(request)
198192
self._load_intrinsics()
199193
self._add_source_dirs()
@@ -1478,7 +1472,7 @@ def serve_default(self, request: dict):
14781472
code=-32601, message=f"method {request['method']} not found"
14791473
)
14801474

1481-
def _load_config_file(self) -> bool | None:
1475+
def _load_config_file(self) -> None:
14821476
"""Loads the configuration file for the Language Server"""
14831477

14841478
# Check for config file
@@ -1510,14 +1504,16 @@ def _load_config_file(self) -> bool | None:
15101504
# command line argument return True so that debug log is setup
15111505
if debugging != self.debug_log and not self.debug_log:
15121506
self.debug_log = True
1513-
return True
1514-
return False
15151507

15161508
except FileNotFoundError:
1517-
self.post_message(f"Error settings file '{self.config}' not found")
1509+
self.post_messages(
1510+
[Severity.error, f"Error settings file '{self.config}' not found"]
1511+
)
15181512

15191513
except ValueError:
1520-
self.post_message(f"Error while parsing '{self.config}' settings file")
1514+
self.post_messages(
1515+
[Severity.error, f"Error while parsing '{self.config}' settings file"]
1516+
)
15211517

15221518
def _load_config_file_dirs(self, config_dict: dict) -> None:
15231519
# Exclude paths (directories & files)
@@ -1662,16 +1658,19 @@ def _config_logger(self, request) -> None:
16621658
the logger will by default output to the main (stderr, stdout) channels.
16631659
"""
16641660

1665-
if not self.debug_log:
1666-
return None
1667-
if not self.root_path:
1668-
return None
1669-
1661+
file_log = True if self.debug_log and self.root_path else False
1662+
fmt = "[%(levelname)-.4s - %(asctime)s] %(message)s"
1663+
if file_log:
16701664
fname = "fortls_debug.log"
16711665
fname = os.path.join(self.root_path, fname)
16721666
logging.basicConfig(filename=fname, level=logging.DEBUG, filemode="w")
1667+
# Also forward logs to the console
1668+
consoleHandler = logging.StreamHandler()
1669+
log.addHandler(consoleHandler)
16731670
log.debug("REQUEST %s %s", request.get("id"), request.get("method"))
16741671
self.post_messages.append([Severity.info, "fortls debugging enabled"])
1672+
else:
1673+
logging.basicConfig(format=fmt, datefmt="%H:%M:%S", level=logging.INFO)
16751674

16761675
def _load_intrinsics(self) -> None:
16771676
# Load intrinsics

0 commit comments

Comments
 (0)