Synopsis
This post explains how to use the ImageJ2/Fiji logging services (SciJava/LogService) in your Jython plugin with a working example.
TL;DR - view the example section for a quick start.
This work is licensed under CC BY-SA 4.0
Logging in ImageJ
Legacy ImageJ logging is performed using the IJ.log(String message)
method. Logging using this results in a separate “Log” window that records all logged messages. All modern logging capabilities are missing (filters, sources, etc.)
Modern ImageJ2/Fiji logging is based on SciJava’s LogService. ImageJ2 ships with a logback-classic implementation. Upon ImageJ2 initializaton, a LogService is automatically initialized. To ask for the instance in a Java class, parameter annotation should be used:
|
|
Jython does not seem to support Java annotation OOB. To ask for LogService instance, use ImageJ2’s scripting parameters syntax:
|
|
Example: modern logging in Fiji/ImageJ2
My ImageJ2 update site provides a minimal Jython module for logging. Install the y3628.sjlogging
Jython submodule from my update site (path = jars/Lib/y3628/
) before proceeding.
Say we have a plugin organized as follows:
|
|
In the main program my_plugin_main.py
, initialize sjlogging
once:
|
|
Then, your can initialize an arbitrary number of Logger in both the main program under plugins/
and submodules under jars/Libs/
:
|
|
Logs will be forwarded to the Console window of ImageJ2. By default, unless you log messages at the ERROR/WARN
levels, the Console window will not pop on its own. Also, logs from different sources are separated beautifully in the Console/Log dialog.
For a complete view of the sjlogging
module used in a real plugin, refer to my plugin punctaTracker on Github. You are more than welcome to raise new issues about the sjlogging
module there also.