diff --git a/salt_lsp/__main__.py b/salt_lsp/__main__.py index de21dab..2225b17 100644 --- a/salt_lsp/__main__.py +++ b/salt_lsp/__main__.py @@ -43,6 +43,10 @@ def add_arguments(parser): help="initialize the server, but don't launch it " "(useful for debugging/testing purposes)", ) + parser.add_argument( + "--log-file", + help="Redirect logs to the given file instead of writing to stderr", + ) parser.add_argument( "--log-level", choices=list(LOG_LEVEL_DICT.keys()) @@ -60,7 +64,7 @@ def main(): log_level = loglevel_from_str(args.log_level[0]) logging.basicConfig( - filename="salt-server.log", + filename=args.log_file, level=log_level, filemode="w", ) @@ -72,7 +76,7 @@ def main(): salt_server = SaltServer() setup_salt_server_capabilities(salt_server) - salt_server.post_init(states, log_level) + salt_server.post_init(states) if args.stop_after_init: return diff --git a/salt_lsp/server.py b/salt_lsp/server.py index 8439b2c..703c6a5 100644 --- a/salt_lsp/server.py +++ b/salt_lsp/server.py @@ -59,14 +59,12 @@ def workspace(self) -> SlsFileWorkspace: def post_init( self, state_name_completions: Dict[str, StateNameCompletion], - log_level=logging.DEBUG, ) -> None: """Further initialisation, called after setup_salt_server_capabilities.""" self._state_name_completions = state_name_completions self._state_names = list(state_name_completions.keys()) self.logger = logging.getLogger(self.__class__.__name__) - self.logger.setLevel(log_level) def complete_state_name( self, params: types.CompletionParams diff --git a/salt_lsp/workspace.py b/salt_lsp/workspace.py index 9e1c37d..f044898 100644 --- a/salt_lsp/workspace.py +++ b/salt_lsp/workspace.py @@ -2,7 +2,7 @@ contents utilizing the existing Workspace implementation from pygls. """ -from logging import getLogger, Logger, DEBUG +from logging import getLogger, Logger from pathlib import Path import sys from typing import List, Optional, Union @@ -59,8 +59,6 @@ def __init__( self._state_name_completions = state_name_completions self.logger: Logger = getLogger(self.__class__.__name__) - # FIXME: make this configurable - self.logger.setLevel(DEBUG) super().__init__(*args, **kwargs)