@@ -186,14 +186,8 @@ def serve_initialize(self, request: dict):
186
186
params .get ("rootUri" ) or params .get ("rootPath" ) or ""
187
187
)
188
188
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 ()
197
191
self ._config_logger (request )
198
192
self ._load_intrinsics ()
199
193
self ._add_source_dirs ()
@@ -1478,7 +1472,7 @@ def serve_default(self, request: dict):
1478
1472
code = - 32601 , message = f"method { request ['method' ]} not found"
1479
1473
)
1480
1474
1481
- def _load_config_file (self ) -> bool | None :
1475
+ def _load_config_file (self ) -> None :
1482
1476
"""Loads the configuration file for the Language Server"""
1483
1477
1484
1478
# Check for config file
@@ -1510,14 +1504,16 @@ def _load_config_file(self) -> bool | None:
1510
1504
# command line argument return True so that debug log is setup
1511
1505
if debugging != self .debug_log and not self .debug_log :
1512
1506
self .debug_log = True
1513
- return True
1514
- return False
1515
1507
1516
1508
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
+ )
1518
1512
1519
1513
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
+ )
1521
1517
1522
1518
def _load_config_file_dirs (self , config_dict : dict ) -> None :
1523
1519
# Exclude paths (directories & files)
@@ -1662,16 +1658,19 @@ def _config_logger(self, request) -> None:
1662
1658
the logger will by default output to the main (stderr, stdout) channels.
1663
1659
"""
1664
1660
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 :
1670
1664
fname = "fortls_debug.log"
1671
1665
fname = os .path .join (self .root_path , fname )
1672
1666
logging .basicConfig (filename = fname , level = logging .DEBUG , filemode = "w" )
1667
+ # Also forward logs to the console
1668
+ consoleHandler = logging .StreamHandler ()
1669
+ log .addHandler (consoleHandler )
1673
1670
log .debug ("REQUEST %s %s" , request .get ("id" ), request .get ("method" ))
1674
1671
self .post_messages .append ([Severity .info , "fortls debugging enabled" ])
1672
+ else :
1673
+ logging .basicConfig (format = fmt , datefmt = "%H:%M:%S" , level = logging .INFO )
1675
1674
1676
1675
def _load_intrinsics (self ) -> None :
1677
1676
# Load intrinsics
0 commit comments