import logging


def TruncateStr(text, max_len=500):
  """Truncates strings to the specified maximum length or 500.

  Args:
    text: Text to truncate if longer than max_len.
    max_len: Maximum length of the string returned by the function.

  Returns:
    A string with max_len or less letters on it.
  """
  if len(text) > max_len:
    logging.warning(
        'Text length of %d is greater than the max length allowed. '
        'Truncating to a length of %d. Text: %s', len(text), max_len, text)
  return text[:max_len]