Skip to content

Commit d5a9f29

Browse files
authored
Merge pull request #21 from rails/rm-logs
Add logging to the hook
2 parents a486496 + a7ed2da commit d5a9f29

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

config.ru

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@
22

33
require "fileutils"
44
require "rack"
5+
require "logger"
6+
7+
# Setup logger - log to STDOUT for systemd
8+
logger = Logger.new(STDOUT)
9+
logger.level = ENV["LOG_LEVEL"] ? Logger.const_get(ENV["LOG_LEVEL"].upcase) : Logger::INFO
10+
logger.formatter = proc do |severity, datetime, progname, msg|
11+
"#{severity}: #{msg}\n"
12+
end
13+
14+
# Use Rack::CommonLogger for HTTP request logging
15+
use Rack::CommonLogger, logger
516

617
run_file = ENV["RUN_FILE"] || "#{__dir__}/run-rails-master-hook"
718
scheduled = <<EOS
@@ -20,10 +31,15 @@ EOS
2031

2132
map "/rails-master-hook" do
2233
run ->(env) do
23-
if env["REQUEST_METHOD"] == "POST"
34+
request_method = env["REQUEST_METHOD"]
35+
36+
if request_method == "POST"
37+
logger.info "Triggering Rails master hook by touching #{run_file}"
2438
FileUtils.touch(run_file)
39+
logger.info "Rails master hook scheduled successfully"
2540
[200, {"Content-Type" => "text/plain", "Content-Length" => scheduled.length.to_s}, [scheduled]]
2641
else
42+
logger.warn "Rejected non-POST request (#{request_method}) to /rails-master-hook"
2743
[404, {"Content-Type" => "text/plain", "Content-Length" => "0"}, []]
2844
end
2945
end

0 commit comments

Comments
 (0)