logster 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (245) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/Gemfile +4 -0
  4. data/Guardfile +8 -0
  5. data/LICENSE.txt +22 -0
  6. data/README.md +38 -0
  7. data/Rakefile +18 -0
  8. data/assets/javascript/app.js +377 -0
  9. data/assets/javascript/external/ember.js +44267 -0
  10. data/assets/javascript/external/ember.min.js +19 -0
  11. data/assets/javascript/external/handlebars.min.js +28 -0
  12. data/assets/javascript/external/jquery.min.js +5 -0
  13. data/assets/javascript/external/lodash.min.js +56 -0
  14. data/assets/javascript/external/moment.min.js +6 -0
  15. data/assets/javascript/templates/application.handlebars +1 -0
  16. data/assets/javascript/templates/index.handlebars +48 -0
  17. data/assets/javascript/templates/message.handlebars +7 -0
  18. data/assets/stylesheets/app.css +188 -0
  19. data/bower_components/ember/.bower.json +22 -0
  20. data/bower_components/ember/.gitignore +5 -0
  21. data/bower_components/ember/Makefile +9 -0
  22. data/bower_components/ember/README.md +12 -0
  23. data/bower_components/ember/bower.json +11 -0
  24. data/bower_components/ember/component.json +13 -0
  25. data/bower_components/ember/composer.json +27 -0
  26. data/bower_components/ember/ember-template-compiler.js +320 -0
  27. data/bower_components/ember/ember.js +44267 -0
  28. data/bower_components/ember/ember.min.js +19 -0
  29. data/bower_components/ember/ember.prod.js +42649 -0
  30. data/bower_components/ember/package.json +11 -0
  31. data/bower_components/handlebars/.bower.json +16 -0
  32. data/bower_components/handlebars/.gitignore +2 -0
  33. data/bower_components/handlebars/README.md +11 -0
  34. data/bower_components/handlebars/bower.json +6 -0
  35. data/bower_components/handlebars/component.json +9 -0
  36. data/bower_components/handlebars/composer.json +35 -0
  37. data/bower_components/handlebars/handlebars-source.gemspec +21 -0
  38. data/bower_components/handlebars/handlebars.amd.js +2719 -0
  39. data/bower_components/handlebars/handlebars.amd.min.js +28 -0
  40. data/bower_components/handlebars/handlebars.js +2746 -0
  41. data/bower_components/handlebars/handlebars.js.nuspec +17 -0
  42. data/bower_components/handlebars/handlebars.min.js +28 -0
  43. data/bower_components/handlebars/handlebars.runtime.amd.js +515 -0
  44. data/bower_components/handlebars/handlebars.runtime.amd.min.js +27 -0
  45. data/bower_components/handlebars/handlebars.runtime.js +530 -0
  46. data/bower_components/handlebars/handlebars.runtime.min.js +27 -0
  47. data/bower_components/handlebars/lib/handlebars/source.rb +11 -0
  48. data/bower_components/jquery/.bower.json +37 -0
  49. data/bower_components/jquery/MIT-LICENSE.txt +21 -0
  50. data/bower_components/jquery/bower.json +27 -0
  51. data/bower_components/jquery/dist/jquery.js +9111 -0
  52. data/bower_components/jquery/dist/jquery.min.js +5 -0
  53. data/bower_components/jquery/dist/jquery.min.map +1 -0
  54. data/bower_components/jquery/src/ajax.js +806 -0
  55. data/bower_components/jquery/src/ajax/jsonp.js +89 -0
  56. data/bower_components/jquery/src/ajax/load.js +75 -0
  57. data/bower_components/jquery/src/ajax/parseJSON.js +13 -0
  58. data/bower_components/jquery/src/ajax/parseXML.js +28 -0
  59. data/bower_components/jquery/src/ajax/script.js +64 -0
  60. data/bower_components/jquery/src/ajax/var/nonce.js +5 -0
  61. data/bower_components/jquery/src/ajax/var/rquery.js +3 -0
  62. data/bower_components/jquery/src/ajax/xhr.js +130 -0
  63. data/bower_components/jquery/src/attributes.js +11 -0
  64. data/bower_components/jquery/src/attributes/attr.js +143 -0
  65. data/bower_components/jquery/src/attributes/classes.js +158 -0
  66. data/bower_components/jquery/src/attributes/prop.js +96 -0
  67. data/bower_components/jquery/src/attributes/support.js +35 -0
  68. data/bower_components/jquery/src/attributes/val.js +153 -0
  69. data/bower_components/jquery/src/callbacks.js +205 -0
  70. data/bower_components/jquery/src/core.js +500 -0
  71. data/bower_components/jquery/src/core/access.js +60 -0
  72. data/bower_components/jquery/src/core/init.js +123 -0
  73. data/bower_components/jquery/src/core/parseHTML.js +39 -0
  74. data/bower_components/jquery/src/core/ready.js +96 -0
  75. data/bower_components/jquery/src/core/var/rsingleTag.js +4 -0
  76. data/bower_components/jquery/src/css.js +455 -0
  77. data/bower_components/jquery/src/css/addGetHookIf.js +24 -0
  78. data/bower_components/jquery/src/css/curCSS.js +57 -0
  79. data/bower_components/jquery/src/css/defaultDisplay.js +69 -0
  80. data/bower_components/jquery/src/css/hiddenVisibleSelectors.js +15 -0
  81. data/bower_components/jquery/src/css/support.js +83 -0
  82. data/bower_components/jquery/src/css/swap.js +28 -0
  83. data/bower_components/jquery/src/css/var/cssExpand.js +3 -0
  84. data/bower_components/jquery/src/css/var/getStyles.js +5 -0
  85. data/bower_components/jquery/src/css/var/isHidden.js +13 -0
  86. data/bower_components/jquery/src/css/var/rmargin.js +3 -0
  87. data/bower_components/jquery/src/css/var/rnumnonpx.js +5 -0
  88. data/bower_components/jquery/src/data.js +175 -0
  89. data/bower_components/jquery/src/data/Data.js +181 -0
  90. data/bower_components/jquery/src/data/accepts.js +20 -0
  91. data/bower_components/jquery/src/data/var/data_priv.js +5 -0
  92. data/bower_components/jquery/src/data/var/data_user.js +5 -0
  93. data/bower_components/jquery/src/deferred.js +149 -0
  94. data/bower_components/jquery/src/deprecated.js +13 -0
  95. data/bower_components/jquery/src/dimensions.js +50 -0
  96. data/bower_components/jquery/src/effects.js +642 -0
  97. data/bower_components/jquery/src/effects/Tween.js +114 -0
  98. data/bower_components/jquery/src/effects/animatedSelector.js +13 -0
  99. data/bower_components/jquery/src/event.js +859 -0
  100. data/bower_components/jquery/src/event/alias.js +39 -0
  101. data/bower_components/jquery/src/event/support.js +9 -0
  102. data/bower_components/jquery/src/exports/amd.js +18 -0
  103. data/bower_components/jquery/src/exports/global.js +32 -0
  104. data/bower_components/jquery/src/intro.js +44 -0
  105. data/bower_components/jquery/src/jquery.js +36 -0
  106. data/bower_components/jquery/src/manipulation.js +583 -0
  107. data/bower_components/jquery/src/manipulation/_evalUrl.js +18 -0
  108. data/bower_components/jquery/src/manipulation/support.js +24 -0
  109. data/bower_components/jquery/src/manipulation/var/rcheckableType.js +3 -0
  110. data/bower_components/jquery/src/offset.js +204 -0
  111. data/bower_components/jquery/src/outro.js +1 -0
  112. data/bower_components/jquery/src/queue.js +142 -0
  113. data/bower_components/jquery/src/queue/delay.js +22 -0
  114. data/bower_components/jquery/src/selector-native.js +171 -0
  115. data/bower_components/jquery/src/selector-sizzle.js +14 -0
  116. data/bower_components/jquery/src/selector.js +1 -0
  117. data/bower_components/jquery/src/serialize.js +111 -0
  118. data/bower_components/jquery/src/sizzle/dist/sizzle.js +2015 -0
  119. data/bower_components/jquery/src/sizzle/dist/sizzle.min.js +3 -0
  120. data/bower_components/jquery/src/sizzle/dist/sizzle.min.map +1 -0
  121. data/bower_components/jquery/src/traversing.js +200 -0
  122. data/bower_components/jquery/src/traversing/findFilter.js +100 -0
  123. data/bower_components/jquery/src/traversing/var/rneedsContext.js +6 -0
  124. data/bower_components/jquery/src/var/arr.js +3 -0
  125. data/bower_components/jquery/src/var/class2type.js +4 -0
  126. data/bower_components/jquery/src/var/concat.js +5 -0
  127. data/bower_components/jquery/src/var/hasOwn.js +5 -0
  128. data/bower_components/jquery/src/var/indexOf.js +5 -0
  129. data/bower_components/jquery/src/var/pnum.js +3 -0
  130. data/bower_components/jquery/src/var/push.js +5 -0
  131. data/bower_components/jquery/src/var/rnotwhite.js +3 -0
  132. data/bower_components/jquery/src/var/slice.js +5 -0
  133. data/bower_components/jquery/src/var/strundefined.js +3 -0
  134. data/bower_components/jquery/src/var/support.js +4 -0
  135. data/bower_components/jquery/src/var/toString.js +5 -0
  136. data/bower_components/jquery/src/var/trim.js +3 -0
  137. data/bower_components/jquery/src/wrap.js +78 -0
  138. data/bower_components/lodash/.bower.json +34 -0
  139. data/bower_components/lodash/LICENSE.txt +22 -0
  140. data/bower_components/lodash/bower.json +23 -0
  141. data/bower_components/lodash/dist/lodash.compat.js +7157 -0
  142. data/bower_components/lodash/dist/lodash.compat.min.js +61 -0
  143. data/bower_components/lodash/dist/lodash.js +6785 -0
  144. data/bower_components/lodash/dist/lodash.min.js +56 -0
  145. data/bower_components/lodash/dist/lodash.underscore.js +4979 -0
  146. data/bower_components/lodash/dist/lodash.underscore.min.js +39 -0
  147. data/bower_components/moment/.bower.json +31 -0
  148. data/bower_components/moment/LICENSE +22 -0
  149. data/bower_components/moment/bower.json +20 -0
  150. data/bower_components/moment/lang/ar-ma.js +56 -0
  151. data/bower_components/moment/lang/ar.js +56 -0
  152. data/bower_components/moment/lang/bg.js +86 -0
  153. data/bower_components/moment/lang/br.js +107 -0
  154. data/bower_components/moment/lang/bs.js +139 -0
  155. data/bower_components/moment/lang/ca.js +66 -0
  156. data/bower_components/moment/lang/cs.js +155 -0
  157. data/bower_components/moment/lang/cv.js +59 -0
  158. data/bower_components/moment/lang/cy.js +77 -0
  159. data/bower_components/moment/lang/da.js +56 -0
  160. data/bower_components/moment/lang/de.js +71 -0
  161. data/bower_components/moment/lang/el.js +79 -0
  162. data/bower_components/moment/lang/en-au.js +62 -0
  163. data/bower_components/moment/lang/en-ca.js +59 -0
  164. data/bower_components/moment/lang/en-gb.js +63 -0
  165. data/bower_components/moment/lang/eo.js +65 -0
  166. data/bower_components/moment/lang/es.js +75 -0
  167. data/bower_components/moment/lang/et.js +76 -0
  168. data/bower_components/moment/lang/eu.js +60 -0
  169. data/bower_components/moment/lang/fa.js +97 -0
  170. data/bower_components/moment/lang/fi.js +103 -0
  171. data/bower_components/moment/lang/fo.js +56 -0
  172. data/bower_components/moment/lang/fr-ca.js +54 -0
  173. data/bower_components/moment/lang/fr.js +58 -0
  174. data/bower_components/moment/lang/gl.js +71 -0
  175. data/bower_components/moment/lang/he.js +77 -0
  176. data/bower_components/moment/lang/hi.js +105 -0
  177. data/bower_components/moment/lang/hr.js +140 -0
  178. data/bower_components/moment/lang/hu.js +105 -0
  179. data/bower_components/moment/lang/hy-am.js +113 -0
  180. data/bower_components/moment/lang/id.js +67 -0
  181. data/bower_components/moment/lang/is.js +124 -0
  182. data/bower_components/moment/lang/it.js +59 -0
  183. data/bower_components/moment/lang/ja.js +58 -0
  184. data/bower_components/moment/lang/ka.js +108 -0
  185. data/bower_components/moment/lang/km.js +55 -0
  186. data/bower_components/moment/lang/ko.js +63 -0
  187. data/bower_components/moment/lang/lb.js +160 -0
  188. data/bower_components/moment/lang/lt.js +118 -0
  189. data/bower_components/moment/lang/lv.js +77 -0
  190. data/bower_components/moment/lang/mk.js +86 -0
  191. data/bower_components/moment/lang/ml.js +64 -0
  192. data/bower_components/moment/lang/mr.js +104 -0
  193. data/bower_components/moment/lang/ms-my.js +66 -0
  194. data/bower_components/moment/lang/nb.js +57 -0
  195. data/bower_components/moment/lang/ne.js +105 -0
  196. data/bower_components/moment/lang/nl.js +67 -0
  197. data/bower_components/moment/lang/nn.js +56 -0
  198. data/bower_components/moment/lang/pl.js +98 -0
  199. data/bower_components/moment/lang/pt-br.js +56 -0
  200. data/bower_components/moment/lang/pt.js +60 -0
  201. data/bower_components/moment/lang/ro.js +72 -0
  202. data/bower_components/moment/lang/ru.js +163 -0
  203. data/bower_components/moment/lang/sk.js +156 -0
  204. data/bower_components/moment/lang/sl.js +144 -0
  205. data/bower_components/moment/lang/sq.js +61 -0
  206. data/bower_components/moment/lang/sr-cyr.js +106 -0
  207. data/bower_components/moment/lang/sr.js +106 -0
  208. data/bower_components/moment/lang/sv.js +63 -0
  209. data/bower_components/moment/lang/ta.js +112 -0
  210. data/bower_components/moment/lang/th.js +58 -0
  211. data/bower_components/moment/lang/tl-ph.js +58 -0
  212. data/bower_components/moment/lang/tr.js +93 -0
  213. data/bower_components/moment/lang/tzm-la.js +55 -0
  214. data/bower_components/moment/lang/tzm.js +55 -0
  215. data/bower_components/moment/lang/uk.js +157 -0
  216. data/bower_components/moment/lang/uz.js +55 -0
  217. data/bower_components/moment/lang/vi.js +62 -0
  218. data/bower_components/moment/lang/zh-cn.js +108 -0
  219. data/bower_components/moment/lang/zh-tw.js +84 -0
  220. data/bower_components/moment/min/langs.js +5991 -0
  221. data/bower_components/moment/min/langs.min.js +3 -0
  222. data/bower_components/moment/min/moment-with-langs.js +7993 -0
  223. data/bower_components/moment/min/moment-with-langs.min.js +9 -0
  224. data/bower_components/moment/min/moment.min.js +6 -0
  225. data/bower_components/moment/moment.js +2489 -0
  226. data/bower_components/moment/readme.md +368 -0
  227. data/lib/logster.rb +9 -0
  228. data/lib/logster/logger.rb +31 -0
  229. data/lib/logster/message.rb +42 -0
  230. data/lib/logster/middleware/reporter.rb +13 -0
  231. data/lib/logster/middleware/viewer.rb +122 -0
  232. data/lib/logster/rails/railtie.rb +39 -0
  233. data/lib/logster/redis_store.rb +124 -0
  234. data/lib/logster/version.rb +3 -0
  235. data/logster.gemspec +30 -0
  236. data/test/logster/middleware/test_viewer.rb +34 -0
  237. data/test/logster/test_redis_store.rb +112 -0
  238. data/test/test_helper.rb +6 -0
  239. data/website/Gemfile +6 -0
  240. data/website/config.ru +2 -0
  241. data/website/data/data.json +1 -0
  242. data/website/docker_container/logster.yml +95 -0
  243. data/website/sample.rb +85 -0
  244. data/website/scripts/persist_logs.rb +13 -0
  245. metadata +375 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d38243e6aa8453d6a6f387598eaa9cc1ddac6a0c
4
+ data.tar.gz: 29a71b02794bbb9ab65585c1834a3f2b5b580458
5
+ SHA512:
6
+ metadata.gz: c7945e8d28eb6df00ab05c4ddfd2f7c488fcac7b2ab98059d3a52b053c5de686dd68f62077144fb08e10b09e41a7ee4fff9bae6bc0de144695fdc2005782f53c
7
+ data.tar.gz: 7c25d78b5e1d14f7d67ddfe9fb157b0653cd32df923061555beda793224d6df9e9541012645cfa2a2f80d07f01b332d4af96fd5d586776c18953eb647cfca77b
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rack-log-viewer.gemspec
4
+ gemspec
@@ -0,0 +1,8 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard :minitest do
5
+ watch(%r{^test/(.*)\/?test_(.*)\.rb$})
6
+ watch(%r{^lib/(.*/)?([^/]+)\.rb$}) { |m| "test/#{m[1]}test_#{m[2]}.rb" }
7
+ watch(%r{^test/test_helper\.rb$}) { 'test' }
8
+ end
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 TODO: Write your name
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,38 @@
1
+ # Logster
2
+
3
+ A web log viewer and logging framework for Rack applications
4
+
5
+ ![logster](http://i.imgur.com/cvfcQpv.png)
6
+
7
+ ## Installation
8
+
9
+ Add these lines to your application's Gemfile:
10
+
11
+ gem 'redis'
12
+ gem 'logster'
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Logster will wire up `/logs` path in your Rails app in **development** mode only. Production mode is being worked on.
19
+
20
+ ## Usage
21
+
22
+ Logster is in current development, at the moment the focus is on a decent tool for dev. Once that is complete production mode will be build.
23
+
24
+ The concept is to have an embedded "exception reporting service" admins can view on live sites.
25
+
26
+ Logs will be visible by default at `http://sitename.com/logs`, only dev mode is implemented now.
27
+
28
+ ## Thanks
29
+
30
+ Logster UI is built using [Ember.js](http://emberjs.com/)
31
+
32
+ ## Contributing
33
+
34
+ 1. Fork it ( https://github.com/SamSaffron/logster/fork )
35
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
36
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
37
+ 4. Push to the branch (`git push origin my-new-feature`)
38
+ 5. Create a new Pull Request
@@ -0,0 +1,18 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ desc "copy js assets"
5
+ task :copy_assets do
6
+ `cp bower_components/moment/min/moment.min.js assets/javascript/external`
7
+ `cp bower_components/jquery/dist/jquery.min.js assets/javascript/external`
8
+ `cp bower_components/ember/ember.js assets/javascript/external`
9
+ `cp bower_components/ember/ember.min.js assets/javascript/external`
10
+ `cp bower_components/handlebars/handlebars.min.js assets/javascript/external`
11
+ `cp bower_components/lodash/dist/lodash.min.js assets/javascript/external`
12
+ end
13
+
14
+ Rake::TestTask.new do |t|
15
+ t.pattern = "test/**/test_*.rb"
16
+ end
17
+
18
+ task(default: :test)
@@ -0,0 +1,377 @@
1
+ moment.lang('en', {
2
+ relativeTime : {
3
+ future: "in %s",
4
+ past: "%s ago",
5
+ s: "secs",
6
+ m: "a min",
7
+ mm: "%d mins",
8
+ h: "an hr",
9
+ hh: "%d hrs",
10
+ d: "a day",
11
+ dd: "%d days",
12
+ M: "a mth",
13
+ MM: "%d mths",
14
+ y: "a yr",
15
+ yy: "%d yrs"
16
+ }
17
+ });
18
+
19
+
20
+ App = Ember.Application.create({
21
+ });
22
+
23
+ App.ajax = function(url, settings) {
24
+ settings = settings || {};
25
+ settings.headers = settings.headers || {};
26
+ settings.headers["X-SILENCE-LOGGER"] = true;
27
+ return $.ajax(Logger.rootPath + url, settings);
28
+ };
29
+
30
+
31
+ App.Router.map(function(){
32
+ this.route("index", { path: "/" });
33
+ });
34
+
35
+ App.Message = Ember.Object.extend({
36
+
37
+ MAX_LEN: 200,
38
+
39
+ expand: function(){
40
+ this.set("expanded",true);
41
+ },
42
+
43
+ hasMore: function(){
44
+ var message = this.get("message");
45
+ var expanded = this.get("expanded");
46
+
47
+ return !expanded && message.length > this.MAX_LEN;
48
+ }.property("message", "expanded"),
49
+
50
+ displayMessage: function(){
51
+ var message = this.get("message");
52
+ var expanded = this.get("expanded");
53
+
54
+ if(!expanded && message.length > this.MAX_LEN){
55
+ message = message.substr(0,this.MAX_LEN);
56
+ }
57
+ return message;
58
+ }.property("message","expanded"),
59
+
60
+ rowClass: function() {
61
+ switch(this.get("severity")){
62
+ case 0:
63
+ return "debug";
64
+ case 1:
65
+ return "info";
66
+ case 2:
67
+ return "warn";
68
+ case 3:
69
+ return "error";
70
+ case 4:
71
+ return "fatal";
72
+ }
73
+ }.property("severity"),
74
+
75
+ glyph: function(){
76
+ switch(this.get("severity")){
77
+ case 0:
78
+ return "";
79
+ case 1:
80
+ return "";
81
+ case 2:
82
+ return "x";
83
+ case 3:
84
+ return "!";
85
+ case 4:
86
+ return "!!";
87
+ }
88
+ }.property("severity")
89
+ });
90
+
91
+ App.MessageCollection = Em.Object.extend({
92
+
93
+ messages: Em.A(),
94
+ total: 0,
95
+
96
+ load: function(opts){
97
+ var self = this;
98
+ opts = opts || {};
99
+
100
+ var data = {
101
+ filter: this.get("filter").join("_")
102
+ };
103
+
104
+ if(opts.before){
105
+ data.before = opts.before;
106
+ }
107
+
108
+ if (opts.after){
109
+ data.after = opts.after;
110
+ }
111
+
112
+ App.ajax("/messages.json", {
113
+ data: data
114
+ }).success(function(data){
115
+ if(data.messages.length > 0) {
116
+ var newRows = self.toMessages(data.messages);
117
+ var messages = self.get("messages");
118
+ if(opts.before) {
119
+ messages.unshiftObjects(newRows);
120
+ } else {
121
+ messages.addObjects(newRows);
122
+ }
123
+ }
124
+ self.set("total",data.total);
125
+ });
126
+ },
127
+
128
+ reload: function(){
129
+ this.set("total", 0);
130
+ this.get("messages").clear();
131
+
132
+ this.load();
133
+ },
134
+
135
+ loadMore: function(){
136
+
137
+ var messages = this.get("messages");
138
+ if(messages.length === 0){
139
+ return;
140
+ }
141
+
142
+ var lastKey = messages[messages.length-1].get("key");
143
+ this.load({
144
+ after: lastKey
145
+ });
146
+ },
147
+
148
+ moreBefore: function(){
149
+ return this.get("totalBefore") > 0;
150
+ }.property("totalBefore"),
151
+
152
+ totalBefore: function() {
153
+ return this.get("total") - this.get("messages").length;
154
+ }.property("total", "messages.@each"),
155
+
156
+ showMoreBefore: function() {
157
+ var messages = this.get("messages");
158
+ var firstKey = messages[0].get("key");
159
+
160
+ this.load({
161
+ before: firstKey
162
+ });
163
+ },
164
+
165
+ toMessages: function(messages){
166
+ return messages.map(function(m){
167
+ return App.Message.create(m);
168
+ });
169
+ }
170
+ });
171
+
172
+
173
+ App.IndexRoute = Em.Route.extend({
174
+ model: function(){
175
+ return App.MessageCollection.create();
176
+ },
177
+
178
+ setupController: function(controller, model){
179
+ this._super(controller, model);
180
+ controller.setProperties({
181
+ "showDebug": true,
182
+ "showInfo": true,
183
+ "showWarn": true,
184
+ "showErr": true,
185
+ "showFatal": true
186
+ });
187
+ controller.set("initialized", true);
188
+ model.reload();
189
+ }
190
+ });
191
+
192
+ App.IndexController = Em.Controller.extend({
193
+ actions: {
194
+ expandMessage: function(message){
195
+ message.expand();
196
+ },
197
+
198
+ showMoreBefore: function(){
199
+ this.get('model').showMoreBefore();
200
+ },
201
+
202
+ loadMore: function(){
203
+ return this.get('model').loadMore();
204
+ }
205
+ },
206
+
207
+ filterChanged: function(){
208
+ var severities = ["Debug", "Info", "Warn", "Err", "Fatal"];
209
+ var filter = [];
210
+ for(var i=0; i<5; i++){
211
+ if(this.get("show" + severities[i])){
212
+ filter.push(i);
213
+ }
214
+ }
215
+
216
+ // always show unknown, rare
217
+ filter.push(5);
218
+ var model = this.get("model");
219
+ model.set("filter", filter);
220
+ if(this.get("initialized")){
221
+ model.reload();
222
+ }
223
+ }.observes(
224
+ "showDebug",
225
+ "showInfo",
226
+ "showWarn",
227
+ "showErr",
228
+ "showFatal"
229
+ ),
230
+
231
+ checkIfAtBottom: function(){
232
+ if (this.checkedBottom) {
233
+ return;
234
+ }
235
+
236
+ var $topPanel = $("#top-panel");
237
+
238
+ var scrollTop = $topPanel.scrollTop();
239
+ var height = $topPanel.height();
240
+ var scrollHeight = $topPanel[0].scrollHeight;
241
+
242
+ this.stickToBottom = scrollHeight - 20 < height + scrollTop;
243
+ this.checkedBottom = true;
244
+ }
245
+ });
246
+
247
+ App.IndexView = Em.View.extend({
248
+ divideView: function(fromTop, win){
249
+ var $win = win || $(window);
250
+ var height = $win.height();
251
+ var fromBottom = $win.height() - fromTop;
252
+
253
+ if (fromTop < 100 || fromTop + 100 > height) {
254
+ return;
255
+ }
256
+
257
+ this.topPanel.css("bottom", fromBottom + 5);
258
+ this.bottomPanel.css("height", fromBottom - 15);
259
+ this.divider.css("bottom", fromBottom - 5);
260
+ },
261
+
262
+ didInsertElement: function(){
263
+ var self = this;
264
+ this.refreshInterval = setInterval(function(){
265
+ self.get('controller').send("loadMore");
266
+ }, 3000);
267
+
268
+ // inspired by http://plugins.jquery.com/misc/textarea.js
269
+ this.topPanel = $("#top-panel");
270
+ this.divider = $("#divider");
271
+ this.bottomPanel = $("#bottom-panel");
272
+
273
+ var $win = $(window),
274
+ resizing = false;
275
+
276
+ var performDrag = function(e){
277
+ if(!resizing) { return; }
278
+ self.divideView(e.clientY, $win);
279
+ };
280
+
281
+ var endDrag = function(){
282
+ $("#overlay").remove();
283
+ resizing = false;
284
+
285
+ if(localStorage){
286
+ localStorage.logster_divider_bottom = parseInt(self.divider.css("bottom"),10);
287
+ }
288
+
289
+ $(document)
290
+ .unbind('mousemove', performDrag)
291
+ .unbind('mouseup', endDrag);
292
+ };
293
+
294
+ self.divider.on("mousedown", function(){
295
+ $("<div id='overlay'></div>").appendTo($("body"));
296
+ resizing = true;
297
+ $(document)
298
+ .mousemove(_.throttle(performDrag,25))
299
+ .mouseup(endDrag);
300
+ }).append("<div class='line-1'></div><div class='line-2'></div><div class='line-3'></div>");
301
+
302
+
303
+ Em.run.next(function(){
304
+ if(localStorage && localStorage.logster_divider_bottom){
305
+ var fromTop = $win.height() - parseInt(localStorage.logster_divider_bottom,10);
306
+ self.divideView(fromTop, $win);
307
+ }
308
+ });
309
+ },
310
+
311
+ willDestroyElement: function(){
312
+ $("#divider").off("mousedown");
313
+ clearInterval(this.refreshInterval);
314
+ }
315
+ });
316
+
317
+ App.MessageView = Em.View.extend({
318
+ templateName: "message",
319
+
320
+ tagName: "tr",
321
+
322
+ classNameBindings: ["context.rowClass", ":message-row", "context.selected:selected"],
323
+
324
+ click: function(){
325
+ var old = this.get("controller.currentMessage");
326
+ if(old){
327
+ old.set("selected",false);
328
+ }
329
+ this.set("context.selected", true);
330
+ this.set("controller.currentMessage", this.get("context"));
331
+ },
332
+
333
+ willInsertElement: function(){
334
+ this.get("controller").checkIfAtBottom();
335
+ },
336
+
337
+ didInsertElement: function(){
338
+ var self = this;
339
+ var $topPanel = $("#top-panel");
340
+ Em.run.next(function(){
341
+ self.set("controller.checkedBottom", false);
342
+
343
+ if (self.get("controller.stickToBottom")){
344
+ self.set("controller.stickToBottom", false);
345
+ $topPanel.scrollTop($topPanel[0].scrollHeight - $topPanel.height());
346
+ }
347
+ });
348
+ }
349
+ });
350
+
351
+ App.ApplicationView = Em.View.extend({
352
+ didInsertElement: function(){
353
+ var updateTimes = function(){
354
+ $('.auto-update-time').each(function(){
355
+ var newTime = moment(
356
+ parseInt(this.getAttribute('data-timestamp'),10)
357
+ ).fromNow();
358
+
359
+ if(newTime != this.innerText) {
360
+ this.innerText = newTime;
361
+ }
362
+
363
+ });
364
+ Em.run.later(updateTimes, 10000);
365
+ };
366
+
367
+ Em.run.later(updateTimes, 10000);
368
+ }
369
+ });
370
+
371
+ Handlebars.registerHelper('timeAgo', function(prop, options){
372
+ var timestamp = Ember.Handlebars.get(this, prop, options);
373
+ var parsed = moment(timestamp);
374
+ var formatted = "<span data-timestamp='" + timestamp + "' class='auto-update-time' title='" + parsed.format() + "'>" + parsed.fromNow() + "</span>";
375
+
376
+ return new Handlebars.SafeString(formatted);
377
+ });