Permalink
Browse files

add basic logging

  • Loading branch information...
1 parent 113acd9 commit 42a604366e609658971bd6bc56b32b06a964e057 @ddollar ddollar committed Oct 10, 2011
Showing with 122 additions and 67 deletions.
  1. +3 −1 bin/compile
  2. +41 −0 lib/language_pack/base.rb
  3. +35 −30 lib/language_pack/rails3.rb
  4. +43 −36 lib/language_pack/ruby.rb
View
@@ -4,5 +4,7 @@ $:.unshift File.expand_path("../../lib", __FILE__)
require "language_pack"
if pack = LanguagePack.detect(ARGV[0], ARGV[1])
- pack.compile
+ pack.log("compile") do
+ pack.compile
+ end
end
@@ -1,6 +1,7 @@
require "language_pack"
require "pathname"
require "yaml"
+require "digest/sha1"
Encoding.default_external = Encoding::UTF_8
@@ -16,6 +17,7 @@ class LanguagePack::Base
def initialize(build_path, cache_path=nil)
@build_path = build_path
@cache_path = cache_path
+ @id = Digest::SHA1.hexdigest("#{Time.now.to_f}-#{rand(1000000)}")[0..10]
Dir.chdir build_path
end
@@ -63,8 +65,47 @@ def release
}.to_yaml
end
+ # log output
+ # Ex. log "some_message", "here", :someattr="value"
+ def log(*args)
+ args.concat [:id => @id]
+ args.concat [:framework => self.class.to_s.split("::").last.downcase]
+
+ start = Time.now.to_f
+ log_internal args, :start => start
+
+ if block_given?
+ begin
+ ret = yield
+ finish = Time.now.to_f
+ log_internal args, "success", :finish => finish, :elapsed => (finish - start)
+ return ret
+ rescue Exception => ex
+ finish = Time.now.to_f
+ log_internal args, "failed", :finish => finish, :elapsed => (finish - start), :message => ex.message
+ raise ex
+ end
+ end
+ end
+
private ##################################
+ def log_internal(*args)
+ message = build_log_message(args)
+ %x{ logger -p user.notice -t "slugc[$$]" "buildpack-ruby #{message}" }
+ end
+
+ def build_log_message(args)
+ args.map do |arg|
+ case arg
+ when Float then "%0.2f" % arg
+ when Array then build_log_message(arg)
+ when Hash then arg.map { |k,v| "#{k}=#{build_log_message([v])}" }.join(" ")
+ else arg
+ end
+ end.join(" ")
+ end
+
# display error message and stop the build process
# @param [String] error message
def error(message)
@@ -49,38 +49,43 @@ def binaries
# runs the tasks for the Rails 3.1 asset pipeline
def setup_asset_pipeline
- if rake_task_defined?("assets:precompile")
- topic("Preparing app for Rails asset pipeline")
- if File.exists?("public/assets/manifest.yml")
- puts "Detected manifest.yml, assuming assets were compiled locally"
- else
- ENV["DATABASE_URL"] ||= begin
- # need to use a dummy DATABASE_URL here, so rails can load the environment
- scheme =
- if gem_is_bundled?("pg")
- "postgres"
- elsif gem_is_bundled?("mysql")
- "mysql"
- elsif gem_is_bundled?("mysql2")
- "mysql2"
- elsif gem_is_bundled?("sqlite3") || gem_is_bundled?("sqlite3-ruby")
- "sqlite3"
- end
- "#{scheme}://user:pass@127.0.0.1/dbname"
- end
+ log("assets_precompile") do
+ if rake_task_defined?("assets:precompile")
+ topic("Preparing app for Rails asset pipeline")
+ if File.exists?("public/assets/manifest.yml")
+ puts "Detected manifest.yml, assuming assets were compiled locally"
+ else
+ ENV["DATABASE_URL"] ||= begin
+ # need to use a dummy DATABASE_URL here, so rails can load the environment
+ scheme =
+ if gem_is_bundled?("pg")
+ "postgres"
+ elsif gem_is_bundled?("mysql")
+ "mysql"
+ elsif gem_is_bundled?("mysql2")
+ "mysql2"
+ elsif gem_is_bundled?("sqlite3") || gem_is_bundled?("sqlite3-ruby")
+ "sqlite3"
+ end
+ "#{scheme}://user:pass@127.0.0.1/dbname"
+ end
+
+ ENV["RAILS_GROUPS"] ||= "assets"
+ ENV["RAILS_ENV"] ||= "production"
- ENV["RAILS_GROUPS"] ||= "assets"
- ENV["RAILS_ENV"] ||= "production"
+ puts "Running: rake assets:precompile"
+ rake_output = ""
+ rake_output << run("env PATH=$PATH:bin bundle exec rake assets:precompile 2>&1")
+ puts rake_output
+ log "assets_precompile", "compile_success"
- puts "Running: rake assets:precompile"
- rake_output = ""
- rake_output << run("env PATH=$PATH:bin bundle exec rake assets:precompile 2>&1")
- puts rake_output
- unless $?.success?
- puts "Precompiling assets failed, enabling runtime asset compilation"
- install_plugin("rails31_enable_runtime_asset_compilation")
- puts "Please see this article for troubleshooting help:"
- puts "http://devcenter.heroku.com/articles/rails31_heroku_cedar#troubleshooting"
+ unless $?.success?
+ log "assets_precompile", "compile_success"
+ puts "Precompiling assets failed, enabling runtime asset compilation"
+ install_plugin("rails31_enable_runtime_asset_compilation")
+ puts "Please see this article for troubleshooting help:"
+ puts "http://devcenter.heroku.com/articles/rails31_heroku_cedar#troubleshooting"
+ end
end
end
end
@@ -135,53 +135,59 @@ def install_libyaml(dir)
# runs bundler to install the dependencies
def build_bundler
- bundle_command = "bundle install --without development:test --path vendor/bundle"
+ log("bundle") do
+ bundle_command = "bundle install --without development:test --path vendor/bundle"
- unless File.exist?("Gemfile.lock")
- error "Gemfile.lock is required. Please run \"bundle install\" locally\nand commit your Gemfile.lock."
- end
+ unless File.exist?("Gemfile.lock")
+ error "Gemfile.lock is required. Please run \"bundle install\" locally\nand commit your Gemfile.lock."
+ end
- if has_windows_gemfile_lock?
- File.unlink("Gemfile.lock")
- else
- # using --deployment is preferred if we can
- bundle_command += " --deployment"
- cache_load ".bundle"
- end
+ if has_windows_gemfile_lock?
+ log("bundle", "has_windows_gemfile_lock")
+ File.unlink("Gemfile.lock")
+ else
+ # using --deployment is preferred if we can
+ bundle_command += " --deployment"
+ cache_load ".bundle"
+ end
- cache_load "vendor/bundle"
+ cache_load "vendor/bundle"
- version = run("bundle version").strip
- topic("Installing dependencies using #{version}")
+ version = run("bundle version").strip
+ topic("Installing dependencies using #{version}")
- Dir.mktmpdir("libyaml-") do |tmpdir|
- libyaml_dir = "#{tmpdir}/#{LIBYAML_PATH}"
- install_libyaml(libyaml_dir)
+ Dir.mktmpdir("libyaml-") do |tmpdir|
+ libyaml_dir = "#{tmpdir}/#{LIBYAML_PATH}"
+ install_libyaml(libyaml_dir)
- # need to setup compile environment for the psych gem
- yaml_include = File.expand_path("#{libyaml_dir}/include")
- yaml_lib = File.expand_path("#{libyaml_dir}/lib")
- env_vars = "env CPATH=#{yaml_include}:$CPATH CPPATH=#{yaml_include}:$CPPATH LIBRARY_PATH=#{yaml_lib}:$LIBRARY_PATH"
- puts "Running: #{bundle_command}"
- pipe("#{env_vars} #{bundle_command} --no-clean 2>&1")
- end
+ # need to setup compile environment for the psych gem
+ yaml_include = File.expand_path("#{libyaml_dir}/include")
+ yaml_lib = File.expand_path("#{libyaml_dir}/lib")
+ env_vars = "env CPATH=#{yaml_include}:$CPATH CPPATH=#{yaml_include}:$CPPATH LIBRARY_PATH=#{yaml_lib}:$LIBRARY_PATH"
+ puts "Running: #{bundle_command}"
+ pipe("#{env_vars} #{bundle_command} --no-clean 2>&1")
+ end
- if $?.success?
- puts "Cleaning up the bundler cache."
- run "bundle clean"
- cache_store ".bundle"
- cache_store "vendor/bundle"
- else
- error "Failed to install gems via Bundler."
+ if $?.success?
+ log "bundle", "success"
+ puts "Cleaning up the bundler cache."
+ run "bundle clean"
+ cache_store ".bundle"
+ cache_store "vendor/bundle"
+ else
+ log "bundle", "failure"
+ error "Failed to install gems via Bundler."
+ end
end
end
# writes ERB based database.yml for Rails. The database.yml uses the DATABASE_URL from the environment during runtime.
def create_database_yml
- return unless File.directory?("config")
- topic("Writing config/database.yml to read from DATABASE_URL")
- File.open("config/database.yml", "w") do |file|
- file.puts <<-DATABASE_YML
+ log("create_database_yml") do
+ return unless File.directory?("config")
+ topic("Writing config/database.yml to read from DATABASE_URL")
+ File.open("config/database.yml", "w") do |file|
+ file.puts <<-DATABASE_YML
<%
require 'cgi'
@@ -225,7 +231,8 @@ def attribute(name, value)
<% params.each do |key, value| %>
<%= key %>: <%= value.first %>
<% end %>
- DATABASE_YML
+ DATABASE_YML
+ end
end
end

0 comments on commit 42a6043

Please sign in to comment.