Skip to content

Commit 652d405

Browse files
committed
Add logs support
1 parent a23509a commit 652d405

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
log/

app.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,22 @@
11
require 'sinatra'
2+
require 'logger'
23

34
class WeDeployApp < Sinatra::Base
5+
6+
::Logger.class_eval { alias :write :'<<' }
7+
access_log = ::File.join(::File.dirname(::File.expand_path(__FILE__)),'log','access.log')
8+
access_logger = ::Logger.new(access_log)
9+
error_logger = ::File.new(::File.join(::File.dirname(::File.expand_path(__FILE__)),'log','error.log'),"a+")
10+
error_logger.sync = true
11+
12+
configure do
13+
use ::Rack::CommonLogger, access_logger
14+
end
15+
16+
before {
17+
env["rack.errors"] = error_logger
18+
}
19+
420
get '/' do
521
erb :home
622
end

0 commit comments

Comments
 (0)