Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
ace28a54
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 搜索 >>
未验证
提交
ace28a54
编写于
7月 24, 2019
作者:
R
Rafael França
提交者:
Rafael Mendonça França
7月 24, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Merge pull request #36753 from cmrd-senya/36752-make-rails-logger-fiber-safe
Make ActiveSupport::Logger Fiber-safe
上级
270fb0b5
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
78 addition
and
1 deletion
+78
-1
activesupport/CHANGELOG.md
activesupport/CHANGELOG.md
+32
-0
activesupport/lib/active_support/logger_thread_safe_level.rb
activesupport/lib/active_support/logger_thread_safe_level.rb
+2
-1
activesupport/test/logger_test.rb
activesupport/test/logger_test.rb
+44
-0
未找到文件。
activesupport/CHANGELOG.md
浏览文件 @
ace28a54
*
Make ActiveSupport::Logger Fiber-safe. Fixes #36752.
Use `Fiber.current.__id__` in `ActiveSupport::Logger#local_level=` in order
to make log level local to Ruby Fibers in addition to Threads.
Example:
logger = ActiveSupport::Logger.new(STDOUT)
logger.level = 1
p "Main is debug? #{logger.debug?}"
Fiber.new {
logger.local_level = 0
p "Thread is debug? #{logger.debug?}"
}.resume
p "Main is debug? #{logger.debug?}"
Before:
Main is debug? false
Thread is debug? true
Main is debug? true
After:
Main is debug? false
Thread is debug? true
Main is debug? false
*Alexander Varnin*
*
Do not delegate missing
`marshal_dump`
and
`_dump`
methods via the
*
Do not delegate missing
`marshal_dump`
and
`_dump`
methods via the
`delegate_missing_to`
extension. This avoids unintentionally adding instance
`delegate_missing_to`
extension. This avoids unintentionally adding instance
variables when calling
`Marshal.dump(object)`
, should the delegation target of
variables when calling
`Marshal.dump(object)`
, should the delegation target of
...
...
activesupport/lib/active_support/logger_thread_safe_level.rb
浏览文件 @
ace28a54
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
require
"active_support/concern"
require
"active_support/concern"
require
"active_support/core_ext/module/attribute_accessors"
require
"active_support/core_ext/module/attribute_accessors"
require
"concurrent"
require
"concurrent"
require
"fiber"
module
ActiveSupport
module
ActiveSupport
module
LoggerThreadSafeLevel
# :nodoc:
module
LoggerThreadSafeLevel
# :nodoc:
...
@@ -28,7 +29,7 @@ def after_initialize
...
@@ -28,7 +29,7 @@ def after_initialize
end
end
def
local_log_id
def
local_log_id
Thread
.
current
.
__id__
Fiber
.
current
.
__id__
end
end
def
local_level
def
local_level
...
...
activesupport/test/logger_test.rb
浏览文件 @
ace28a54
...
@@ -258,6 +258,50 @@ def test_logger_level_local_thread_safety
...
@@ -258,6 +258,50 @@ def test_logger_level_local_thread_safety
assert_level
(
Logger
::
INFO
)
assert_level
(
Logger
::
INFO
)
end
end
def
test_logger_level_main_fiber_safety
@logger
.
level
=
Logger
::
INFO
assert_level
(
Logger
::
INFO
)
fiber
=
Fiber
.
new
do
assert_level
(
Logger
::
INFO
)
end
@logger
.
silence
(
Logger
::
ERROR
)
do
assert_level
(
Logger
::
ERROR
)
fiber
.
resume
end
end
def
test_logger_level_local_fiber_safety
@logger
.
level
=
Logger
::
INFO
assert_level
(
Logger
::
INFO
)
another_fiber
=
Fiber
.
new
do
@logger
.
silence
(
Logger
::
ERROR
)
do
assert_level
(
Logger
::
ERROR
)
@logger
.
silence
(
Logger
::
DEBUG
)
do
assert_level
(
Logger
::
DEBUG
)
end
end
assert_level
(
Logger
::
INFO
)
end
Fiber
.
new
do
@logger
.
silence
(
Logger
::
ERROR
)
do
assert_level
(
Logger
::
ERROR
)
@logger
.
silence
(
Logger
::
DEBUG
)
do
another_fiber
.
resume
assert_level
(
Logger
::
DEBUG
)
end
end
assert_level
(
Logger
::
INFO
)
end
.
resume
assert_level
(
Logger
::
INFO
)
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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录