Source code for wolframclient.logger.utils
# -*- coding: utf-8 -*-
from __future__ import absolute_import, print_function, unicode_literals
import logging
from wolframclient.utils import six
if six.PY2:
def setup_logging_to_file(path, level=logging.INFO):
logging.basicConfig(
filename=path,
filemode='a',
format='%(asctime)s, %(name)s %(levelname)s %(message)s',
level=level)
else:
[docs] def setup_logging_to_file(path, level=logging.INFO):
"""Setup a basic Python logging configuration to a given file."""
logging.basicConfig(
format=u'%(asctime)s, %(name)s %(levelname)s %(message)s',
handlers=[logging.FileHandler(path, 'a', 'utf-8')],
level=level)
[docs]def str_trim(o, max_char=80):
"""Return the string representation of an object, trimmed to keep up to `max_char` characters.
"""
as_str = str(o)
if len(as_str) > max_char:
return '%s...(%i more)' % (as_str[:max_char], len(as_str) - max_char)
else:
return as_str