Skip to content

Commit

Permalink
Don't log file contents in YCM; Log responses
Browse files Browse the repository at this point in the history
  • Loading branch information
puremourning authored and bstaletic committed May 11, 2024
1 parent 2cb9cc6 commit 4a15888
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion python/ycm/client/base_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from ycmd.utils import ToBytes, GetCurrentDirectory, ToUnicode
from ycmd.hmac_utils import CreateRequestHmac, CreateHmac
from ycmd.responses import ServerError, UnknownExtraConf
from copy import deepcopy

HTTP_SERVER_ERROR = 500

Expand Down Expand Up @@ -163,7 +164,22 @@ def _MakeRequest( data, handler, method, timeout, payload ):
headers = BaseRequest._ExtraHeaders( method,
request_uri,
sent_data )
_logger.debug( 'POST %s\n%s\n%s', request_uri, headers, sent_data )
if _logger.isEnabledFor( logging.DEBUG ):
if isinstance( data, dict ) and 'file_data' in data:
filtered_data = dict( data )
file_data = filtered_data.pop( 'file_data' )
# Filter the file contents from the log. This is a lot of data and
# might be sensitive. Mostly this just makes debugging easier
# because we can see them messages rather than jsut walls of ecaped
# file data.
filtered_data[ 'file_data' ] = {
filepath: {
'filetypes': data[ 'filetypes' ],
'contents': '...',
}
for filepath, data in file_data.items()
}
_logger.debug( 'POST %s\n%s\n%s\n', request_uri, headers, filtered_data )
else:
headers = BaseRequest._ExtraHeaders( method, request_uri )
if payload:
Expand Down Expand Up @@ -253,9 +269,12 @@ def _JsonFromFuture( future ):
try:
response = future.result()
response_text = response.read()
_logger.debug("RX: %s", response_text)

_ValidateResponseObject( response, response_text )
response.close()


if response_text:
return json.loads( response_text )
return None
Expand Down

0 comments on commit 4a15888

Please sign in to comment.