abidinamdar / gmapcatcher

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

Use more powerful logging mechanism #134

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What new or enhanced feature are you proposing?
Using logging mechanism (python logging module)

What goal would this enhancement help you achieve?
When application is running some errors or other "helper" informations are
displayed to the standard out.
It is possible to use logging engine "import logging" and set it to log to
the console, file,... set different levels for console, file,...

1. For released app logging would be set (for example) to log to file in
home directory with severity "Error" or maybe no output at all.
2. it will be possible to set more finer severity when needed - (for
example) Warning, Info, Debug,... . Like in case of debugging or when
reproducing error - you have problem? set Debug and send logs.
3. change settings dialog to set the logging severity and log file name/path.
4. no need to adjust source code to "get rid" of undesirable outputs.

Original issue reported on code.google.com by standa31...@gmail.com on 2 Mar 2010 at 9:45

GoogleCodeExporter commented 8 years ago
getting error in windows, the file maps.exe.log used to be created only when 
there was a real error

Original comment by heldersepu on 6 Nov 2010 at 3:26

GoogleCodeExporter commented 8 years ago
If I understand correctly:
- maps.py - used in linux writes output to standard out and stderr - on console
User must use output redirecting to catch output into file. No file is 
generated automaticly.
- maps.py - used in windows writes output to standard out and stderr - on 
console
User must use output redirecting to catch output into file. No file is 
generated automaticly.
- maps.exe - generated by p2exe - uses default behavior - ignores stdout, 
stderr writes into mqps.exe.log and displays dialog box "See the logfile for 
details". File maps.exe.log is generated automaticly if anything is printed to 
stderr.

Using logging module will give more control over log output.

Implementation proposition:
- log format will be set in mapsConst.py
- log file path and name will be set in mapsConst.py
- default log level will be set to error. So only messages with severity error 
or higher will be logged.
- log file name will be: gmapcatcher.log
- log file will be overwriten on each gmapcatcher restart
- for log file path I suggest to use same directory where gmapcatcher.conf is 
placed. We need to do some writing into directory. We know, that it is possible 
for directory. Directory with maps.exe is dedicated for program code. It should 
not be used for program generated output.
- all exceptions should be catched. In exception handler exception would be 
dealt and/or logged using logging.
- all output to stderr should be logged using logging mechanism with severity 
error or higher.

Change to current behavior - is it OK?
- stderr will be overriden to output file in same directory with 
gmapcatcher.conf. If there is still some output to stderr, which should not be, 
we don't want to lost it. After redirecting there will be no message after 
closing maps.exe even thought there was an output to stderr.

Using logging mechanism should be something like:
import logging
log = logging.getLogger(__name__)

and anywhere in the code use:
log.<log_level_function>( message )

If there are no objections with proposed behavior I will replace print 
statements with logging in the existing code.

Original comment by standa31...@gmail.com on 10 Nov 2010 at 7:59

GoogleCodeExporter commented 8 years ago
Re-commited.
Hope it's better now - not changing default behavior.
See docstrings in r1075

Please report if there is a problem in any situations.

Original comment by standa31...@gmail.com on 19 Nov 2010 at 6:04

GoogleCodeExporter commented 8 years ago
Good, I just made windows installer and no problems
I guess we should provide an easy way to change the "default behavior" instead 
of having the log format set in mapsConst.py we should consider add it to the 
mapConf.py just like 'auto_refresh' is an option that the user can modify in 
the configuration file.

Original comment by heldersepu on 22 Nov 2010 at 1:43

GoogleCodeExporter commented 8 years ago
Reason I used mapConst is to have logging set up as fast as possible. Befor 
configuration file is read. IMO logging should be able to catch error messages 
while reading config file. 

Logging settings is in-fact configuration setting so it should go to 
configuration file. So maybe some hybrid solution - like - set basics in 
mapConst - to catch readConfigu errors and after config file is read modify 
settings to users-like?

Original comment by standa31...@gmail.com on 23 Nov 2010 at 10:32

GoogleCodeExporter commented 8 years ago
hybrid Sounds great! we keep the default in mapConst and if there is a 
"logging=1" we change the log level to something else

Original comment by heldersepu on 23 Nov 2010 at 1:48

GoogleCodeExporter commented 8 years ago
I been reading more your code and I see that the "default behavior" changes 
when the user enters "--logging-path=" as one of the args. That is enough no 
need to add it to the mapConf.py

Original comment by heldersepu on 23 Nov 2010 at 3:17

GoogleCodeExporter commented 8 years ago
OK, I'm fine with that. :)

Original comment by standa31...@gmail.com on 24 Nov 2010 at 8:25