Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
75a53297
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,体验更适合开发者的 AI 搜索 >>
未验证
提交
75a53297
编写于
9月 24, 2019
作者:
G
George Claghorn
提交者:
GitHub
9月 24, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add ActionController::Base.log_at
Allow setting a different log level per request.
上级
29be48f5
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
126 addition
and
16 deletion
+126
-16
actionpack/CHANGELOG.md
actionpack/CHANGELOG.md
+11
-0
actionpack/lib/action_controller.rb
actionpack/lib/action_controller.rb
+1
-0
actionpack/lib/action_controller/api.rb
actionpack/lib/action_controller/api.rb
+1
-0
actionpack/lib/action_controller/base.rb
actionpack/lib/action_controller/base.rb
+1
-0
actionpack/lib/action_controller/metal/logging.rb
actionpack/lib/action_controller/metal/logging.rb
+20
-0
actionpack/test/controller/logging_test.rb
actionpack/test/controller/logging_test.rb
+39
-0
activesupport/lib/active_support/logger_silence.rb
activesupport/lib/active_support/logger_silence.rb
+2
-13
activesupport/lib/active_support/logger_thread_safe_level.rb
activesupport/lib/active_support/logger_thread_safe_level.rb
+16
-3
activesupport/test/logger_test.rb
activesupport/test/logger_test.rb
+35
-0
未找到文件。
actionpack/CHANGELOG.md
浏览文件 @
75a53297
*
`ActionController::Base.log_at`
allows setting a different log level per request.
```ruby
# Use the debug level if a particular cookie is set.
class ApplicationController < ActionController::Base
log_at :debug, if: -> { cookies[:debug] }
end
```
*George Claghorn*
*
Allow system test screen shots to be taken more than once in
*
Allow system test screen shots to be taken more than once in
a test by prefixing the file name with an incrementing counter.
a test by prefixing the file name with an incrementing counter.
...
...
actionpack/lib/action_controller.rb
浏览文件 @
75a53297
...
@@ -39,6 +39,7 @@ module ActionController
...
@@ -39,6 +39,7 @@ module ActionController
autoload
:BasicImplicitRender
autoload
:BasicImplicitRender
autoload
:ImplicitRender
autoload
:ImplicitRender
autoload
:Instrumentation
autoload
:Instrumentation
autoload
:Logging
autoload
:MimeResponds
autoload
:MimeResponds
autoload
:ParamsWrapper
autoload
:ParamsWrapper
autoload
:Redirecting
autoload
:Redirecting
...
...
actionpack/lib/action_controller/api.rb
浏览文件 @
75a53297
...
@@ -123,6 +123,7 @@ def self.without_modules(*modules)
...
@@ -123,6 +123,7 @@ def self.without_modules(*modules)
ForceSSL
,
ForceSSL
,
DataStreaming
,
DataStreaming
,
DefaultHeaders
,
DefaultHeaders
,
Logging
,
# Before callbacks should also be executed as early as possible, so
# Before callbacks should also be executed as early as possible, so
# also include them at the bottom.
# also include them at the bottom.
...
...
actionpack/lib/action_controller/base.rb
浏览文件 @
75a53297
...
@@ -234,6 +234,7 @@ def self.without_modules(*modules)
...
@@ -234,6 +234,7 @@ def self.without_modules(*modules)
HttpAuthentication
::
Digest
::
ControllerMethods
,
HttpAuthentication
::
Digest
::
ControllerMethods
,
HttpAuthentication
::
Token
::
ControllerMethods
,
HttpAuthentication
::
Token
::
ControllerMethods
,
DefaultHeaders
,
DefaultHeaders
,
Logging
,
# Before callbacks should also be executed as early as possible, so
# Before callbacks should also be executed as early as possible, so
# also include them at the bottom.
# also include them at the bottom.
...
...
actionpack/lib/action_controller/metal/logging.rb
0 → 100644
浏览文件 @
75a53297
# frozen_string_literal: true
module
ActionController
module
Logging
extend
ActiveSupport
::
Concern
module
ClassMethods
# Set a different log level per request.
#
# # Use the debug log level if a particular cookie is set.
# class ApplicationController < ActionController::Base
# log_at :debug, if: -> { cookies[:debug] }
# end
#
def
log_at
(
level
,
**
options
)
around_action
->
(
_
,
action
)
{
logger
.
log_at
(
level
,
&
action
)
},
**
options
end
end
end
end
actionpack/test/controller/logging_test.rb
0 → 100644
浏览文件 @
75a53297
# frozen_string_literal: true
require
"abstract_unit"
class
LoggingTest
<
ActionController
::
TestCase
class
TestController
<
ActionController
::
Base
log_at
:debug
,
if:
->
{
params
[
:level
]
==
"debug"
}
log_at
:warn
,
if:
->
{
params
[
:level
]
==
"warn"
}
def
show
render
plain:
logger
.
level
end
end
tests
TestController
setup
do
@logger
=
@controller
.
logger
=
ActiveSupport
::
Logger
.
new
(
nil
,
level:
Logger
::
INFO
)
end
test
"logging at the default level"
do
get
:show
assert_equal
Logger
::
INFO
.
to_s
,
response
.
body
end
test
"logging at a noisier level per request"
do
assert_no_changes
->
{
@logger
.
level
}
do
get
:show
,
params:
{
level:
"debug"
}
assert_equal
Logger
::
DEBUG
.
to_s
,
response
.
body
end
end
test
"logging at a quieter level per request"
do
assert_no_changes
->
{
@logger
.
level
}
do
get
:show
,
params:
{
level:
"warn"
}
assert_equal
Logger
::
WARN
.
to_s
,
response
.
body
end
end
end
activesupport/lib/active_support/logger_silence.rb
浏览文件 @
75a53297
...
@@ -27,19 +27,8 @@ module LoggerSilence
...
@@ -27,19 +27,8 @@ module LoggerSilence
end
end
# Silences the logger for the duration of the block.
# Silences the logger for the duration of the block.
def
silence
(
temporary_level
=
Logger
::
ERROR
)
def
silence
(
severity
=
Logger
::
ERROR
)
if
silencer
silencer
?
log_at
(
severity
)
{
yield
self
}
:
yield
(
self
)
begin
old_local_level
=
local_level
self
.
local_level
=
temporary_level
yield
self
ensure
self
.
local_level
=
old_local_level
end
else
yield
self
end
end
end
end
end
end
end
activesupport/lib/active_support/logger_thread_safe_level.rb
浏览文件 @
75a53297
...
@@ -37,10 +37,15 @@ def local_level
...
@@ -37,10 +37,15 @@ def local_level
end
end
def
local_level
=
(
level
)
def
local_level
=
(
level
)
if
level
case
level
when
Integer
self
.
class
.
local_levels
[
local_log_id
]
=
level
self
.
class
.
local_levels
[
local_log_id
]
=
level
else
when
Symbol
self
.
class
.
local_levels
[
local_log_id
]
=
Logger
::
Severity
.
const_get
(
level
.
to_s
.
upcase
)
when
nil
self
.
class
.
local_levels
.
delete
(
local_log_id
)
self
.
class
.
local_levels
.
delete
(
local_log_id
)
else
raise
ArgumentError
,
"Invalid log level:
#{
level
.
inspect
}
"
end
end
end
end
...
@@ -48,9 +53,17 @@ def level
...
@@ -48,9 +53,17 @@ def level
local_level
||
super
local_level
||
super
end
end
# Change the thread-local level for the duration of the given block.
def
log_at
(
level
)
old_local_level
,
self
.
local_level
=
local_level
,
level
yield
ensure
self
.
local_level
=
old_local_level
end
# Redefined to check severity against #level, and thus the thread-local level, rather than +@level+.
# Redefined to check severity against #level, and thus the thread-local level, rather than +@level+.
# FIXME: Remove when the minimum Ruby version supports overriding Logger#level.
# FIXME: Remove when the minimum Ruby version supports overriding Logger#level.
def
add
(
severity
,
message
=
nil
,
progname
=
nil
,
&
block
)
#
:nodoc:
def
add
(
severity
,
message
=
nil
,
progname
=
nil
,
&
block
)
#:nodoc:
severity
||=
UNKNOWN
severity
||=
UNKNOWN
progname
||=
@progname
progname
||=
@progname
...
...
activesupport/test/logger_test.rb
浏览文件 @
75a53297
...
@@ -315,6 +315,41 @@ def test_logger_level_local_fiber_safety
...
@@ -315,6 +315,41 @@ def test_logger_level_local_fiber_safety
assert_level
(
Logger
::
INFO
)
assert_level
(
Logger
::
INFO
)
end
end
def
test_temporarily_logging_at_a_noisier_level
@logger
.
level
=
Logger
::
INFO
@logger
.
debug
"NOT THERE"
@logger
.
log_at
Logger
::
DEBUG
do
@logger
.
debug
"THIS IS HERE"
end
@logger
.
debug
"NOT THERE"
assert_not_includes
@output
.
string
,
"NOT THERE"
assert_includes
@output
.
string
,
"THIS IS HERE"
end
def
test_temporarily_logging_at_a_quieter_level
@logger
.
log_at
Logger
::
ERROR
do
@logger
.
debug
"NOT THERE"
@logger
.
error
"THIS IS HERE"
end
assert_not_includes
@output
.
string
,
"NOT THERE"
assert_includes
@output
.
string
,
"THIS IS HERE"
end
def
test_temporarily_logging_at_a_symbolic_level
@logger
.
log_at
:error
do
@logger
.
debug
"NOT THERE"
@logger
.
error
"THIS IS HERE"
end
assert_not_includes
@output
.
string
,
"NOT THERE"
assert_includes
@output
.
string
,
"THIS IS HERE"
end
private
private
def
level_name
(
level
)
def
level_name
(
level
)
::
Logger
::
Severity
.
constants
.
find
do
|
severity
|
::
Logger
::
Severity
.
constants
.
find
do
|
severity
|
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录