When you use the --onefile option, PyInstaller extracts your code into a temporary directory (e.g. _MEIxxxxx) and executes from there.
So your script’s working directory isn’t the same as where the .exe file is located.
That’s why your log file isn’t created next to your .exe.
To fix this, explicitly set your log file path to the same folder as the executable:
import sys, os, logging
if getattr(sys, 'frozen', False):
# Running as bundled exe
application_path = os.path.dirname(sys.executable)
else:
# Running from source
application_path = os.path.dirname(os.path.abspath(__file__))
log_path = os.path.join(application_path, "log.log")
logging.basicConfig(filename=log_path, level=logging.INFO, filemode='w')
Now the log file will be created next to your .exe file, not in the temporary _MEI... directory.