Sha256: ad9fc4305bae98df25e2371c4e9a6b1237972345bc16cbefcb2ef2780850dd2c

Contents?: true

Size: 999 Bytes

Versions: 5

Compression:

Stored size: 999 Bytes

Contents

module Kamal::Commands::App::Logging
  def logs(container_id: nil, timestamps: true, since: nil, lines: nil, grep: nil, grep_options: nil)
    pipe \
      container_id_command(container_id),
      "xargs docker logs#{" --timestamps" if timestamps}#{" --since #{since}" if since}#{" --tail #{lines}" if lines} 2>&1",
      ("grep '#{grep}'#{" #{grep_options}" if grep_options}" if grep)
  end

  def follow_logs(host:, container_id: nil, timestamps: true, lines: nil, grep: nil, grep_options: nil)
    run_over_ssh \
      pipe(
        container_id_command(container_id),
        "xargs docker logs#{" --timestamps" if timestamps}#{" --tail #{lines}" if lines} --follow 2>&1",
        (%(grep "#{grep}"#{" #{grep_options}" if grep_options}) if grep)
      ),
      host: host
  end

  private

  def container_id_command(container_id)
    case container_id
    when Array then container_id
    when String, Symbol then "echo #{container_id}"
    else current_running_container_id
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
kamal-2.5.3 lib/kamal/commands/app/logging.rb
kamal-2.5.2 lib/kamal/commands/app/logging.rb
kamal-2.5.1 lib/kamal/commands/app/logging.rb
kamal-2.5.0 lib/kamal/commands/app/logging.rb
kamal-2.4.0 lib/kamal/commands/app/logging.rb