Debug plugins with a log file

• Mar 3, 2023 - 09:08

We cant use console.log anymore, so i needed a tool to display log messages.
For that i created a component named DebugTools.

Usage :
1)add the component in the plugin directory (documents/musescore4/plugins/mplugin)
2)Add the reference part in your main plugin.
3)Use the methods
This was written for MS4 but could be easily adapted to other versions.

I use that tools also to dump different objects (segment, element ,..) but this is another story !

Attachment Size
DebugTools1.PNG 58.26 KB
DebugTools2.PNG 50.19 KB
Modele.PNG 26.24 KB


In reply to by parkingb

Little suggestion. The console object has other interesting log methods such as trace, warn and error.
This could be nice to have similar functions in you Item.
That way the info written to the file could be prefixed with the level of the debug (similar to the PatternLayout of Log4j):

[TRACE] Culpa occaecati rerum optio qui. 
Et doloremque voluptas et eligendi aperiam. 
[WARN] Fugiat molestiae voluptas qui voluptatem aperiam.
[ERROR] Et aut distinctio officiis. Ut consequatur quaerat et quisquam. 

In reply to by dominiqueverriere

The only part I'm doubtful it will work is using this approach for logging in separated ".js" files.
I put most of my plugin code in external javascript files that I can reuse across all my plugin(*)
I wonder if I could manage to access that debugTools item from those javascript libraries...
I'll have a try.

(*): That I call with qml statements such as
import "selectionhelper.js" as SelHelper
and then calls such as
var chords = SelHelper.getChordsFromCursor(curScore)

Do you still have an unanswered question? Please log in first to post your question.