Working on a Cinnamon applet (Example). These use Javascript interpreted by the cjs interpreter and run without a console window.
How can I log something to a file or to a console from within the code I am working on?
I can not put test code into a separate Javascript file and run it with cjs <the file>, because there I do not have access to modules provided to applets by Cinnamon.
Logging
To log from the javascript:
To inspect things, including objects with possibly circular references, define this function:
and use it like so:
or like so, to hide keys starting with underscores:
or like so, to fold specific keys you are not interested in:
Viewing the log
To view the logged messages, either use the console or a GUI (or both).
Using the console
Or, prior to Cinnamon 3.8.8:
Press
ctrl+cto abort the logging.To reload the applet:
where
your-applet-uuidis the value of theuuidkey in metadata.json.It is simplest to run this command from another console, so you do not have to abort the logging.
Using a GUI
Cinnamon also has the Melange-Cinnamon debugger. To open it:
Win key+L.Alt+F2→ type "lg" →Enter.The logging happens under the log tab.
To reload the code of the applet, find it under the extensions tab, right click → reload code.
To reload Cinnamon and do other things, use the Actions button.
The debugger has a small bug, sometimes the scroll bar disappears when long stuff gets logged. To get it back, press
ctrl+Homeandctrl+End.To be able to have the debugger window in the background, right click its title bar.
Kudos
refReplacerfunction