File tree Expand file tree Collapse file tree 3 files changed +18
-8
lines changed Expand file tree Collapse file tree 3 files changed +18
-8
lines changed Original file line number Diff line number Diff line change 1
- # (unreleased)
1
+ # 3.1.x (unreleased)
2
2
3
- ...
3
+ * Added debug log sanitization ( @ airhorns , @ orenmazor , @ yaauie )
4
4
5
5
# 3.0.7
6
6
Original file line number Diff line number Diff line change @@ -274,13 +274,23 @@ def logging(commands)
274
274
275
275
begin
276
276
commands . each do |name , *args |
277
- @logger . debug ( "Redis >> #{ name . to_s . upcase } #{ args . map ( &:to_s ) . join ( " " ) } " )
277
+ logged_args = args . map do |a |
278
+ case
279
+ when a . respond_to? ( :inspect ) then a . inspect
280
+ when a . respond_to? ( :to_s ) then a . to_s
281
+ else
282
+ # handle poorly-behaved descendants of BasicObject
283
+ klass = a . instance_exec { ( class << self ; self end ) . superclass }
284
+ "\# <#{ klass } :#{ a . __id__ } >"
285
+ end
286
+ end
287
+ @logger . debug ( "[Redis] command=#{ name . to_s . upcase } args=#{ logged_args . join ( ' ' ) } " )
278
288
end
279
289
280
290
t1 = Time . now
281
291
yield
282
292
ensure
283
- @logger . debug ( "Redis >> %0.2fms " % ( ( Time . now - t1 ) * 1000 ) ) if t1
293
+ @logger . debug ( "[ Redis] call_time= %0.2f ms " % ( ( Time . now - t1 ) * 1000 ) ) if t1
284
294
end
285
295
end
286
296
Original file line number Diff line number Diff line change @@ -9,8 +9,8 @@ class TestInternals < Test::Unit::TestCase
9
9
def test_logger
10
10
r . ping
11
11
12
- assert log . string =~ / Redis >> PING/
13
- assert log . string =~ /Redis >> \d +\. \d +ms/
12
+ assert log . string [ "[ Redis] command= PING" ]
13
+ assert log . string =~ /\[ Redis\] call_time= \d +\. \d + ms/
14
14
end
15
15
16
16
def test_logger_with_pipelining
@@ -19,8 +19,8 @@ def test_logger_with_pipelining
19
19
r . get "foo"
20
20
end
21
21
22
- assert log . string [ "SET foo bar" ]
23
- assert log . string [ "GET foo" ]
22
+ assert log . string [ " command= SET args= \" foo\" \" bar\" " ]
23
+ assert log . string [ " command= GET args= \" foo\" " ]
24
24
end
25
25
26
26
def test_recovers_from_failed_commands
You can’t perform that action at this time.
0 commit comments