browserlog 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. checksums.yaml +15 -0
  2. data/MIT-LICENSE +20 -0
  3. data/Rakefile +30 -0
  4. data/app/assets/javascripts/browserlog/application.js +14 -0
  5. data/app/assets/javascripts/browserlog/logs.js.coffee +94 -0
  6. data/app/assets/stylesheets/browserlog/application.css +15 -0
  7. data/app/assets/stylesheets/browserlog/dark-theme.css.scss +100 -0
  8. data/app/assets/stylesheets/browserlog/light-theme.css.scss +99 -0
  9. data/app/assets/stylesheets/browserlog/log.css.scss +38 -0
  10. data/app/controllers/browserlog/application_controller.rb +4 -0
  11. data/app/controllers/browserlog/logs_controller.rb +44 -0
  12. data/app/helpers/browserlog/application_helper.rb +4 -0
  13. data/app/helpers/browserlog/logs_helper.rb +4 -0
  14. data/app/views/browserlog/logs/_form.html.erb +17 -0
  15. data/app/views/browserlog/logs/edit.html.erb +6 -0
  16. data/app/views/browserlog/logs/index.html.erb +1 -0
  17. data/app/views/browserlog/logs/new.html.erb +5 -0
  18. data/app/views/browserlog/logs/show.html.erb +4 -0
  19. data/app/views/browserlog/logs/unauthorized.html.erb +0 -0
  20. data/app/views/layouts/browserlog/application.html.erb +21 -0
  21. data/config/routes.rb +4 -0
  22. data/lib/browserlog.rb +12 -0
  23. data/lib/browserlog/config.rb +13 -0
  24. data/lib/browserlog/engine.rb +37 -0
  25. data/lib/browserlog/log_colorize.rb +97 -0
  26. data/lib/browserlog/log_reader.rb +35 -0
  27. data/lib/browserlog/selective_logger.rb +63 -0
  28. data/lib/browserlog/version.rb +3 -0
  29. data/lib/tasks/browserlog_tasks.rake +4 -0
  30. data/spec/dummy/README.rdoc +28 -0
  31. data/spec/dummy/Rakefile +7 -0
  32. data/spec/dummy/app/assets/javascripts/application.js +13 -0
  33. data/spec/dummy/app/assets/stylesheets/application.css +15 -0
  34. data/spec/dummy/app/controllers/application_controller.rb +5 -0
  35. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  36. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  37. data/spec/dummy/bin/bundle +3 -0
  38. data/spec/dummy/bin/rails +4 -0
  39. data/spec/dummy/bin/rake +4 -0
  40. data/spec/dummy/config.ru +4 -0
  41. data/spec/dummy/config/application.rb +27 -0
  42. data/spec/dummy/config/boot.rb +5 -0
  43. data/spec/dummy/config/database.yml +19 -0
  44. data/spec/dummy/config/environment.rb +5 -0
  45. data/spec/dummy/config/environments/development.rb +38 -0
  46. data/spec/dummy/config/environments/production.rb +89 -0
  47. data/spec/dummy/config/environments/test.rb +40 -0
  48. data/spec/dummy/config/initializers/backtrace_silencers.rb +9 -0
  49. data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
  50. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  51. data/spec/dummy/config/initializers/inflections.rb +16 -0
  52. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  53. data/spec/dummy/config/initializers/session_store.rb +3 -0
  54. data/spec/dummy/config/initializers/wrap_parameters.rb +15 -0
  55. data/spec/dummy/config/locales/en.yml +23 -0
  56. data/spec/dummy/config/routes.rb +3 -0
  57. data/spec/dummy/config/secrets.yml +22 -0
  58. data/spec/dummy/db/development.sqlite3 +0 -0
  59. data/spec/dummy/db/schema.rb +16 -0
  60. data/spec/dummy/db/test.sqlite3 +0 -0
  61. data/spec/dummy/log/test.log +40 -0
  62. data/spec/dummy/public/404.html +67 -0
  63. data/spec/dummy/public/422.html +67 -0
  64. data/spec/dummy/public/500.html +66 -0
  65. data/spec/dummy/public/favicon.ico +0 -0
  66. data/spec/spec_helper.rb +19 -0
  67. metadata +188 -0
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ OTBhNjE4YWQyMjI2MzMyOGVkMmRjYjNhMmRhMjFkYjRmZmNmOGYwNw==
5
+ data.tar.gz: !binary |-
6
+ ZjhhYTJhMzlhNzI2YjhiMmNhZGU0YzllMDczYWRiMDYyYzI5ZDE4Nw==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ Yjc0YzU1ZDFkZDU5YjY4MjUzYjQ3MTMwZDE3MTE3MmIxZWRkMGIyNmYyOWIw
10
+ N2NlZTlmYTAxZmYwOWFlYTJmNjJlMTU2NDYyYjdjMjIxYThjYWVjZTc4YzZh
11
+ YTAyYmRiOGQ0OWRmMDFkN2FkMTU4YTBkZjlhNWU2YzQzMzM2OTA=
12
+ data.tar.gz: !binary |-
13
+ N2Q2MmI1NDU5Y2IzYTNlNjU4N2NiZmFjMDVmMTNjN2Q4ZDFlY2UyNjllNTJh
14
+ ZjE0MzIwZTQ5MzA1ZjdiMDU5OWQ2YWIxOTIyY2M5MTRlNjkwZDU1YzVlYjZk
15
+ OWExZGIwNjBiYjgzMjI5OWNmM2IzZGU1MWFkYzYyZWZhN2ZjNTg=
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2014 Andre Dieb Martins <andre.dieb@gmail.com>
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,30 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ APP_RAKEFILE = File.expand_path('../spec/dummy/Rakefile', __FILE__)
8
+ load 'rails/tasks/engine.rake'
9
+
10
+ Bundler::GemHelper.install_tasks
11
+
12
+ require 'rspec/core'
13
+ require 'rspec/core/rake_task'
14
+
15
+ begin
16
+ require 'rubocop/rake_task'
17
+ Rubocop::RakeTask.new
18
+ rescue LoadError
19
+ desc 'Run RuboCop'
20
+ task :rubocop do
21
+ $stderr.puts 'Rubocop is disabled'
22
+ end
23
+ end
24
+
25
+ desc 'Run all specs in spec directory (excluding plugin specs)'
26
+ RSpec::Core::RakeTask.new(spec: 'app:db:test:prepare') do |spec|
27
+ spec.pattern = 'spec/**/*_spec.rb'
28
+ end
29
+
30
+ task default: [:spec, :rubocop]
@@ -0,0 +1,14 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file.
9
+ //
10
+ // Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require jquery
14
+ //= require_tree .
@@ -0,0 +1,94 @@
1
+ class ThemeSwitcherView
2
+ constructor: ->
3
+ @body = $('body')
4
+ $(document).on('change', '.theme-switch', @switchTheme)
5
+ @loadTheme()
6
+
7
+ switchTheme: (e) =>
8
+ localStorage.setItem('browserlog-theme', e.target.value)
9
+ @loadTheme()
10
+
11
+ loadTheme: ->
12
+ $('.theme-switch').val(@getCurrentTheme())
13
+ @body.attr('data-theme', @getCurrentTheme())
14
+
15
+ getCurrentTheme: ->
16
+ localStorage.getItem('browserlog-theme') || 'dark'
17
+
18
+ class LogView
19
+
20
+ constructor: ->
21
+ @lines = $('#lines')
22
+ @body = $('body')
23
+ @resumeButton = $('.resume-scroll-btn')
24
+ @autoScroll = true
25
+ @attachEvents()
26
+
27
+ attachEvents: ->
28
+ window.onscroll = @disableAutoScroll
29
+ @body.on('click', '.resume-scroll-btn', @enableAutoScroll)
30
+
31
+ update: (lines) ->
32
+ @appendLines(lines)
33
+ @updateScroll() if @autoScroll
34
+
35
+ appendLines: (lines) ->
36
+ linesString = ''
37
+ linesString += "<li>#{line}</li>" for line in lines
38
+ @lines.append(linesString)
39
+
40
+ disableAutoScroll: (e) =>
41
+ if (e.timeStamp > @timestamp) and @hasScroll() and @body.scrollTop() > 0
42
+ @autoScroll = false
43
+ @resumeButton.removeClass('hidden')
44
+
45
+ enableAutoScroll: =>
46
+ @autoScroll = true
47
+ @resumeButton.addClass('hidden')
48
+ @updateScroll()
49
+
50
+ updateScroll: ->
51
+ @body.scrollTop(@body.prop('scrollHeight'))
52
+ @timestamp = (new Date()).getTime()
53
+
54
+ hasScroll: ->
55
+ @body.height() == @body.prop('scrollHeight')
56
+
57
+
58
+ class LogFeed
59
+ POLL_PERIOD: 1500
60
+
61
+ constructor: (listener) ->
62
+ @listener = listener
63
+ @currentLine = -1
64
+
65
+ getLines: =>
66
+ $.get(window.location.href + '/changes.json', {currentLine: @currentLine})
67
+ .done(@getLinesSuccess)
68
+ .fail(@getLinesError)
69
+ .always(@getLinesComplete)
70
+
71
+ getLinesSuccess: (data, status, xhr) =>
72
+ @listener.update(data.lines)
73
+ @currentLine = data.last_line_number
74
+
75
+ getLinesError: (data, status, err) =>
76
+ console.log "Error fetching logs"
77
+ # TODO
78
+
79
+ getLinesComplete: (xhr, status) =>
80
+ @reschedule()
81
+
82
+ start: ->
83
+ setTimeout @getLines, 0
84
+
85
+ reschedule: ->
86
+ setTimeout @getLines, @POLL_PERIOD
87
+
88
+ $ ->
89
+ logfeed = new LogFeed(new LogView)
90
+ logfeed.start()
91
+
92
+ new ThemeSwitcherView
93
+
94
+ console.log "Started fetching logs"
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any styles
10
+ * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
11
+ * file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,100 @@
1
+ $cyan: #66D9EF;
2
+ $purple: #AE81FF;
3
+ $yellow: #E6DB74;
4
+ $green: #A6E22E;
5
+ $magenta-like: #F92672;
6
+
7
+ $default: #fff;
8
+ $background: #272822;
9
+
10
+ $method: $purple;
11
+ $path: $yellow;
12
+ $ip: $default;
13
+ $date: $default;
14
+
15
+ $controller: $magenta-like;
16
+ $action: $yellow;
17
+ $format: $purple;
18
+
19
+ $template-name: $yellow;
20
+ $layout-name: $purple;
21
+ $rendering-time: $cyan;
22
+
23
+ $model-load: $magenta-like;
24
+ $sql-query: $default;
25
+
26
+ $total-time: $cyan;
27
+ $status-success: $green;
28
+ $status-failure: red;
29
+
30
+ [data-theme='dark'] {
31
+ color: $default;
32
+ background-color: $background;
33
+
34
+ // request
35
+ .method {
36
+ color: $method;
37
+ }
38
+
39
+ .path {
40
+ color: $path;
41
+ }
42
+
43
+ .ip {
44
+ color: $ip;
45
+ }
46
+
47
+ .date {
48
+ color: $date;
49
+ }
50
+
51
+ // controller
52
+ .controller {
53
+ color: $controller;
54
+ }
55
+
56
+ .action {
57
+ color: $action;
58
+ }
59
+
60
+ .format {
61
+ color: $format;
62
+ }
63
+
64
+ // render
65
+ .template-name {
66
+ color: $template-name;
67
+ }
68
+
69
+ .layout-name {
70
+ color: $layout-name;
71
+ }
72
+
73
+ .rendering-time {
74
+ color: $rendering-time;
75
+ }
76
+
77
+ // load/sql
78
+ .model-load {
79
+ color: $model-load;
80
+ }
81
+
82
+ .sql-query {
83
+ color: $sql-query;
84
+ }
85
+
86
+ // complete
87
+ .total-time {
88
+ color: $total-time;
89
+ }
90
+
91
+ .status {
92
+ &.success {
93
+ color: $status-success;
94
+ }
95
+
96
+ &.error {
97
+ color: $status-failure;
98
+ }
99
+ }
100
+ }
@@ -0,0 +1,99 @@
1
+ $blue: #4687b8;
2
+ $purple: #606aa1;
3
+ $green: #48b685;
4
+ $orange: #da564a;
5
+
6
+ $default: #585856;
7
+ $background: #fff;
8
+
9
+ $method: $purple;
10
+ $path: $blue;
11
+ $ip: $default;
12
+ $date: $default;
13
+
14
+ $controller: $orange;
15
+ $action: $orange;
16
+ $format: $purple;
17
+
18
+ $template-name: $orange;
19
+ $layout-name: $purple;
20
+ $rendering-time: $blue;
21
+
22
+ $model-load: $orange;
23
+ $sql-query: $default;
24
+
25
+ $total-time: $blue;
26
+ $status-success: $green;
27
+ $status-failure: red;
28
+
29
+ [data-theme='light'] {
30
+ color: $default;
31
+ background-color: $background;
32
+
33
+ // request
34
+ .method {
35
+ color: $method;
36
+ }
37
+
38
+ .path {
39
+ color: $path;
40
+ }
41
+
42
+ .ip {
43
+ color: $ip;
44
+ }
45
+
46
+ .date {
47
+ color: $date;
48
+ }
49
+
50
+ // controller
51
+ .controller {
52
+ color: $controller;
53
+ }
54
+
55
+ .action {
56
+ color: $action;
57
+ }
58
+
59
+ .format {
60
+ color: $format;
61
+ }
62
+
63
+ // render
64
+ .template-name {
65
+ color: $template-name;
66
+ }
67
+
68
+ .layout-name {
69
+ color: $layout-name;
70
+ }
71
+
72
+ .rendering-time {
73
+ color: $rendering-time;
74
+ }
75
+
76
+ // load/sql
77
+ .model-load {
78
+ color: $model-load;
79
+ }
80
+
81
+ .sql-query {
82
+ color: $sql-query;
83
+ }
84
+
85
+ // complete
86
+ .total-time {
87
+ color: $total-time;
88
+ }
89
+
90
+ .status {
91
+ &.success {
92
+ color: $status-success;
93
+ }
94
+
95
+ &.error {
96
+ color: $status-failure;
97
+ }
98
+ }
99
+ }
@@ -0,0 +1,38 @@
1
+ body {
2
+ margin: 0;
3
+ position: relative;
4
+ font: {
5
+ family: Consolas, Courier New, Courier, monospace;
6
+ size: 1em;
7
+ }
8
+ }
9
+
10
+ #lines {
11
+ margin: 0;
12
+ padding: 12px;
13
+
14
+ li {
15
+ margin: 2px 0;
16
+ list-style: none;
17
+ }
18
+ }
19
+
20
+ .resume-scroll-btn {
21
+ position: fixed;
22
+ right: 20px;
23
+ bottom: 20px;
24
+
25
+ &.hidden {
26
+ display: none;
27
+ }
28
+ }
29
+
30
+ .theme-switch {
31
+ position: fixed;
32
+ top: 20px;
33
+ right: 20px
34
+ }
35
+
36
+ .space {
37
+ width: 20px;
38
+ }
@@ -0,0 +1,4 @@
1
+ module Browserlog
2
+ class ApplicationController < ActionController::Base
3
+ end
4
+ end
@@ -0,0 +1,44 @@
1
+ module Browserlog
2
+ class LogsController < ApplicationController
3
+ before_filter :check_env
4
+ before_filter :check_auth
5
+
6
+ layout 'browserlog/application'
7
+
8
+ def index
9
+ @filename = "#{params[:env]}.log"
10
+ @filepath = Rails.root.join("log/#{@filename}")
11
+ end
12
+
13
+ def changes
14
+ lines, last_line_number = reader.read(offset: params[:currentLine].to_i)
15
+
16
+ respond_to do |format|
17
+ format.json do
18
+ render json: {
19
+ lines: lines.map! { |line| colorizer.colorize_line(line) } ,
20
+ last_line_number: last_line_number
21
+ }
22
+ end
23
+ end
24
+ end
25
+
26
+ private
27
+
28
+ def reader
29
+ Browserlog::LogReader.new
30
+ end
31
+
32
+ def colorizer
33
+ Browserlog::LogColorize.new
34
+ end
35
+
36
+ def check_env
37
+ fail unless %w(test development production).include?(params[:env])
38
+ end
39
+
40
+ def check_auth
41
+ fail 'Logs not allowed on production environment.' if Rails.env.production? && !Browserlog.config.allow_production_logs
42
+ end
43
+ end
44
+ end