[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    Re: [PyQt] Logging UTF-8 when pyqtdeployed
From:       Barry <barry () barrys-emacs ! org>
Date:       2017-02-11 16:00:46
Message-ID: 26B7F0F9-934A-47F1-A0B5-2C1E382B006C () barrys-emacs ! org
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


Barry

> On 7 Feb 2017, at 22:28, Kyle Altendorf <sda@fstab.net> wrote:
> 
> > On 2017-02-07 16:47, Dave Gradwell wrote:
> > If my pyqtdeploy'ed app is run from under pyqtdeploy itself (with the
> > ‘run application' checkbox) then it can send UTF-8 characters to the
> > Python logging module, which end up in a log file — which is good.  It
> > also works fine in interpreted/development mode, i.e., unpackaged.
> > But if I quit pyqtdeploy and immediately just double click the (now
> > packaged) app then it fails to log UTF-8 with the error message
> > "UnicodeEncodeError: 'ascii' codec can't encode character '\xfc' in
> > position 66: ordinal not in range(128)"
> 
> Is this Windows?  Is it a GUI application?  If so, I found that when deployed my \
> sys.stdout and sys.stderr were actually None.  I won't recommend what I have done \
> as _good_ but I will share it in case it is _useful_ at least for exploration. 
> https://github.com/altendky/st/blob/master/epyq/__main__.py#L11-L24
> https://github.com/altendky/st/blob/26bfdb5a8409e20e9fc6870f6a9e56ddc516f65b/epyqlib/tee.py
>  
> Roughly speaking I replace sys.stdout and sys.stderr *shudder* with either my log \
> file or my tee object which sends to both the file and stdout/err.  Nasty, but \
> without it I was flying totally blind except that my application stopped running.  \
> Someday I'll do a proper logging solution.

What I do for Windows is intercept writes to stdout and stderr and write them the \
logging system.

See the the logging code in \
https://github.com/barry-scott/scm-workbench/blob/master/Source/Common/wb_logging.py

And the setup in https://github.com/barry-scott/scm-workbench/blob/master/Source/Common/wb_app.py


The features I needed are:
* log rotation and max size limits
* optionally capture stdout and stderr - always on for production
* optionally output log to stdout - used while debugging
* output to Qt Widget




> 
> > I have the appropriate encoding hint at the top of my .py files  # -*-
> > coding: utf-8 -*-
> 
> My understanding is that that is for Python 2 for parsing the code file itself and \
> would not be relevant here. 
> Cheers,
> -kyle
> _______________________________________________
> PyQt mailing list    PyQt@riverbankcomputing.com
> https://www.riverbankcomputing.com/mailman/listinfo/pyqt


[Attachment #5 (text/html)]

<html><head><meta http-equiv="content-type" content="text/html; \
charset=utf-8"></head><body \
dir="auto"><div><br></div><div><div><br><br>Barry<div><br></div></div>On 7 Feb 2017, \
at 22:28, Kyle Altendorf &lt;<a href="mailto:sda@fstab.net">sda@fstab.net</a>&gt; \
wrote:<br><br></div><blockquote type="cite"><div><span>On 2017-02-07 16:47, Dave \
Gradwell wrote:</span><br><blockquote type="cite"><span>If my pyqtdeploy'ed app is \
run from under pyqtdeploy itself (with the</span><br></blockquote><blockquote \
type="cite"><span>‘run application' checkbox) then it can send UTF-8 characters to \
the</span><br></blockquote><blockquote type="cite"><span>Python logging module, which \
end up in a log file — which is good. &nbsp;It</span><br></blockquote><blockquote \
type="cite"><span>also works fine in interpreted/development mode, i.e., \
unpackaged.</span><br></blockquote><blockquote type="cite"><span>But if I quit \
pyqtdeploy and immediately just double click the \
(now</span><br></blockquote><blockquote type="cite"><span>packaged) app then it fails \
to log UTF-8 with the error message</span><br></blockquote><blockquote \
type="cite"><span>"UnicodeEncodeError: 'ascii' codec can't encode character '\xfc' \
in</span><br></blockquote><blockquote type="cite"><span>position 66: ordinal not in \
range(128)"</span><br></blockquote><span></span><br><span>Is this Windows? &nbsp;Is \
it a GUI application? &nbsp;If so, I found that when deployed my sys.stdout and \
sys.stderr were actually None. &nbsp;I won't recommend what I have done as _good_ but \
I will share it in case it is _useful_ at least for \
exploration.</span><br><span></span><br><span><a \
href="https://github.com/altendky/st/blob/master/epyq/__main__.py#L11-L24">https://github.com/altendky/st/blob/master/epyq/__main__.py#L11-L24</a></span><br><span><a \
href="https://github.com/altendky/st/blob/26bfdb5a8409e20e9fc6870f6a9e56ddc516f65b/epy \
qlib/tee.py">https://github.com/altendky/st/blob/26bfdb5a8409e20e9fc6870f6a9e56ddc516f65b/epyqlib/tee.py</a></span><br><span></span><br><span>Roughly \
speaking I replace sys.stdout and sys.stderr *shudder* with either my log file or my \
tee object which sends to both the file and stdout/err. &nbsp;Nasty, but without it I \
was flying totally blind except that my application stopped running. &nbsp;Someday \
I'll do a proper logging \
solution.</span><br></div></blockquote><div><br></div><div>What I do for Windows is \
intercept writes to stdout and stderr and write them the logging \
system.</div><div><br></div><div>See the the logging code in&nbsp;<a \
href="https://github.com/barry-scott/scm-workbench/blob/master/Source/Common/wb_loggin \
g.py">https://github.com/barry-scott/scm-workbench/blob/master/Source/Common/wb_logging.py</a></div><div><br></div><div>And \
the setup in&nbsp;<a \
href="https://github.com/barry-scott/scm-workbench/blob/master/Source/Common/wb_app.py \
">https://github.com/barry-scott/scm-workbench/blob/master/Source/Common/wb_app.py</a></div><div><br></div><div>The \
features I needed are:</div><div>* log rotation and max size limits</div><div>* \
optionally capture stdout and stderr - always on for production</div><div>* \
optionally output log to stdout - used while debugging</div><div>* output to Qt \
Widget</div><div><br></div><div><br></div><div><br></div><div><br></div><blockquote \
type="cite"><div><span></span><br><blockquote type="cite"><span>I have the \
appropriate encoding hint at the top of my .py files &nbsp;# \
-*-</span><br></blockquote><blockquote type="cite"><span>coding: utf-8 \
-*-</span><br></blockquote><span></span><br><span>My understanding is that that is \
for Python 2 for parsing the code file itself and would not be relevant \
here.</span><br><span></span><br><span>Cheers,</span><br><span>-kyle</span><br><span>_______________________________________________</span><br><span>PyQt \
mailing list &nbsp;&nbsp;&nbsp;<a \
href="mailto:PyQt@riverbankcomputing.com">PyQt@riverbankcomputing.com</a></span><br><span><a \
href="https://www.riverbankcomputing.com/mailman/listinfo/pyqt">https://www.riverbankcomputing.com/mailman/listinfo/pyqt</a></span></div></blockquote></body></html>



[Attachment #6 (text/plain)]

_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
https://www.riverbankcomputing.com/mailman/listinfo/pyqt

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic