I am starting a python application (exe version created using pyInstaller)
from a windows service (created in python, converted to exe using
pyinstaller and installed using sc) but the log files generated by my
application are not getting rotated. The code creates one log file and
after it gets filled upto set limit for rotation, the logs just get stuck
there while the code keeps on working perfectly fine.
So I have actually used a logger.conf file which has logger configuration
with rotatingFileHandler to rotate file after every 10KBs (for testing
purpose). The configuration in conf file looks like this:
...
[handler_fileRotationHandler]
class=logging.handlers.RotatingFileHandler
level=NOTSET
formatter=simpleFormatter
args=('<absolute path of log file>','a',10240,5)
...
Inside python code I am using this config to create and rotate log files
like below code:
...
import common
import os
import sys
import logging
import logging.config
#current working directory path of script
if getattr(sys, 'frozen', False):
# we are running in a bundle
common.COMMON_PATH = sys._MEIPASS
else:
# we are running in a normal Python environment
common.COMMON_PATH = os.path.dirname(os.path.abspath(__file__))
#locations
common.LOG_FILE=common.COMMON_PATH+'/logging.conf'
#logger config
logging.config.fileConfig(common.LOG_FILE)
common.logger = logging.getLogger('<name of logger from logging.conf>')
logger = common.logger
...
In above code snippet, common.py is a python file created for declaring and
initializing some common vars of whole source code.
*Here is a list of cases when proper log file rotation works:*
1- The python version started using python command
2- The exe version (created using PyInstaller) works fine when launched by
double clicking directly
3- The exe version when started from a windows service also created in
python, if service is installed using python commands like below:
MyService.py install
*Now here is when it does not work:*
I am converting the windows service code to exe (using pyInstaller again)
and install the service with sc using below command:
sc create MyService binPath= "<absolute path of service exe file>"
When started using this service, the application works fine, and log file
is generated too, but after reaching the max size defined in fileHandler
for log, it does not create another log file and thus gets stuck in terms
of log there only. The application keeps on working perfectly fine, just
logs doesn't get recorded.
*Here is what I have tried and observed:*
1- In both cases, I have launched my app exe version using
subprocess.Popen() command and my application does not have any UI element,
so it runs perfectly in windows session 0 in background. Just for the
information, in case it is relevant.
2- If I remove existing log statements and empty log file, logs start to
get logged in the file and again stop when max size reach.
3- I have used os.getcwd() command to get directory where my app runs when
launched in both cases for which I found below directories:
in python service installed using python case, app runs in
"C:\Users\nirvan\AppData\Local\Programs\Python\Python36\lib\site-packages\win32"
while in exe version launched from service installed using sc case, app
runs in "C:\Windows\system32"
Although in both cases, the logging.conf file provides the log file
creation path, so I am assuming this should not be any issue (in fact, log
file does gets created at expected location, just file rotation does not
work, so this I guess is not relevant)
I need to use the exe version installed by sc only and not python service
version. How to solve this issue, any help or guidance or direction is
appreciated.
--
You received this message because you are subscribed to the Google Groups
"PyInstaller" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/pyinstaller.
To view this discussion on the web visit
https://groups.google.com/d/msgid/pyinstaller/509fd0ab-996b-4f56-925f-bb7523b48bd4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.