Class: Jatai::Commands::Logs

Inherits:
Base
  • Object
show all
Defined in:
lib/jatai/commands/logs.rb

Constant Summary collapse

DEFAULT_TAIL =
100

Instance Method Summary collapse

Methods inherited from Base

#api, #app_slug, #error, #info, #pastel, #project_config, #require_auth!, #success

Instance Method Details

#execute(options = {}) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/jatai/commands/logs.rb', line 8

def execute(options = {})
  require_auth!
  slug = app_slug
  tail = options.fetch("tail", DEFAULT_TAIL).to_s

  logs = api.get("/api/v1/apps/#{slug}/logs", params: { tail: tail })

  if logs.nil? || logs.empty?
    info("Nenhum log disponível.")
    return
  end

  logs.each do |entry|
    timestamp = entry["timestamp"]
    source = entry["source"]
    level = entry["level"]
    message = entry["message"]

    level_str = case level
    when "error" then pastel.red(level)
    when "warn" then pastel.yellow(level)
    when "info" then pastel.green(level)
    else pastel.dim(level || "log")
    end

    puts "#{pastel.dim(timestamp)} #{pastel.cyan(source)} [#{level_str}] #{message}"
  end
rescue Api::Client::ApiError => e
  error("Erro: #{e.message}")
end