[DRE-commits] [gemwatch] 01/03: Implement error logging

Antonio Terceiro terceiro at moszumanska.debian.org
Thu Aug 6 14:36:26 UTC 2015


This is an automated email from the git hooks/post-receive script.

terceiro pushed a commit to branch master
in repository gemwatch.

commit 98cc3f49c5a03340b125683906a30a8c835aaf27
Author: Antonio Terceiro <terceiro at debian.org>
Date:   Thu Aug 6 11:34:03 2015 -0300

    Implement error logging
    
    we don't have access to web server logs on alioth
---
 .gitignore  |  1 +
 gemwatch.rb | 16 ++++++++++++++++
 2 files changed, 17 insertions(+)

diff --git a/.gitignore b/.gitignore
index 5d029b4..e6dd0a9 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
 *.swp
 tmp/download/
+tmp/log/
 .bundle
diff --git a/gemwatch.rb b/gemwatch.rb
index 90da8fe..1e4cd4a 100644
--- a/gemwatch.rb
+++ b/gemwatch.rb
@@ -4,6 +4,7 @@ require 'sinatra'
 require 'haml'
 require 'restclient'
 require 'json'
+require 'time'
 
 begin
   # alioth
@@ -19,6 +20,7 @@ require 'open-uri'
 
 DOWNLOAD_BASE = File.join(File.dirname(__FILE__), 'tmp', 'download')
 ASSETS_BASE = File.join(File.dirname(__FILE__), 'public')
+LOG_BASE = File.join(File.dirname(__FILE__), 'tmp', 'log')
 
 module GemWatch
   class << self
@@ -198,5 +200,19 @@ not_found do
 end
 
 error 500 do
+  now = Time.now
+  log = File.join(LOG_BASE, now.strftime('%Y/%m/%d.log'))
+  FileUtils.mkdir_p(File.dirname(log))
+  error = env['sinatra.error']
+
+  File.open(log, 'a') do |f|
+    f.flock(File::LOCK_EX)
+    f.puts(now.to_s + ": " + error.message)
+    f.puts('-' * 72)
+    f.puts(error.backtrace)
+    f.puts
+    f.flock(File::LOCK_UN)
+  end
+
   haml :error
 end

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-ruby-extras/gemwatch.git



More information about the Pkg-ruby-extras-commits mailing list