jenkins-bot has submitted this change. (
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/692624 )
Change subject: [IMPR] Use different logfiles for multiple processes (Step 2)
......................................................................
[IMPR] Use different logfiles for multiple processes (Step 2)
Use different logfiles if multiple processes of the same script are running
to prevent WindowsError/PermissionError when renaming a file. This also
prevents having different mixed logs in the same file.
- if config.logfilename is used this will be kept unchanged
- otherwise the logfilename is changed from <scriptname>-bot.log
to <scriptname>-<pid>-bot.log if PID is not 1
Bug: T56685
Change-Id: I38937c3060d4653d1ffe8a8d9b918a8548907ab0
---
M pywikibot/bot.py
1 file changed, 11 insertions(+), 3 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/bot.py b/pywikibot/bot.py
index 86ab1d7..219601d 100644
--- a/pywikibot/bot.py
+++ b/pywikibot/bot.py
@@ -103,7 +103,7 @@
from warnings import warn
import pywikibot
-from pywikibot import config, daemonize, i18n, version
+from pywikibot import config, daemonize, i18n, throttle, version
from pywikibot.backports import Dict, Iterable, List, Sequence
from pywikibot.bot_choice import (
AlwaysChoice,
@@ -346,11 +346,19 @@
# if user has enabled file logging, configure file handler
if module_name in config.log or '*' in config.log:
+ # get PID
+ pywikibot.Site().throttle # initialize a Throttle object and set PID
+ pid = throttle.pid # get the global PID
+ pid = str(pid) + '-' if pid > 1 else ''
+
if config.logfilename:
+ # keep config.logfilename unchanged
logfile = config.datafilepath('logs', config.logfilename)
else:
- logfile = config.datafilepath('logs', '{}-bot.log'
- .format(module_name))
+ # add PID to logfle name
+ logfile = config.datafilepath('logs', '{}-{}bot.log'
+ .format(module_name, pid))
+
file_handler = RotatingFileHandler(filename=logfile,
maxBytes=1024 * config.logfilesize,
backupCount=config.logfilecount,
--
To view, visit
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/692624
To unsubscribe, or for help writing mail filters, visit
https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I38937c3060d4653d1ffe8a8d9b918a8548907ab0
Gerrit-Change-Number: 692624
Gerrit-PatchSet: 3
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Bináris <wikiposta(a)gmail.com>
Gerrit-Reviewer: JAn Dudík <jan.dudik(a)gmail.com>
Gerrit-Reviewer: Mpaa <mpaa.wiki(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged