Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
6f5fdf81
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,发现更多精彩内容 >>
提交
6f5fdf81
编写于
11月 25, 2011
作者:
J
José Valim
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #3747 from lest/middleware-logger
middlewares should have configurable logger
上级
8ff8fa5e
cd9d28d6
变更
8
显示空白变更内容
内联
并排
Showing
8 changed file
with
37 addition
and
32 deletion
+37
-32
actionpack/lib/action_dispatch/middleware/params_parser.rb
actionpack/lib/action_dispatch/middleware/params_parser.rb
+3
-3
actionpack/lib/action_dispatch/middleware/show_exceptions.rb
actionpack/lib/action_dispatch/middleware/show_exceptions.rb
+10
-6
actionpack/test/abstract_unit.rb
actionpack/test/abstract_unit.rb
+2
-2
actionpack/test/dispatch/request/json_params_parsing_test.rb
actionpack/test/dispatch/request/json_params_parsing_test.rb
+6
-10
actionpack/test/dispatch/request/xml_params_parsing_test.rb
actionpack/test/dispatch/request/xml_params_parsing_test.rb
+6
-10
actionpack/test/dispatch/show_exceptions_test.rb
actionpack/test/dispatch/show_exceptions_test.rb
+7
-0
railties/lib/rails/application.rb
railties/lib/rails/application.rb
+2
-1
railties/test/application/configuration_test.rb
railties/test/application/configuration_test.rb
+1
-0
未找到文件。
actionpack/lib/action_dispatch/middleware/params_parser.rb
浏览文件 @
6f5fdf81
...
...
@@ -52,7 +52,7 @@ def parse_formatted_parameters(env)
false
end
rescue
Exception
=>
e
# YAML, XML or Ruby code block errors
logger
.
debug
"Error occurred while parsing request parameters.
\n
Contents:
\n\n
#{
request
.
raw_post
}
"
logger
(
env
)
.
debug
"Error occurred while parsing request parameters.
\n
Contents:
\n\n
#{
request
.
raw_post
}
"
raise
e
end
...
...
@@ -68,8 +68,8 @@ def content_type_from_legacy_post_data_format_header(env)
nil
end
def
logger
defined?
(
Rails
.
logger
)
?
Rails
.
logger
:
Logger
.
new
(
$stderr
)
def
logger
(
env
)
env
[
'action_dispatch.logger'
]
||
Logger
.
new
(
$stderr
)
end
end
end
actionpack/lib/action_dispatch/middleware/show_exceptions.rb
浏览文件 @
6f5fdf81
...
...
@@ -63,7 +63,7 @@ def call(env)
private
def
render_exception
(
env
,
exception
)
log_error
(
exception
)
log_error
(
e
nv
,
e
xception
)
exception
=
original_exception
(
exception
)
if
env
[
'action_dispatch.show_detailed_exceptions'
]
==
true
...
...
@@ -124,14 +124,14 @@ def public_path
defined?
(
Rails
.
public_path
)
?
Rails
.
public_path
:
'public_path'
end
def
log_error
(
exception
)
return
unless
logger
def
log_error
(
e
nv
,
e
xception
)
return
unless
logger
(
env
)
ActiveSupport
::
Deprecation
.
silence
do
message
=
"
\n
#{
exception
.
class
}
(
#{
exception
.
message
}
):
\n
"
message
<<
exception
.
annoted_source_code
.
to_s
if
exception
.
respond_to?
(
:annoted_source_code
)
message
<<
" "
<<
application_trace
(
exception
).
join
(
"
\n
"
)
logger
.
fatal
(
"
#{
message
}
\n\n
"
)
logger
(
env
)
.
fatal
(
"
#{
message
}
\n\n
"
)
end
end
...
...
@@ -153,8 +153,12 @@ def clean_backtrace(exception, *args)
exception
.
backtrace
end
def
logger
defined?
(
Rails
.
logger
)
?
Rails
.
logger
:
Logger
.
new
(
$stderr
)
def
logger
(
env
)
env
[
'action_dispatch.logger'
]
||
stderr_logger
end
def
stderr_logger
Logger
.
new
(
$stderr
)
end
def
original_exception
(
exception
)
...
...
actionpack/test/abstract_unit.rb
浏览文件 @
6f5fdf81
...
...
@@ -333,9 +333,9 @@ def public_path
"
#{
FIXTURE_LOAD_PATH
}
/public"
end
remove_method
:logger
remove_method
:
stderr_
logger
# Silence logger
def
logger
def
stderr_
logger
nil
end
end
...
...
actionpack/test/dispatch/request/json_params_parsing_test.rb
浏览文件 @
6f5fdf81
...
...
@@ -32,16 +32,12 @@ def teardown
test
"logs error if parsing unsuccessful"
do
with_test_routing
do
begin
$stderr
=
StringIO
.
new
output
=
StringIO
.
new
json
=
"[
\"
person]
\"
: {
\"
name
\"
:
\"
David
\"
}}"
post
"/parse"
,
json
,
{
'CONTENT_TYPE'
=>
'application/json'
,
'action_dispatch.show_exceptions'
=>
true
}
post
"/parse"
,
json
,
{
'CONTENT_TYPE'
=>
'application/json'
,
'action_dispatch.show_exceptions'
=>
true
,
'action_dispatch.logger'
=>
Logger
.
new
(
output
)
}
assert_response
:error
$stderr
.
rewind
&&
err
=
$stderr
.
read
output
.
rewind
&&
err
=
output
.
read
assert
err
=~
/Error occurred while parsing request parameters/
ensure
$stderr
=
STDERR
end
end
end
...
...
actionpack/test/dispatch/request/xml_params_parsing_test.rb
浏览文件 @
6f5fdf81
...
...
@@ -54,16 +54,12 @@ def call(env)
test
"logs error if parsing unsuccessful"
do
with_test_routing
do
begin
$stderr
=
StringIO
.
new
output
=
StringIO
.
new
xml
=
"<person><name>David</name><avatar type='file' name='me.jpg' content_type='image/jpg'>
#{
ActiveSupport
::
Base64
.
encode64
(
'ABC'
)
}
</avatar></pineapple>"
post
"/parse"
,
xml
,
default_headers
.
merge
(
'action_dispatch.show_exceptions'
=>
true
)
post
"/parse"
,
xml
,
default_headers
.
merge
(
'action_dispatch.show_exceptions'
=>
true
,
'action_dispatch.logger'
=>
Logger
.
new
(
output
)
)
assert_response
:error
$stderr
.
rewind
&&
err
=
$stderr
.
read
output
.
rewind
&&
err
=
output
.
read
assert
err
=~
/Error occurred while parsing request parameters/
ensure
$stderr
=
STDERR
end
end
end
...
...
actionpack/test/dispatch/show_exceptions_test.rb
浏览文件 @
6f5fdf81
...
...
@@ -128,4 +128,11 @@ def call(env)
get
"/"
,
{},
{
'action_dispatch.show_exceptions'
=>
true
}
assert_equal
"text/html; charset=utf-8"
,
response
.
headers
[
"Content-Type"
]
end
test
'uses logger from env'
do
@app
=
ProductionApp
output
=
StringIO
.
new
get
"/"
,
{},
{
'action_dispatch.show_exceptions'
=>
true
,
'action_dispatch.logger'
=>
Logger
.
new
(
output
)}
assert_match
(
/puke/
,
output
.
rewind
&&
output
.
read
)
end
end
railties/lib/rails/application.rb
浏览文件 @
6f5fdf81
...
...
@@ -123,7 +123,8 @@ def env_config
@env_config
||=
super
.
merge
({
"action_dispatch.parameter_filter"
=>
config
.
filter_parameters
,
"action_dispatch.secret_token"
=>
config
.
secret_token
,
"action_dispatch.show_exceptions"
=>
config
.
action_dispatch
.
show_exceptions
"action_dispatch.show_exceptions"
=>
config
.
action_dispatch
.
show_exceptions
,
"action_dispatch.logger"
=>
Rails
.
logger
})
end
...
...
railties/test/application/configuration_test.rb
浏览文件 @
6f5fdf81
...
...
@@ -524,6 +524,7 @@ def index
assert_equal
app
.
env_config
[
'action_dispatch.parameter_filter'
],
app
.
config
.
filter_parameters
assert_equal
app
.
env_config
[
'action_dispatch.secret_token'
],
app
.
config
.
secret_token
assert_equal
app
.
env_config
[
'action_dispatch.show_exceptions'
],
app
.
config
.
action_dispatch
.
show_exceptions
assert_equal
app
.
env_config
[
'action_dispatch.logger'
],
Rails
.
logger
end
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录