Sublime Forum

SublimeLog — On-the-fly ST2 console logging

#1

I just released the first version of this very simple plugin to dump a log of the ST2 console into the disk.

The plugin is available at https://github.com/yrammos/SublimeLog.

Please note that I’ve only been able to test this on a OS X, so please do let me know of any issues should you have a Linux or Windows machine.

The package is not yet available via Package Control but I will submit it there as soon as I have a couple of confirmations that it works well on Linux and Windows.

Instructions and important notes are available on GitHub.

Enjoy!


As a collateral benefit, this plugin should meet the needs of those who have been wishing a separate console window. To do this, just open your terminal and run:

tail -f ~/.subl.log

… possibly replacing ~/.subl.log with the path and name of your log file.

This will provide you with a live stream of the ST2 console output in the terminal window.

On Windows, the tail command is available as part of the GNU Utilities for Win32 package http://unxutils.sourceforge.net/.

0 Likes

#2

Thanks, this seems to work pretty well on Win-64. Oddly not everything in the console gets logged however (notably the ‘Writing file /C/blah.txt with encoding UTF-8’ messages don’t get logged.

I’d like to see an option to automatically enable logging on startup if possible.

0 Likes

#3

Thanks for your feedback, RyanJ, and my apologies for the belated response. I somehow failed to notice the topic.

Indeed, a small number of messages are not logged by the package, including the one you mention (“Writing file…”). Another class of such messages are actual Python commands typed at the console prompt. For example, if you open the console and type

print "Hello"

the window will display

>>> print "Hello" Hello
but SublimeLog will only log

Hello

I have so far not discovered any other classes of “missed” messages and, to my knowledge, everything else gets captured as expected.

I have been unable to figure out the cause of this glitch. It is possible that Sublime Text does not use the standard output pipe — which is “wiretapped” by the logger plugin — for these recalcitrant messages.

I am sorry for the inconvenience and will be sure to update the plugin accordingly if I come across a “clean” workaround.

0 Likes

#4

[quote=“yrammos”]Thanks for your feedback, RyanJ, and my apologies for the belated response. I somehow failed to notice the topic.

Indeed, a small number of messages are not logged by the package, including the one you mention (“Writing file…”). Another class of such messages are actual Python commands typed at the console prompt. For example, if you open the console and type

print "Hello"

the window will display

>>> print "Hello" Hello
but SublimeLog will only log

Hello

I have so far not discovered any other classes of “missed” messages and, to my knowledge, everything else gets captured as expected.

I have been unable to figure out the cause of this glitch. It is possible that Sublime Text does not use the standard output pipe — which is “wiretapped” by the logger plugin — for these recalcitrant messages.

I am sorry for the inconvenience and will be sure to update the plugin accordingly if I come across a “clean” workaround.[/quote]

The output “collected” by the console is part python stdout (all plugins), and part sublime itself. By tapping into stdout in a plugin, you’re only achieving half of what sublime is doing, as sublime is capable of writing directly to the console (as with the interactive prompt, “Writing file”; blah blah).
Maybe sublime has an interface for gathering this, but I kind of doubt it. Still useful for keeping track of plugins under development that crash sublime, though! (that is, assuming you’re too lazy to manually open a logfile yourself. This does it for you.)

0 Likes

#5

[quote=“joushou”]
The output “collected” by the console is part python stdout (all plugins), and part sublime itself. By tapping into stdout in a plugin, you’re only achieving half of what sublime is doing, as sublime is capable of writing directly to the console (as with the interactive prompt, “Writing file”; blah blah).
Maybe sublime has an interface for gathering this, but I kind of doubt it. Still useful for keeping track of plugins under development that crash sublime, though! (that is, assuming you’re too lazy to manually open a logfile yourself. This does it for you.)[/quote]

This indeed appears to be the case: the core application is able to print on the console directly, circumnavigating the Python environment, and my package does not capture such output. It might be possible to find a user-accessible hook for it — I haven’t looked hard — but it seems a bit unlikely.

If it is any consolation, in my experience by far most of the console content —— and I would venture to say the most useful stuff —— is directed through the Python environment, therefore captured by SublimeLog. For others though, this limitation might be disconcerting.

[quote=“joushou”]
Still useful for keeping track of plugins under development that crash sublime, though! (that is, assuming you’re too lazy to manually open a logfile yourself. This does it for you.[/quote]

This is not the only use case. Several packages use the console to output messages, for example LaTeXTools and Package Control. The former was actually my motivation for writing SublimeLog in the first place. :smile:

0 Likes

#6

Update: The latest betas of ST3 seem to redirect virtually all console output via the standard pipes, therefore SublimeLog is able to capture it.
Only the Python commands as entered by the user in the prompt are still not captured.

0 Likes