Page MenuHomePhabricator

All pywikibot logging seems to be dumped in pwb-bot.log instead of different files
Open, LowPublic

Description

For some reason all Pywikibot logging ends up in pwb-bot.log now instead of <name of script>-bot.log. This is very annoying when you run multiple bots and you want to debug one of them. pwb.py is a wrapper so it should also wrap around the logging.

My logging configuration in user-config.py:
log = ['*']

I run Pywikibot: [https] r-pywikibot-core.git (75134ba, g7223, 2016/04/21, 22:05:31, ok)

Event Timeline

Did some more digging. Might be around a bit longer and I just started using the pwb.py wrapper more often. I do have a login-bot.log from Apr 22 20:13 when I ran pwb.py login.py, The "/usr/bin/python /data/project/multichill/pywikibot/pwb.py /data/project/multichill/code/bot/wikidata/getty_import.py" seem all to end up in the pwb-bot.log so maybe that doesn't get parsed properly?

You need to call pywikibot.handle_args() to set up logging:

import pywikibot
pywikibot.error('boo!')

will log to pwb-bot.log,

import pywikibot
pywikibot.handle_args()
pywikibot.error('boo!')

will log to <name>-bot.log.

You need to call pywikibot.handle_args() to set up logging:

Looks like a good work around, but not really a fix. pwb.py should just initialize this.

I thought this is called automatically when running bot.py (so every time when running any class built on Bot class)?

I thought this is called automatically when running bot.py (so every time when running any class built on Bot class)?

Yes, I believe the Bot class will call handle_args. I think Maarten's point is that pwb.py should be transparent to the logging layer, so

python script.py

and

python pwb.py script.py

should be equivalent in terms of logging. I think the first will log to script-bot.log, while the second will log to pwb-bot.log

I think the first will log to script-bot.log, while the second will log to pwb-bot.log

Per my testing both log into script-bot.log, if Bot class used in script, only the latter logs the call itself (one line) into pwb-bot.log. Should we close this as invalid or call handle_args (or some other logging initializer) in pwb.py already (before loading bot class)?

Maybe it makes more sense in a table:

python script.pypython pwb.py script.py
script calls handle_argsscript-bot.logscript-bot.log
script only calls pywikibot.logscript-bot.logpwb-bot.log

so if a script doesn't call handle_args, the behavior differs between calling through pwb.py or not, and this is inconsistent.

The best way would be that all scripts calls handle_args which they didn’t currently. But this could be needed to show deprecation warnings in debug mode.
Can’t we implement a mechanism to process something like handle_args and store the unhandled options in a variable to be returned if hande_args is really called. I guess there is no script which overwrites the global options.

Xqt triaged this task as Low priority.Jun 5 2018, 5:13 AM

> I guess there is no script which overwrites the global options.

At least we could easily find them.