Skip to content

Commit

Permalink
Log to stderr by default instead of salt-server.log
Browse files Browse the repository at this point in the history
Output logs to stderr by default instead of salt-server.log, to stop the
server from creating log files in the project root directory or current
working directory.

Add a "--log-file" flag to support writing logs to a given file instead
of stderr.

Update SaltServer and SlsFileWorkspace so they use the "--log-level"
flag value.
  • Loading branch information
koppchen committed Sep 7, 2022
1 parent a258323 commit d49df73
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
8 changes: 6 additions & 2 deletions salt_lsp/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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",
)
Expand All @@ -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
Expand Down
2 changes: 0 additions & 2 deletions salt_lsp/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions salt_lsp/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit d49df73

Please sign in to comment.