pixels4nickels / webiopi

Automatically exported from code.google.com/p/webiopi
0 stars 0 forks source link

can not use logging to the file together with webiopi #120

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

import logging
logging.basicConfig(filename='example.log',level=logging.DEBUG)
logging.debug('This message should go to the log file')
import webiopi
logging.info('This message should also go to the log file, but is displayed in 
Terminall window after importing webiopi')

WebIOPi version used?
=>0.0.7

Python version used?
=> 2.7

Distro used? (WebIOPi has only been tested on Raspbian Wheezy)
=> Yes- raspian Wheezy

Raspberry Pi board revision? (1 or 2)
=> B+

For Javascript side bugs, Browser?
=>

Please provide any additional information below.

Original issue reported on code.google.com by maciej2...@gmail.com on 21 Sep 2014 at 12:59

GoogleCodeExporter commented 9 years ago
See info on this wiki page how to enable file logging and debugging within 
WebIOPi:

https://code.google.com/p/webiopi/wiki/INSTALL?tm=6

Just use the -l and -d options in interactive mode.

You can also set this for the webiopi daemon, just modify the coresponding 
command that starts webiopi as daemon. However, when run as daemon webiopi 
already logs to a file being /var/log/webiopi by default.

You find the details in webiopi.init.sh, but this is just the template, do not 
modify anything here unless you call setup.sh again (and know what you do ...).

Andreas

Original comment by andreas....@googlemail.com on 22 Sep 2014 at 7:47

GoogleCodeExporter commented 9 years ago
Hi Andreas, 

I would like to apologize for my not clear issue description. 

The problem I have rised is not linked to WEBIOPI logging features, that I have 
tested and it works OK.

The problem I faced is in my app in Python and influance (I guess) of WEBIOPI 
on standard Python logging module.  

I would like to use your module for some home automation features. I want to 
use module "logging", which is included in Python to save in my app's log file 
history of running it. 

The problem is, that after invoking WEBIOPI module in Python (using "import 
webiopi") all ma log request (i.e."logging.debug('XXXXXXX')) are not saved in 
log file but displayed in terminal window. 

If I will try to run the same Python code without "import webiopi" everything 
is working fine. All log requests are saved in my log file. 

The problem appears right after "import webiopi", before using WEBIOPI 
functions, classes etc. Just importing breaking logging feature :(

# the line below: works OK
import logging

# the line below: works OK
logging.basicConfig(filename='example.log',level=logging.DEBUG)

# the line below: works OK
logging.debug('This message should go to the log file')

# the line below: works OK - but from the moment "logging" is not working 
properly.

import webiopi

# the line below: does no works. The text shoul be saved in log file but is 
not. Is displayed in terminal window.

logging.info('This message should also go to the log file, but is displayed in 
Terminall window after importing webiopi')

br, 
maciej

Original comment by maciej2...@gmail.com on 22 Sep 2014 at 7:42

GoogleCodeExporter commented 9 years ago
Yes, this is right and works as designed so far ... at least in the current 
release and how Eric implemented it.

If you import webiopi, you also import webiopi logging (see 
webiopi/utils/logger.py) and this grabs and configures the root logger. Your 
basic logger configuration will just be overwritten, as you discovered, after 
the import statement.

BUT, if you look at the code, WebIOPi looks to be able to log simultaneous to 
console AND log file (if you configure the log file using the -l parameter).

You may be able to create your own logger (logging.getLogger('mylogger') so 
that you can get different log entries (in the SAME log file) that can be 
distinguished by their different names. You may be also able to set different 
log levels for your logger, but I'm not sure if this works as WebIOPi sets 
currently direct the log level for the root logger, but you may try it. You may 
also be able to set a different file handler to your specific logger, but it is 
not recommended to do so according to the Python documentation.

See here (https://docs.python.org/2/howto/logging-cookbook.html) for very 
helpful tips and code examples on Python logging.

Andreas

Original comment by andreas....@googlemail.com on 23 Sep 2014 at 7:05