From ba5da6824fe767449340e3a09f4289160698fd4c Mon Sep 17 00:00:00 2001 From: sigoa Date: Mon, 22 Jan 2018 13:29:19 +0100 Subject: [PATCH 1/2] to demo utf8, emoji logging without exception --- src/bitmessagemain.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/bitmessagemain.py b/src/bitmessagemain.py index 91032fe5..fcb842a0 100755 --- a/src/bitmessagemain.py +++ b/src/bitmessagemain.py @@ -1,4 +1,5 @@ #!/usr/bin/python2.7 +# -*- coding: utf-8 -*- # Copyright (c) 2012-2016 Jonathan Warren # Copyright (c) 2012-2016 The Bitmessage developers # Distributed under the MIT/X11 software license. See the accompanying @@ -405,12 +406,22 @@ All parameters are optional. port = BMConfigParser().getint('bitmessagesettings', 'apiport') return {'address':address,'port':port} + +def emojiLogg(): + from debug import logger + reload(sys) + sys.setdefaultencoding( 'utf8') + logger.warning(str( u'exc:äüöß 🤷 🤷 without exception 😃 '.encode("UTF-8") ) ) + logger.warning( ' äüß 🤷 🤷 🤷 -- just a test emoji warning to demo this ') + + def main(): mainprogram = Main() mainprogram.start() if __name__ == "__main__": + #emojiLogg() # uncomment this to demo utf8, emoji logging without exception main() -- 2.45.1 From 7fa7c2665d38b5ec990c7afa3eea9e4eaf797fca Mon Sep 17 00:00:00 2001 From: sigoa Date: Thu, 25 Jan 2018 06:34:56 +0100 Subject: [PATCH 2/2] globally set effective default encoding('utf8') also rename function of demo of utf logging , including emoji capability --- src/bitmessagemain.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/bitmessagemain.py b/src/bitmessagemain.py index fcb842a0..2ae04185 100755 --- a/src/bitmessagemain.py +++ b/src/bitmessagemain.py @@ -407,12 +407,16 @@ All parameters are optional. return {'address':address,'port':port} -def emojiLogg(): +def LoggWithUnicode(): from debug import logger - reload(sys) - sys.setdefaultencoding( 'utf8') - logger.warning(str( u'exc:äüöß 🤷 🤷 without exception 😃 '.encode("UTF-8") ) ) - logger.warning( ' äüß 🤷 🤷 🤷 -- just a test emoji warning to demo this ') + #reload(sys) + #sys.setdefaultencoding( 'utf8') + logger.info(str( u'logger encoding reset '.encode("UTF-8") )) + #logger.info('unicode as log output possible: 🤷 ') + #logger.info( ' äüß 🤷 🤷 🤷 -- just a test emoji info to demo the function LoggWithUnicode() , no exception raised ') + # note that .info lines are invisible under standard logging settings, unlike a .warning log + # uncomment for demo + # call function #LoggWithUnicode() # to demo/test utf8 / Unicode logging without exception @@ -420,8 +424,11 @@ def main(): mainprogram = Main() mainprogram.start() + +reload(sys) +sys.setdefaultencoding('utf8') + if __name__ == "__main__": - #emojiLogg() # uncomment this to demo utf8, emoji logging without exception main() -- 2.45.1