Skip to content

Commit

Permalink
Merge 055d7c7 into 790d5f4
Browse files Browse the repository at this point in the history
  • Loading branch information
rwols committed Nov 29, 2019
2 parents 790d5f4 + 055d7c7 commit b653ec7
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions plugin/core/logging.py
@@ -1,4 +1,5 @@
import traceback
from threading import Lock

MYPY = False
if MYPY:
Expand All @@ -9,6 +10,7 @@
log_debug = False
log_exceptions = True
log_server = True
mutex = Lock()


def set_debug_logging(logging_enabled: bool) -> None:
Expand All @@ -29,19 +31,22 @@ def set_server_logging(logging_enabled: bool) -> None:
def debug(*args: 'Any') -> None:
"""Print args to the console if the "debug" setting is True."""
if log_debug:
printf(*args)
with mutex:
printf(*args)


def exception_log(message: str, ex: Exception) -> None:
if log_exceptions:
print(message)
ex_traceback = ex.__traceback__
print(''.join(traceback.format_exception(ex.__class__, ex, ex_traceback)))
with mutex:
print(message)
ex_traceback = ex.__traceback__
print(''.join(traceback.format_exception(ex.__class__, ex, ex_traceback)))


def server_log(server_name: str, *args: 'Any') -> None:
if log_server:
printf(*args, prefix=server_name)
with mutex:
printf(*args, prefix=server_name)


def printf(*args: 'Any', prefix: str = 'LSP') -> None:
Expand Down

0 comments on commit b653ec7

Please sign in to comment.