├── Default (Linux).sublime-keymap ├── Default (OSX).sublime-keymap ├── Default (Windows).sublime-keymap ├── Main.sublime-menu ├── README.md ├── SublimeLog.py ├── SublimeLog.sublime-commands ├── SublimeLog.sublime-settings └── packages.json /Default (Linux).sublime-keymap: -------------------------------------------------------------------------------- 1 | [ 2 | { "keys": ["ctrl+alt+c"], "command": "log_console_output" } 3 | ] -------------------------------------------------------------------------------- /Default (OSX).sublime-keymap: -------------------------------------------------------------------------------- 1 | [ 2 | { "keys": ["ctrl+super+c"], "command": "log_console_output" } 3 | ] -------------------------------------------------------------------------------- /Default (Windows).sublime-keymap: -------------------------------------------------------------------------------- 1 | [ 2 | { "keys": ["ctrl+alt+c"], "command": "log_console_output" } 3 | ] -------------------------------------------------------------------------------- /Main.sublime-menu: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "caption": "Preferences", 4 | "mnemonic": "n", 5 | "id": "preferences", 6 | "children": 7 | [ 8 | { 9 | "caption": "Package Settings", 10 | "mnemonic": "P", 11 | "id": "package-settings", 12 | "children": 13 | [ 14 | { 15 | "caption": "SublimeLog", 16 | "children": 17 | [ 18 | { "command": "log_console_output", 19 | "caption": "Toggle logger (on/off)" 20 | }, 21 | { "caption": "-"}, 22 | { 23 | "command": "open_file", 24 | "args": {"file": "${packages}/SublimeLog/SublimeLog.sublime-settings"}, 25 | "caption": "Settings – Default" 26 | }, 27 | { 28 | "command": "open_file", 29 | "args": {"file": "${packages}/User/SublimeLog.sublime-settings"}, 30 | "caption": "Settings – User" 31 | }, 32 | { "caption": "-" }, 33 | { 34 | "command": "open_file", 35 | "args": { 36 | "file": "${packages}/SublimeLog/Default (OSX).sublime-keymap", 37 | "platform": "OSX" 38 | }, 39 | "caption": "Key Bindings – Default" 40 | }, 41 | { 42 | "command": "open_file", 43 | "args": { 44 | "file": "${packages}/SublimeLog/Default (Linux).sublime-keymap", 45 | "platform": "Linux" 46 | }, 47 | "caption": "Key Bindings – Default" 48 | }, 49 | { 50 | "command": "open_file", 51 | "args": { 52 | "file": "${packages}/SublimeLog/Default (Windows).sublime-keymap", 53 | "platform": "Windows" 54 | }, 55 | "caption": "Key Bindings – Default" 56 | }, 57 | { 58 | "command": "open_file", 59 | "args": { 60 | "file": "${packages}/User/SublimeLog (OSX).sublime-keymap", 61 | "platform": "OSX" 62 | }, 63 | "caption": "Key Bindings – User" 64 | }, 65 | { 66 | "command": "open_file", 67 | "args": { 68 | "file": "${packages}/User/SublimeLog (Linux).sublime-keymap", 69 | "platform": "Linux" 70 | }, 71 | "caption": "Key Bindings – User" 72 | }, 73 | { 74 | "command": "open_file", 75 | "args": { 76 | "file": "${packages}/User/SublimeLog (Windows).sublime-keymap", 77 | "platform": "Windows" 78 | }, 79 | "caption": "Key Bindings – User" 80 | } 81 | ] 82 | } 83 | ] 84 | } 85 | ] 86 | } 87 | ] 88 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | SublimeLog 2 | ========== 3 | 4 | A bare-bones console logger for Sublime Text ~~~~2 and~~~~ 3. 5 | 6 | 7 | ### Description 8 | 9 | [Sublime Text 3](http://www.sublimetext.com) provides a console (accessible via ``Control-` ``) for interaction with the editor's Python-based innards and plug-in architecture. This plug-in logs the console contents into a plain-text file ornamented with logger activation/deactivation timestamps. 10 | 11 | The log is erased and recreated each time Sublime Text is launched. 12 | 13 | ### Installation 14 | 15 | The most straightforward installation method is by far via [Will Bond's](http://wbond.net/) superb [Package Control](http://wbond.net/sublime_packages/package_control/package_developers). Alternatively, you may clone (or copy the contents of) this repository into your Sublime Text `./Packages` folder: 16 | 17 | git clone https://github.com/yrammos/SublimeLog.git 18 | 19 | ### Commands 20 | 21 | For now SublimeLog supplies a single command that toggles the logger. The default key-binding is `Command-Control-C` on OS X or `Alt-Control-C` on Windows/Linux. You may also invoke it via the command palette (`⌘-Shift-P` on a Mac or `Ctrl-Shift-P` otherwise): `SublimeLog: Toggle logger (on/off)` 22 | 23 | The key-binding is adjustable in the default JSON file appropriate to your platform: 24 | 25 | ./Packages/SublimeLog/Default ({OSX | Linux | Windows}).sublime-keymapping 26 | 27 | or, to prevent overwrites following plugin updates, in a corresponding file within the User subfolder: 28 | 29 | ./Packages/User/SublimeLog ({OSX | Linux | Windows}).sublime-keymapping 30 | 31 | ### Retrieving the log 32 | 33 | By default, the console is logged in the following plain-text file: 34 | 35 | {HOME}/.subl.log 36 | 37 | This default destination is adjustable in: 38 | 39 | ./Packages/SublimeLog/SublimeLog.sublime-settings 40 | 41 | or, preferably, in the User subfolder: 42 | 43 | ./Packages/User/SublimeLog.sublime-settings 44 | 45 | Whatever path-filename you declare for the log is relative to your root folder, so please be sure you have adequate write permissions or the plug-in will complain politely. 46 | 47 | Note that Sublime Text no longer needs to be restarted for changes to these settings to take effect. 48 | 49 | ### Serving suggestion 50 | 51 | I wrote this plug-in as a complement to my LaTeX workflow. Within a dedicated terminal session, or a tmux pane for that matter, I constantly monitor the log file for changes: 52 | 53 | tail -f ~/.subl.log 54 | 55 | This provides me with a dynamic view of the console stream in a separate window, without the space- and time-consuming tedium of toggling the console view. 56 | 57 | If need to maintain a history of log files following successive restarts of the editor, `multitail` is probably the best solution. It runs on all major Unix platforms and on Windows via Cygwin. 58 | 59 | ### Version history 60 | 61 | #### 12/2/2016 62 | - FIXED: Non-ASCII timestamps no longer cause a crash. 63 | - NEW: Support for Sublime Text 2 is dropped. 64 | 65 | #### 4/18/2013 66 | - NEW: Support for Sublime Text 3. 67 | - NEW: Logger may now be toggled via the command palette. 68 | - NEW: Settings modifications no longer necessitate an editor restart to take effect. 69 | 70 | #### 7/17/2012 71 | - NEW: Adds preferences menu (Sublime Text 2 > Preferences > Package Settings > SublimeLog). 72 | - FIXED: Default and user preferences are now honored as expected. 73 | 74 | #### 6/26/2012 75 | - NEW: Plugin now available via [Package Control](http://wbond.net/sublime_packages/package_control/package_developers). 76 | 77 | #### 6/22/2012 78 | - NEW: First release. 79 | 80 | Copyright © 2012-3 by [Yannis Rammos](twitter.com/yannisrammos). This work is made available under the terms of the Creative Commons Attribution-NonCommercial 3.0 Unported (CC BY-NC 3.0) license, . 81 | -------------------------------------------------------------------------------- /SublimeLog.py: -------------------------------------------------------------------------------- 1 | # SublimeLog: A bare-bones console logger for Sublime Text 2 & Sublime Text 3. 2 | # Please see README file for license info. 3 | 4 | import sublime_plugin 5 | import sys 6 | import sublime 7 | import os 8 | import time 9 | 10 | class LogConsoleOutputCommand(sublime_plugin.ApplicationCommand): 11 | def __init__(self): 12 | # First we backup the standard input and output pipes. 13 | self.active = False 14 | self.ready = False 15 | self.out_backup = sys.stdout 16 | self.err_backup = sys.stderr 17 | 18 | def errands(self): 19 | # Then we obtain the log filename from the settings, if available. Otherwise use a default value. 20 | # Path handling should be cross-platform but has only been tested on OS X (for lack of access to other systems). 21 | self.settings = sublime.load_settings("SublimeLog.sublime-settings") 22 | self.logfilename = self.settings.get("logfile") 23 | if self.logfilename == None: 24 | self.logfilename = os.path.abspath(os.path.join(os.path.expanduser("~"), ".subl.log")) 25 | else: 26 | self.logfilename = os.path.expanduser(self.logfilename) 27 | self.logfilename = os.path.abspath(self.logfilename) 28 | # We open and truncate log file, or create a blank one. In case of an exception we exit. 29 | try: 30 | self.logfile = open(self.logfilename, "w", 1, 'utf-8') 31 | self.logfile.truncate(0) 32 | print("SublimeLog: Log file path is " + self.logfilename) 33 | self.ready = True 34 | except: 35 | sublime.status_message("SublimeLog: Error opening log file (" + self.logfilename + ").") 36 | self.ready = False 37 | return 38 | 39 | def run(self): 40 | # On first execution, or in case of unsuccessful file handling, 41 | # run file-related errands and attach "change" event handler to the log location 42 | # (so that changing the log location does not require a restart of the editor). 43 | if not self.ready: 44 | self.errands(); 45 | self.settings.add_on_change("logfile", self.errands) 46 | # Here we toggle the logger, after ensuring that the log file has been properly opened. 47 | # There may be a more efficient way to do this but for all intents and purposes the overhead is tiny. 48 | if self.ready: 49 | if not self.active: 50 | self.active = True 51 | sublime.status_message("SublimeLog: Console logging activated (" + self.logfilename + ").") 52 | sys.stdout = self 53 | sys.stderr = self 54 | print ("=> => => [" + time.strftime("%d %b %Y, %X", time.localtime()) + "] Console logging activated (" + self.logfilename + ").") 55 | else: 56 | self.active = False 57 | sublime.status_message("SublimeLog: Console logging deactivated (" + self.logfilename + ").") 58 | print ("<= <= <= [" + time.strftime("%d %b %Y, %X", time.localtime()) + "] Console logging deactivated (" + self.logfilename + ").") 59 | sys.stdout = self.out_backup 60 | sys.stderr = self.err_backup 61 | 62 | def write(self, message): 63 | # This method overrides sys.stdout.write() and sys.stderr.write(). 64 | # It simply duplicates the contents of the standard output and error pipes into the log file. 65 | self.out_backup.write(message) 66 | self.logfile.write(message) 67 | -------------------------------------------------------------------------------- /SublimeLog.sublime-commands: -------------------------------------------------------------------------------- 1 | [ 2 | { "caption": "SublimeLog: Toggle logger (on/off)", "command": "log_console_output"} 3 | ] -------------------------------------------------------------------------------- /SublimeLog.sublime-settings: -------------------------------------------------------------------------------- 1 | { 2 | // Name your log file as desired, with full path, or leave commented-out for default setting ("[home]/.subl.log"). 3 | // Sublime Editor must be restarted for changes to take effect. 4 | 5 | // "logfile": "" 6 | } -------------------------------------------------------------------------------- /packages.json: -------------------------------------------------------------------------------- 1 | { 2 | "schema_version": "3.0.0", 3 | "packages": [ 4 | "name": "SublimeLogger", 5 | "details": "https://github.com/yrammos/SublimeLog", 6 | "releases": [ 7 | { 8 | "sublime_text": ">=3000", 9 | "tags": "true" 10 | } 11 | ] 12 | ] 13 | } --------------------------------------------------------------------------------