3

I am new to cloud foundry and am trying to find out of there is a way for downloading log files or search them in cloud foundry.

I know that I can open the logs files using vmc files but is there any other way of accessing the logs?

Thanks, Kinjal

Kinjal Doshi
  • 151
  • 1
  • 12

1 Answers1

8

I think the easiest way to do this is using the VMC client library, 'cfoundry'.

The following ruby script connects and downloads the three main logs:

#!/usr/bin/env ruby

require 'rubygems'
require 'cfoundry'

creds = { :username => ARGV[0], :password => ARGV[1] }
app_name = ARGV[2]

files_to_dl = ['logs/staging.log', 'logs/stderr.log', 'logs/stdout.log']

c = CFoundry::Client.new "http://api.cloudfoundry.com"
c.login creds

app = c.app_by_name app_name

files_to_dl.each do |file|
  begin
    content = app.file(file)

    local_path = file.match(/\/([^\/]+)$/)[1]
    File.open(local_path, 'w') { |f| f.write(content) }

  rescue CFoundry::NotFound
    puts "404!"
  end
end

This script assumes you are using the latest version of VMC (older, legacy versions don't use cfoundry) and that you also pass in username, password and application name when calling the script. It will write the contents of the remote files locally.

Steffen Opel
  • 63,899
  • 11
  • 192
  • 211
Dan Higham
  • 3,974
  • 16
  • 15
  • Thanks a lot for the quick help Dan. The script worked like a charm and I wouldn't know where to get started as I am not very familiar with ruby script writing – Kinjal Doshi Dec 06 '12 at 11:37
  • I have actually since created a CF app that uploads logs from any application to cloud storage at regular intervals, check it out .. https://github.com/danhigham/log_squirrel – Dan Higham Dec 13 '12 at 18:58
  • HI,after upgdate vmc to 0.4.7, this script run but the log file is 0 byte – atian25 Dec 29 '12 at 07:52