print in python files not arriving in logs

From the python orthanc documentation I can see that a print in python should end up in the orthanc logs. However that doesn’t seem to be happening.

Orthanc.json:

{

“PythonScript” : “C:\Program Files\Orthanc Server\scripts\forwardSeriesToWBxPy.py”,


}

forwardSeriesToWBxPy.py:

print(‘hello world’)

Orthanc logs:

W1007 11:42:54.511983 main.cpp:1942] Orthanc version: 1.9.3
W1007 11:42:54.511983 OrthancConfiguration.cpp:117] Scanning folder “Configuration” for configuration files
W1007 11:42:54.511983 OrthancConfiguration.cpp:66] Reading the configuration from: “Configuration\dicomweb.json”
W1007 11:42:54.511983 OrthancConfiguration.cpp:66] Reading the configuration from: “Configuration\mysql.json”
W1007 11:42:54.511983 OrthancConfiguration.cpp:66] Reading the configuration from: “Configuration\orthanc.json”
W1007 11:42:54.511983 OrthancConfiguration.cpp:66] Reading the configuration from: “Configuration\postgresql.json”
W1007 11:42:54.511983 OrthancConfiguration.cpp:66] Reading the configuration from: “Configuration\serve-folders.json”
W1007 11:42:54.511983 OrthancConfiguration.cpp:66] Reading the configuration from: “Configuration\stone-webviewer.json”
W1007 11:42:54.527639 OrthancConfiguration.cpp:66] Reading the configuration from: “Configuration\transfers.json”
W1007 11:42:54.527639 OrthancConfiguration.cpp:66] Reading the configuration from: “Configuration\webviewer.json”
W1007 11:42:54.527639 OrthancConfiguration.cpp:66] Reading the configuration from: “Configuration\worklists.json”
W1007 11:42:54.684105 main.cpp:864] Loading plugin(s) from: C:\Program Files\Orthanc Server\Plugins
W1007 11:42:54.684105 PluginsManager.cpp:269] Registering plugin ‘connectivity-checks’ (version 1.9.3)
W1007 11:42:54.684105 PluginsManager.cpp:269] Registering plugin ‘stone-webviewer’ (version 1.0)
W1007 11:42:54.684105 PluginsManager.cpp:269] Registering plugin ‘worklists’ (version 1.9.3)
W1007 11:42:54.684105 PluginsManager.cpp:168] Sample worklist plugin is initializing
W1007 11:42:54.684105 PluginsManager.cpp:168] Worklist server is disabled by the configuration file
W1007 11:42:54.684105 PluginsManager.cpp:269] Registering plugin ‘authorization’ (version 0.2.4)
W1007 11:42:54.684105 PluginsManager.cpp:168] Initializing the authorization plugin
W1007 11:42:54.684105 PluginsManager.cpp:168] No section “Authorization” in the configuration file, the authorization plugin is disabled
W1007 11:42:54.699791 PluginsManager.cpp:269] Registering plugin ‘dicom-web’ (version 1.6)
W1007 11:42:54.699791 PluginsManager.cpp:168] URI to the DICOMweb REST API: /dicom-web/
W1007 11:42:54.699791 PluginsManager.cpp:168] URI to the WADO-URI API: /wado
W1007 11:42:54.699791 PluginsManager.cpp:269] Registering plugin ‘gdcm’ (version 1.2)
W1007 11:42:54.699791 PluginsManager.cpp:168] Version of GDCM: 3.0.8
W1007 11:42:54.699791 PluginsManager.cpp:168] GDCM throttling is disabled
W1007 11:42:54.699791 PluginsManager.cpp:269] Registering plugin ‘mysql-index’ (version 4.0)
W1007 11:42:54.699791 PluginsManager.cpp:168] The MySQL index is currently disabled, set “EnableIndex” to “true” in the “MySQL” section of the configuration file of Orthanc
W1007 11:42:54.699791 PluginsManager.cpp:269] Registering plugin ‘mysql-storage’ (version 4.0)
W1007 11:42:54.715464 PluginsManager.cpp:168] The MySQL storage area is currently disabled, set “EnableStorage” to “true” in the “MySQL” section of the configuration file of Orthanc
W1007 11:42:54.715464 PluginsManager.cpp:269] Registering plugin ‘osimis-cloud’ (version 0.3)
W1007 11:42:54.715464 PluginsManager.cpp:269] Registering plugin ‘postgresql-index’ (version 4.0)
W1007 11:42:54.715464 PluginsManager.cpp:168] The PostgreSQL index is currently disabled, set “EnableIndex” to “true” in the “PostgreSQL” section of the configuration file of Orthanc
W1007 11:42:54.715464 PluginsManager.cpp:269] Registering plugin ‘postgresql-storage’ (version 4.0)
W1007 11:42:54.715464 PluginsManager.cpp:168] The PostgreSQL storage area is currently disabled, set “EnableStorage” to “true” in the “PostgreSQL” section of the configuration file of Orthanc
W1007 11:42:54.715464 PluginsManager.cpp:269] Registering plugin ‘python’ (version 3.4)
W1007 11:42:54.715464 PluginsManager.cpp:168] Python plugin is initializing
W1007 11:42:54.715464 PluginsManager.cpp:168] Using Python script “forwardSeriesToWBxPy.py” from directory: C:\Program Files\Orthanc Server\scripts
W1007 11:42:54.715464 PluginsManager.cpp:168] Program name: C:\Program Files\Orthanc Server\Orthanc.exe
W1007 11:42:54.730974 PluginsManager.cpp:269] Registering plugin ‘transfers’ (version 1.0)
W1007 11:42:54.730974 PluginsManager.cpp:269] Registering plugin ‘web-viewer’ (version 2.7)
W1007 11:42:54.730974 PluginsManager.cpp:168] Initializing the Web viewer
W1007 11:42:54.730974 PluginsManager.cpp:168] Web viewer using 6 threads for the decoding of the DICOM images
W1007 11:42:54.730974 PluginsManager.cpp:168] Storing the cache of the Web viewer in folder: C:\Orthanc\WebViewerCache
W1007 11:42:54.746640 PluginsManager.cpp:168] Web viewer using a cache of 100 MB
W1007 11:42:54.746640 PluginsManager.cpp:269] Registering plugin ‘wsi’ (version 1.0)
W1007 11:42:54.746640 PluginsManager.cpp:168] The whole-slide imaging plugin will use at most 12 threads to transcode the tiles
W1007 11:42:54.760695 PluginsManager.cpp:269] Registering plugin ‘osimis-web-viewer’ (version 1.4.2.0-9d9eff4)
W1007 11:42:54.760695 PluginsManager.cpp:168] Initializing the Web viewer
W1007 11:42:54.760695 PluginsManager.cpp:168] Using GDCM instead of the DICOM decoder that is built in Orthanc
W1007 11:42:54.762232 PluginsManager.cpp:269] Registering plugin ‘serve-folders’ (version 1.9.3)
W1007 11:42:54.762232 PluginsManager.cpp:168] ServeFolders: Empty configuration file: No additional folder will be served!
W1007 11:42:54.762232 OrthancInitialization.cpp:329] SQLite index directory: “C:\Orthanc”
W1007 11:42:54.762232 OrthancInitialization.cpp:425] Storage directory: “C:\Orthanc”
W1007 11:42:54.762232 HttpClient.cpp:1176] HTTPS will use the CA certificates from this file: C:\Program Files\Orthanc Server\Configuration\ca-certificates.crt
W1007 11:42:54.762232 LuaContext.cpp:93] Lua says: Lua toolbox installed
W1007 11:42:54.762232 LuaContext.cpp:93] Lua says: Lua toolbox installed
W1007 11:42:54.762232 ServerContext.cpp:478] Disk compression is disabled
W1007 11:42:54.762232 ServerIndex.cpp:391] No limit on the number of stored patients
W1007 11:42:54.762232 ServerIndex.cpp:411] No limit on the size of the storage area
W1007 11:42:54.762232 ServerContext.cpp:220] Reloading the jobs from the last execution of Orthanc
W1007 11:42:54.762232 JobsEngine.cpp:271] The jobs engine has started with 2 threads
W1007 11:42:54.762232 main.cpp:1249] DICOM server listening with AET MIRADAPLATFORM on port: 4242
W1007 11:42:54.762232 HttpServer.cpp:1992] HTTP compression is enabled
W1007 11:42:54.762232 main.cpp:1010] Remote access is allowed but “AuthenticationEnabled” is not in the configuration, automatically enabling HTTP authentication for security
W1007 11:42:54.762232 main.cpp:1036] ====> HTTP authentication is enabled, but no user is declared. Creating a default user: Review your configuration option “RegisteredUsers”. Your setup is INSECURE <====
W1007 11:42:54.762232 main.cpp:1124] Remote LUA script execution is disabled
W1007 11:42:54.777867 HttpServer.cpp:1769] HTTP server listening on port: 8042 (HTTPS encryption is disabled, remote access is allowed)
W1007 11:42:54.777867 main.cpp:876] Orthanc has started

Hello world never appears in the logs. Is there anything I need to do to get it to log those print statements?

Hi,

Actually, the python print goes to stdout which, in docker, gets into the “logs” because docker logs are made of stderr and stdout.

On Windows, you only get the orthanc logs, not stdout. You should therefore use
orthanc.LogInfo()
orthanc.LogWarning()

HTH

Alain.

Awesome, that works. Thanks!

Hello,
This can be achieved by creating a handler that redirect logs to sys stdout :slight_smile:

import threading
import orthanc
import multiprocessing
import json
import signal
import logging
import sys

root = logging.getLogger()
root.setLevel(logging.INFO)
handler = logging.StreamHandler(sys.stdout)
handler.setLevel(logging.INFO)
formatter = logging.Formatter(‘%(asctime)s p%(process)d %(levelname)s - %(message)s’)
handler.setFormatter(formatter)
root.addHandler(handler)

Then use it like this:

logging.info(“Kafka on stable study event enabled: %s”, basic_config[‘kafka_enabled’])

Enjoy!