# -*- coding: utf-8 -*-
import logging
import six
import sys

# LC_ALL=C python2 logtest.py
# - works
# LC_ALL=C python3 logtest.py
# - UnicodeEncodeError

logger = logging.getLogger('gtkdoc')
formatter = logging.Formatter('%(xfilename)s:%(xlineno)d:%(message)s')
stream = sys.stdout
if six.PY3:
  stream = open(sys.stdout.fileno(), mode='w', encoding='utf8', buffering=1)
ch = logging.StreamHandler(stream)
ch.setLevel(logging.DEBUG)
ch.setFormatter(formatter)
logger.addHandler(ch)
logger.setLevel(logging.DEBUG)
logger.info('hello', extra={'xfilename':'foo.py','xlineno':32})
logger.info(u'☺ ☻', extra={'xfilename':'foo.py','xlineno':50})

