The Logging Plugin

JavaScript

logging.js - The client-side portion of Gate One's Logging plugin.

GateOne.TermLogging.createLogItem(container, logObj, delay)

Creates a logItem element using logObj and places it in container.

delay controls how long it will wait before using a CSS3 effect to move it into view.

GateOne.TermLogging.createPanel()

Creates the logging panel (just the empty shell of it).

GateOne.TermLogging.displayFlatLogAction(message)

Opens a new window displaying the (flat) log contained within message if there are no errors reported.

GateOne.TermLogging.displayMetadata(logFile)

Displays the information about the log file, logFile in the metadata area of the log viewer.

GateOne.TermLogging.displayPlaybackLogAction(message)

Opens a new window playing back the log contained within message if there are no errors reported.

GateOne.TermLogging.getMaxLogItems(elem)

Calculates and returns the number of log items that will fit in the given element (elem). elem may be a DOM node or an element ID (string).

GateOne.TermLogging.incomingLogAction(message)

Adds message['log'] to GateOne.TermLogging.serverLogs and places it into the view.

GateOne.TermLogging.incomingLogsCompleteAction(message)

Sets the header of the log viewer and displays a message to indicate we're done loading.

GateOne.TermLogging.init()

Creates the log viewer panel and registers the following WebSocket actions:

GateOne.Net.addAction('terminal:logging_log', GateOne.TermLogging.incomingLogAction);
GateOne.Net.addAction('terminal:logging_logs_complete', GateOne.TermLogging.incomingLogsCompleteAction);
GateOne.Net.addAction('terminal:logging_log_flat', GateOne.TermLogging.displayFlatLogAction);
GateOne.Net.addAction('terminal:logging_log_playback', GateOne.TermLogging.displayPlaybackLogAction);
GateOne.TermLogging.loadLogs(forceUpdate)

After GateOne.TermLogging.serverLogs has been populated this function will redraw the view depending on sort and pagination values.

If forceUpdate empty out GateOne.TermLogging.serverLogs and tell the server to send us a new list.

GateOne.TermLogging.loadPagination(logItems[, page])

Sets up the pagination for the given array of logItems and returns the pagination node.

If page is given, the pagination will highlight the given page number and adjust prev/next accordingly.

GateOne.TermLogging.openLogFlat(logFile)

Tells the server to open logFile for playback via the 'terminal:logging_get_log_flat' server-side WebSocket action (will end up calling displayFlatLogAction().

GateOne.TermLogging.openLogPlayback(logFile[, where])

Tells the server to open logFile for playback via the 'terminal:logging_get_log_playback' server-side WebSocket action (will end up calling displayPlaybackLogAction().

If where is given and it is set to 'preview' the playback will happen in the log_preview iframe.

GateOne.TermLogging.saveRenderedLog(logFile)

Tells the server to open logFile rendered as a self-contained recording (via the 'logging_get_log_file' WebSocket action) and send it back to the browser for saving (using the 'save_file' WebSocket action).

GateOne.TermLogging.sessionLoggingDisabled()

Just removes the "Log Viewer" button from the Terminal info panel. It gets sent if the server has "session_logging": false.

GateOne.TermLogging.sortFunctions

An associative array of functions that are used to sort logs. When the user clicks on one of the sorting options it assigns one of these functions to GateOne.TermLogging.sortfunc() which is then applied like so:

logs.sort(GateOne.TermLogging.sortfunc);
GateOne.TermLogging.sortFunctions.alphabetical(a, b)

Sorts logs alphabetically using the title (connect_string).

GateOne.TermLogging.sortFunctions.alphabetical(a, b)

Sorts logs according to their size.

GateOne.TermLogging.sortFunctions.date(a, b)

Sorts logs by date (start_date) followed by alphabetical order of the title (connect_string).

GateOne.TermLogging.toggleSortOrder()

Reverses the order of the logs array.

Python

logging_plugin.py - A plugin for Gate One that provides logging-related functionality.

Hooks

This Python plugin file implements the following hooks:

hooks = {
    'WebSocket': {
        'logging_get_logs': enumerate_logs,
        'logging_get_log_flat': retrieve_log_flat,
        'logging_get_log_playback': retrieve_log_playback,
        'logging_get_log_file': save_log_playback,
    },
    'Events': {
        'terminal:authenticate': send_logging_css_template
    }
}

Docstrings

logging_plugin.get_256_colors(self)[source]

Returns the rendered 256-color CSS.

logging_plugin.enumerate_logs(self, limit=None)[source]

Calls _enumerate_logs() via a multiprocessing.Process so it doesn't cause the IOLoop to block.

Log objects will be returned to the client one at a time by sending 'logging_log' actions to the client over the WebSocket (self).

logging_plugin._enumerate_logs(queue, user, users_dir, limit=None)[source]

Enumerates all of the user's logs and sends the client a "logging_logs" message with the result.

If limit is given, only return the specified logs. Works just like MySQL: limit="5,10" will retrieve logs 5-10.

logging_plugin.retrieve_log_flat(self, settings)[source]

Calls _retrieve_log_flat() via a multiprocessing.Process so it doesn't cause the IOLoop to block.

Parameters:settings (dict) -- A dict containing the log_filename, colors, and theme to use when generating the HTML output.

Here's the details on settings:

Parameters:
  • settings['log_filename'] -- The name of the log to display.
  • settings['colors'] -- The CSS color scheme to use when generating output.
  • settings['theme'] -- The CSS theme to use when generating output.
  • settings['where'] -- Whether or not the result should go into a new window or an iframe.
logging_plugin._retrieve_log_flat(queue, settings)[source]

Writes the given log_filename to queue in a flat format equivalent to:

./logviewer.py --flat log_filename

settings - A dict containing the log_filename, colors_css, and theme_css to use when generating the HTML output.

logging_plugin.retrieve_log_playback(self, settings)[source]

Calls _retrieve_log_playback() via a multiprocessing.Process so it doesn't cause the IOLoop to block.

logging_plugin._retrieve_log_playback(queue, settings)[source]

Writes a JSON-encoded message to the client containing the log in a self-contained HTML format similar to:

./logviewer.py log_filename

settings - A dict containing the log_filename, colors, and theme to use when generating the HTML output.

Parameters:
  • settings['log_filename'] -- The name of the log to display.
  • settings['colors_css'] -- The CSS color scheme to use when generating output.
  • settings['theme_css'] -- The entire CSS theme <style> to use when generating output.
  • settings['where'] -- Whether or not the result should go into a new window or an iframe.

The output will look like this:

{
    'result': "Success",
    'log': <HTML rendered output>,
    'metadata': {<metadata of the log>}
}

It is expected that the client will create a new window with the result of this method.

logging_plugin.save_log_playback(self, settings)[source]

Calls _save_log_playback() via a multiprocessing.Process so it doesn't cause the IOLoop to block.

logging_plugin._save_log_playback(queue, settings)[source]

Writes a JSON-encoded message to the client containing the log in a self-contained HTML format similar to:

./logviewer.py log_filename

The difference between this function and _retrieve_log_playback() is that this one instructs the client to save the file to disk instead of opening it in a new window.

Parameters:
  • settings['log_filename'] -- The name of the log to display.
  • settings['colors'] -- The CSS color scheme to use when generating output.
  • settings['theme'] -- The CSS theme to use when generating output.
  • settings['where'] -- Whether or not the result should go into a new window or an iframe.

The output will look like this:

{
    'result': "Success",
    'data': <HTML rendered output>,
    'mimetype': 'text/html'
    'filename': <filename of the log recording>
}

It is expected that the client will create a new window with the result of this method.

logging_plugin.session_logging_check(self)[source]

Attached to the terminal:session_logging_check WebSocket action; replies with terminal:logging_sessions_disabled if terminal session logging is disabled.

Note

The terminal:logging_sessions_disabled message just has the client remove the "Log Viewer" button so they don't get confused with an always-empty log viewer.

logging_plugin.send_logging_css_template(self)[source]

Sends our logging.css template to the client using the 'load_style' WebSocket action. The rendered template will be saved in Gate One's 'cache_dir'.