Module: Nucleus::Adapters::V1::CloudControl::Logs

Included in:
Nucleus::Adapters::V1::CloudControl
Defined in:
lib/nucleus/adapters/v1/cloud_control/logs.rb,
lib/nucleus/adapters/v1/cloud_control/log_poller.rb

Overview

cloud control application’s log management operations

Defined Under Namespace

Classes: LogPoller

Constant Summary collapse

LOG_TYPES =

Cloud control log types. The key and id shall match the Nucleus definitions of log files, whereas the name shall match the cloud control log id.

{
  all: { id: 'all', name: 'all', type: Enums::ApplicationLogfileType::OTHER },
  request: { id: 'request', name: 'access', type: Enums::ApplicationLogfileType::REQUEST },
  application: { id: 'application', name: 'error', type: Enums::ApplicationLogfileType::APPLICATION },
  api: { id: 'api', name: 'deploy', type: Enums::ApplicationLogfileType::API },
  system: { id: 'system', name: 'worker', type: Enums::ApplicationLogfileType::SYSTEM }
}

Instance Method Summary collapse

Instance Method Details

#log?(application_name, log_id) ⇒ Boolean

Returns:

  • (Boolean)

See Also:



30
31
32
33
34
35
# File 'lib/nucleus/adapters/v1/cloud_control/logs.rb', line 30

def log?(application_name, log_id)
  # fails with 404 if application is not available
  get("/app/#{application_name}")

  LOG_TYPES.key? log_id.to_sym
end

#log_entries(application_name, log_id) ⇒ Object

cloud control shows the last 500 log messages if applicable

See Also:



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/nucleus/adapters/v1/cloud_control/logs.rb', line 50

def log_entries(application_name, log_id)
  unless log?(application_name, log_id)
    fail Errors::AdapterResourceNotFoundError,
         "Invalid log file '#{log_id}', not available for application '#{application_name}'"
  end
  if log_id == 'all'
    fetched_lines = []
    (LOG_TYPES.keys - [:all]).each do |current_log_id|
      cc_log_entries(application_name, current_log_id).each do |line|
        line[:nucleus_origin] = current_log_id
        fetched_lines.push(line)
      end
    end
    fetched_lines.sort_by! { |line| line[:time] }
    fetched_lines.collect { |line| format_log_entry(line[:nucleus_origin], line) }
  else
    cc_log_entries(application_name, log_id).collect { |line| format_log_entry(log_id, line) }
  end
end

#logs(application_name) ⇒ Object

See Also:



18
19
20
21
22
23
24
25
26
27
# File 'lib/nucleus/adapters/v1/cloud_control/logs.rb', line 18

def logs(application_name)
  # fails with 404 if application is not available and serves for timestamps
  app = get("/app/#{application_name}").body

  LOG_TYPES.values.collect do |log|
    log[:created_at] = app[:date_created]
    log[:updated_at] = app[:date_modified]
    log
  end
end

#tail(application_name, log_id, stream) ⇒ Object

cloud control shows the last 500 log messages if applicable

See Also:



39
40
41
42
43
44
45
46
# File 'lib/nucleus/adapters/v1/cloud_control/logs.rb', line 39

def tail(application_name, log_id, stream)
  # cache headers as they are bound to a request and could be lost with the next tick
  headers_to_use = headers
  logs_to_poll = log_id == 'all' ? LOG_TYPES.keys - [:all] : [log_id]
  poller = LogPoller.new(self, headers_to_use)
  poller.start(application_name, logs_to_poll, stream)
  TailStopper.new(poller, :stop)
end