Class: WebConsole::Logger

Inherits:
Object
  • Object
show all
Defined in:
lib/webconsole/logger.rb

Constant Summary collapse

MESSAGE_PREFIX =
'MESSAGE '
ERROR_PREFIX =
'ERROR '
LOG_PLUGIN_NAME =
'Log'
SHOW_LOG_SCRIPT =

Toggle

File.join(APPLESCRIPT_DIRECTORY, "show_log.scpt")
HIDE_LOG_SCRIPT =
File.join(APPLESCRIPT_DIRECTORY, "hide_log.scpt")
TOGGLE_LOG_SCRIPT =
File.join(APPLESCRIPT_DIRECTORY, "toggle_log.scpt")

Instance Method Summary collapse

Instance Method Details

#error(message) ⇒ Object



38
39
40
41
42
# File 'lib/webconsole/logger.rb', line 38

def error(message)
  message = message.dup
  message.gsub!(%r{^}, ERROR_PREFIX)
  log_message(message)
end

#hideObject



19
20
21
# File 'lib/webconsole/logger.rb', line 19

def hide
  WebConsole::run_applescript(HIDE_LOG_SCRIPT, [window_id])
end

#info(message) ⇒ Object

Messages



30
31
32
33
34
35
36
# File 'lib/webconsole/logger.rb', line 30

def info(message)
  message = message.dup
  message.gsub!(%r{^}, MESSAGE_PREFIX) # Prefix all lines
  # Strip trailing white space
  # Add a line break
  log_message(message)
end

#showObject



14
15
16
# File 'lib/webconsole/logger.rb', line 14

def show
  WebConsole::run_applescript(SHOW_LOG_SCRIPT, [window_id])
end

#toggleObject



24
25
26
# File 'lib/webconsole/logger.rb', line 24

def toggle
  WebConsole::run_applescript(TOGGLE_LOG_SCRIPT, [window_id])
end

#view_idObject



50
51
52
53
54
55
56
57
# File 'lib/webconsole/logger.rb', line 50

def view_id
  @view_id ||= WebConsole::split_id_in_window(window_id, LOG_PLUGIN_NAME)
  return @view_id unless @view_id.nil?

  @view_id = WebConsole::split_id_in_window_last(window_id)
  WebConsole::run_plugin_in_split(LOG_PLUGIN_NAME, window_id, @view_id)
  @view_id  
end

#window_idObject

Properties



46
47
48
# File 'lib/webconsole/logger.rb', line 46

def window_id
  @window_id ||= ENV.has_key?(WINDOW_ID_KEY) ? ENV[WINDOW_ID_KEY] : WebConsole::create_window
end