Python logging doesn't work when script is called from another program


I have a python script that I use with LibreOffice Calc to do some more advanced macros. I need to debug this script and I’m trying to use logging for this. Logging works fine when the script is called from the command line, but it doesn’t work at all when the script is called by LibreOffice.

Here is my logging test code:

import logging
logging.basicConfig(filename='test.log', level=logging.INFO)

As requested, here is the LibreOffice Basic script that calls the Python script (this was mostly just a copy/paste from a guide on how to call Python scripts from LO):

function cev(a as String) as double
Dim scriptPro As Object, myScript As Object
Dim a1(1), b1(0), c1(0) as variant
a1(0) = ThisComponent
a1(1) = a
scriptPro = ThisComponent.getScriptProvider()
myScript = scriptPro.getScript( _
cev = myScript.invoke(a1, b1, c1)
end function

The basic script is called on a single cell using CEV(cellAddress), which passes the contents of the cell through to the Python script as a string.

Asked By: synthc



Maybe it is working but you just don’t know where test.log file is getting placed when it runs from LibreOffice. Try providing an absolute file path for test.log, like let’s say C:/test.log.

Answered By: Emrah Diril

Well, I updated to LibreOffice 7 and this started working. The Python version in LO 7 is 3.8 instead of 3.5, so maybe that made the difference.

Answered By: synthc
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.