logger.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. # This file is part of TRS (http://math.kompiler.org)
  2. #
  3. # TRS is free software: you can redistribute it and/or modify it under the
  4. # terms of the GNU Affero General Public License as published by the Free
  5. # Software Foundation, either version 3 of the License, or (at your option) any
  6. # later version.
  7. #
  8. # TRS is distributed in the hope that it will be useful, but WITHOUT ANY
  9. # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  10. # A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
  11. # details.
  12. #
  13. # You should have received a copy of the GNU Affero General Public License
  14. # along with TRS. If not, see <http://www.gnu.org/licenses/>.
  15. import logging
  16. import logging.config
  17. import sys
  18. try:
  19. import config as cfg
  20. except ImportError:
  21. cfg = object()
  22. import default_config as default
  23. try:
  24. logging.basicConfig(level=logging.DEBUG,
  25. format=getattr(cfg, 'LOG_FORMAT', default.LOG_FORMAT),
  26. filename=getattr(cfg, 'LOG_FILE', default.LOG_FILE),
  27. filemode='a')
  28. except IOError as e: # pragma: no cover
  29. print >>sys.stderr, 'warning: IOError raised: "%s"' % str(e)
  30. def logger(name):
  31. return logging.getLogger(name)
  32. def filter_non_ascii(data):
  33. return ''.join(map(lambda x: 33 < ord(x) < 125 and x or '.', data))