Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
c131211c
R
rails
项目概览
张重言
/
rails
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rails
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
c131211c
编写于
9月 26, 2012
作者:
J
Jeremy Kemper
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Tune up Rails::Rack::Logger. Only put space between requests in development logs.
上级
86ebe0bd
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
30 addition
and
21 deletion
+30
-21
railties/lib/rails/rack/logger.rb
railties/lib/rails/rack/logger.rb
+23
-14
railties/test/application/rack/logger_test.rb
railties/test/application/rack/logger_test.rb
+7
-7
未找到文件。
railties/lib/rails/rack/logger.rb
浏览文件 @
c131211c
...
...
@@ -3,36 +3,45 @@
module
Rails
module
Rack
#
Log the request started and flush all loggers after it
.
#
Sets log tags, logs the request, calls the app, and flushes the logs
.
class
Logger
<
ActiveSupport
::
LogSubscriber
def
initialize
(
app
,
tag
s
=
nil
)
@app
,
@tag
s
=
app
,
tags
.
presence
def
initialize
(
app
,
tag
gers
=
nil
)
@app
,
@tag
gers
=
app
,
taggers
||
[]
end
def
call
(
env
)
if
@tags
&&
Rails
.
logger
.
respond_to?
(
:tagged
)
Rails
.
logger
.
tagged
(
compute_tags
(
env
))
{
call_app
(
env
)
}
request
=
ActionDispatch
::
Request
.
new
(
env
)
# Put some space between requests in development logs.
Rails
.
logger
.
info
"
\n\n
"
if
Rails
.
env
.
development?
if
Rails
.
logger
.
respond_to?
(
:tagged
)
Rails
.
logger
.
tagged
(
compute_tags
(
request
))
{
call_app
(
request
,
env
)
}
else
call_app
(
env
)
call_app
(
request
,
env
)
end
end
protected
def
call_app
(
env
)
request
=
ActionDispatch
::
Request
.
new
(
env
)
path
=
request
.
filtered_path
Rails
.
logger
.
info
"
\n\n
"
Rails
.
logger
.
info
"Started
#{
request
.
request_method
}
\"
#{
path
}
\"
for
#{
request
.
ip
}
at
#{
Time
.
now
.
to_default_s
}
"
def
call_app
(
request
,
env
)
Rails
.
logger
.
info
started_request_message
(
request
)
@app
.
call
(
env
)
ensure
ActiveSupport
::
LogSubscriber
.
flush_all!
end
def
compute_tags
(
env
)
request
=
ActionDispatch
::
Request
.
new
(
env
)
# Started GET "/session/new" for 127.0.0.1 at 2012-09-26 14:51:42 -0700
def
started_request_message
(
request
)
'Started %s "%s" for %s at %s'
%
[
request
.
request_method
,
request
.
filtered_path
,
request
.
ip
,
Time
.
now
.
to_default_s
]
end
@tags
.
collect
do
|
tag
|
def
compute_tags
(
request
)
@taggers
.
collect
do
|
tag
|
case
tag
when
Proc
tag
.
call
(
request
)
...
...
railties/test/application/rack/logger_test.rb
浏览文件 @
c131211c
...
...
@@ -23,31 +23,31 @@ def teardown
end
def
logs
@logs
||=
@logger
.
logged
(
:info
)
@logs
||=
@logger
.
logged
(
:info
)
.
join
(
"
\n
"
)
end
test
"logger logs proper HTTP GET verb and path"
do
get
"/blah"
wait
assert_match
(
/^Started GET "\/blah"/
,
logs
[
0
])
assert_match
'Started GET "/blah"'
,
logs
end
test
"logger logs proper HTTP HEAD verb and path"
do
head
"/blah"
wait
assert_match
(
/^Started HEAD "\/blah"/
,
logs
[
0
])
assert_match
'Started HEAD "/blah"'
,
logs
end
test
"logger logs HTTP verb override"
do
post
"/"
,
{
:_method
=>
'put'
}
post
"/"
,
_method:
'put'
wait
assert_match
(
/^Started PUT "\/"/
,
logs
[
0
])
assert_match
'Started PUT "/"'
,
logs
end
test
"logger logs HEAD requests"
do
post
"/"
,
{
:_method
=>
'head'
}
post
"/"
,
_method:
'head'
wait
assert_match
(
/^Started HEAD "\/"/
,
logs
[
0
])
assert_match
'Started HEAD "/"'
,
logs
end
end
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录