File tree Expand file tree Collapse file tree 2 files changed +20
-0
lines changed Expand file tree Collapse file tree 2 files changed +20
-0
lines changed Original file line number Diff line number Diff line change 1
1
module Sprockets
2
2
module Rails
3
+ class LoggerSilenceError < StandardError ; end
4
+
3
5
class QuietAssets
4
6
def initialize ( app )
5
7
@app = app
@@ -8,11 +10,23 @@ def initialize(app)
8
10
9
11
def call ( env )
10
12
if env [ 'PATH_INFO' ] =~ @assets_regex
13
+ raise_logger_silence_error unless ::Rails . logger . respond_to? ( :silence )
14
+
11
15
::Rails . logger . silence { @app . call ( env ) }
12
16
else
13
17
@app . call ( env )
14
18
end
15
19
end
20
+
21
+ private
22
+ def raise_logger_silence_error
23
+ error = "You have enabled `config.assets.quiet`, but your `Rails.logger`\n "
24
+ error << "does not use the `LoggerSilence` module.\n \n "
25
+ error << "Please use a compatible logger such as `ActiveSupport::Logger`\n "
26
+ error << "to take advantage of quiet asset logging.\n \n "
27
+
28
+ raise LoggerSilenceError , error
29
+ end
16
30
end
17
31
end
18
32
end
Original file line number Diff line number Diff line change @@ -43,6 +43,12 @@ def test_does_not_silence_without_match
43
43
assert_equal Logger ::DEBUG , middleware . call ( "PATH_INFO" => "/path/to/thing" )
44
44
end
45
45
46
+ def test_logger_does_not_respond_to_silence
47
+ ::Rails . logger . stub :respond_to? , false do
48
+ assert_raises ( Sprockets ::Rails ::LoggerSilenceError ) { middleware . call ( "PATH_INFO" => "/assets/stylesheets/application.css" ) }
49
+ end
50
+ end
51
+
46
52
private
47
53
48
54
def middleware
You can’t perform that action at this time.
0 commit comments