Created
October 14, 2009 13:20
-
-
Save simonjefford/210069 to your computer and use it in GitHub Desktop.
Revisions
-
simonjefford revised this gist
Nov 8, 2009 . 1 changed file with 3 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -12,8 +12,7 @@ def call(env) def _call(env) status, headers, body = @app.call(env) return [status, headers, body] unless (headers["Content-Type"] =~ /html/ && env['firebug.logs']) response = Rack::Response.new([], status, headers) js = generate_js(env['firebug.logs']) body.each do |line| @@ -26,7 +25,7 @@ def _call(env) private def generate_js(logs) js = ["<script type=\"text/javascript\">"] start_group(js) logs.each do |level, log| level = sanitise_level(level) @@ -58,4 +57,4 @@ def end_group(js) js << "console.groupEnd();" end end end -
unknown revised this gist
Oct 15, 2009 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -12,7 +12,7 @@ def call(env) def _call(env) status, headers, body = @app.call(env) return [status, headers, body] unless (headers["Content-Type"] =~ /html/) return [status, headers, body] unless env['firebug.logs'] response = Rack::Response.new([], status, headers) js = generate_js(env['firebug.logs']) @@ -58,4 +58,4 @@ def end_group(js) js << "console.groupEnd();" end end end -
simonjefford revised this gist
Oct 14, 2009 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -12,7 +12,7 @@ def call(env) def _call(env) status, headers, body = @app.call(env) return [status, headers, body] if !(headers["Content-Type"] =~ /html/) return [status, headers, body] unless env['firebug.logs'] response = Rack::Response.new([], status, headers) js = generate_js(env['firebug.logs']) @@ -35,6 +35,7 @@ def generate_js(logs) end end_group(js) js << "</script>" js << "</body>" js.join("\n") end -
simonjefford revised this gist
Oct 14, 2009 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,5 @@ # See also http://github.com/simonjefford/rack_firebug_logger # for this middleware + tests + a rails plugin class FirebugLogger def initialize(app, options = {}) @app = app -
simonjefford revised this gist
Oct 14, 2009 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -10,7 +10,7 @@ def call(env) def _call(env) status, headers, body = @app.call(env) return [status, headers, body] unless (headers["Content-Type"] =~ /html/) return [status, headers, body] unless env['firebug.logs'] response = Rack::Response.new([], status, headers) js = generate_js(env['firebug.logs']) -
simonjefford revised this gist
Oct 14, 2009 . 3 changed files with 0 additions and 35 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1 +0,0 @@ This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,22 +0,0 @@ This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,12 +0,0 @@ -
simonjefford revised this gist
Oct 14, 2009 . 1 changed file with 6 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,10 @@ Currently takes one option when initialised, :group. This allows you to specify the group under which your logs appear - see "Nested grouping" at http://getfirebug.com/logging.html for an example. To log, set env['firebug.logs'] to a list of pairs. The first element in each pair should be the log level: :info, :warn, :debug or :error. The second element should be the message. For example -
simonjefford created this gist
Oct 14, 2009 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1 @@ Allows logging from your Rack-based app in Firebug (or the WebKit inspector) This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,22 @@ Copyright (c) 2009 Simon Jefford Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,8 @@ Currently takes one option when initialised, :group. This allows you to specify the group under which your logs appear - see "Nested grouping" at http://getfirebug.com/logging.html for an example. To log, set env['firebug.logs'] to a list of pairs. The first element in each pair should be the log level: :info, :warn, :debug or :error. The second element should be the message. For example env['firebug.logs'] = [[:info, "beginning"]] env['firebug.logs'] << [:error, "something went wrong"] This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,58 @@ class FirebugLogger def initialize(app, options = {}) @app = app @options = options end def call(env) dup._call(env) end def _call(env) status, headers, body = @app.call(env) return [status, headers, body] if !(headers["Content-Type"] =~ /html/) return [status, headers, body] unless env['firebug.logs'] response = Rack::Response.new([], status, headers) js = generate_js(env['firebug.logs']) body.each do |line| line.gsub!("</body>", js) response.write(line) end response.finish end private def generate_js(logs) js = ["<script>"] start_group(js) logs.each do |level, log| level = sanitise_level(level) log.gsub!('"', '\"') js << "console.#{level.to_s}(\"#{log}\");" end end_group(js) js << "</script>" js.join("\n") end def start_group(js) if @options[:group] js << "console.group(\"#{@options[:group]}\");" end end def sanitise_level(level) if [:info, :debug, :warn, :error].include?(level) level else :debug end end def end_group(js) if @options[:group] js << "console.groupEnd();" end end end