ood_appkit 0.0.3 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 855e5b35f11c2361f24bb43d8e6bbc0e3dc7a539
4
- data.tar.gz: 4bf1b4d053ceaa167aac2eba7d7a4d6a98726b7d
3
+ metadata.gz: 39b8d7a85e8c3c1493bf2ce9312efe948b4fc2ee
4
+ data.tar.gz: 6b88fe091a61ac648c19257e6d6b6971706fdec8
5
5
  SHA512:
6
- metadata.gz: 4e3795b83fe9770fa02d1ba989fc66b621dbb8fc10509b8c1768e7ffb8ecac28b0589c263f8d8c2cc7e749953c55c46ca8892b1524b6bb83cca6169e3257a8f7
7
- data.tar.gz: ff2d6778b998fddd391acc569d597d8f6745e1e6caf168ea09bbc37197232c3a1a873b1928bd45dd0f6a2c6570be36cbbbaa4c604d101f0031238c4d7cef3647
6
+ metadata.gz: 27295db64c6f2845ce43e998d228102c02a872dd9f9fcc1540f6cb591eca728f3de40a950be5244e7d3798bab1321e6552f2d235475a6a3e7e9c071f92b9059e
7
+ data.tar.gz: ce7771692a67c9fa0ddbcf71ae8bbde584b2e19ce9f99538ca65b05ad678d0a65870e8a3c114e0007965f8a95ef453a019302c87baeb2dc962c89958732e4fd1
data/README.md CHANGED
@@ -250,6 +250,7 @@ And add a show view for this controller:
250
250
  </div>
251
251
  ```
252
252
 
253
+
253
254
  ### Override Bootstrap Variables
254
255
 
255
256
  You can easily override any bootstrap variable using environment variables:
@@ -341,6 +342,39 @@ It is also included if you import the default stylesheet:
341
342
  @import "ood_appkit";
342
343
  ```
343
344
 
345
+ ### Custom Log Formatting
346
+
347
+ A custom log formatter is provided, along with lograge, to both reduce the
348
+ amount of unnecessary logging in production but properly prefix each log with
349
+ timestamp, log severity, and the name of the application. By default
350
+ `enable_log_formatter` is set to true for the production environment, but you
351
+ can turn it on all the time by using an initializer:
352
+
353
+ ```ruby
354
+ # config/initializers/ood_appkit.rb
355
+
356
+ OodAppkit.configure do |config|
357
+ # Default
358
+ config.enable_log_formatter = true
359
+ end
360
+ ```
361
+
362
+ This does several things things:
363
+
364
+ 1. enable lograge
365
+ 2. call `OodAppkit::LogFormatter.setup` which
366
+
367
+ * sets the formatter of the Rails logger to an instance of OodAppkit::LogFormatter
368
+ * and sets the `progname` of the Rails logger to the `APP_TOKEN` env var if it is set
369
+
370
+
371
+ In production, a single log will look like:
372
+
373
+ ```
374
+ [2016-06-20 10:23:59 -0400 sys/dashboard] "INFO method=GET path=/pun/dev/dashboard/ format=html controller=dashboard action=index status=200 duration=297.15 view=290.20"
375
+ ```
376
+
377
+
344
378
  ## Branding Features
345
379
 
346
380
  To take advantage of branding features you must import it in your stylesheet:
@@ -39,6 +39,11 @@ module OodAppkit
39
39
  # @return [OpenStruct] bootstrap variables to override
40
40
  attr_accessor :bootstrap
41
41
 
42
+ # Set to false if you don't want Rails.logger formatter
43
+ # to use LogFormatter and lograge to be enabled automatically
44
+ # @return [boolean] whether to use OodAppkit log formatting in production
45
+ attr_accessor :enable_log_formatter
46
+
42
47
  # Customize configuration for this object.
43
48
  # @yield [self]
44
49
  def configure
@@ -95,6 +100,8 @@ module OodAppkit
95
100
  navbar_inverse_brand_hover_color: '$navbar-inverse-link-hover-color'
96
101
  )
97
102
  ENV.each {|k, v| /^BOOTSTRAP_(?<name>.+)$/ =~ k ? self.bootstrap[name.downcase] = v : nil}
103
+
104
+ self.enable_log_formatter = ::Rails.env.production?
98
105
  end
99
106
  end
100
107
  end
@@ -1,3 +1,5 @@
1
+ require 'lograge'
2
+
1
3
  module OodAppkit
2
4
  # The Rails Engine that defines the OodAppkit environment
3
5
  class Engine < Rails::Engine
@@ -6,15 +8,20 @@ module OodAppkit
6
8
  OodAppkit.set_default_configuration
7
9
  end
8
10
 
9
- # Confirm the `OodAppkit.dataroot` configuration option was set
11
+ # enable lograge if gem available
12
+ initializer "lograge" do |app|
13
+ if OodAppkit.enable_log_formatter
14
+ # enable lograge to use with formatter
15
+ app.config.lograge.enabled = true
16
+ end
17
+ end
18
+
10
19
  config.after_initialize do
20
+ # Confirm the `OodAppkit.dataroot` configuration option was set
11
21
  raise UndefinedDataroot, "OodAppkit.dataroot must be defined (default: ENV['OOD_DATAROOT'])" unless OodAppkit.dataroot
12
- end
13
22
 
14
- config.to_prepare do
15
- # TODO:
16
- # make the helper available to all views
17
- # i.e. ApplicationController.helper(OodBannerHelper)
23
+ # setup logger to use proper formatter and set progname
24
+ LogFormatter.setup if OodAppkit.enable_log_formatter
18
25
  end
19
26
 
20
27
  # An exception raised when `OodAppkit.dataroot` configuration option is undefined
@@ -0,0 +1,34 @@
1
+ module OodAppkit
2
+ # format log messages with timestamp severity and app token e.g.:
3
+ #
4
+ # [2016-06-17 15:31:01 -0400 sys/dashboard] INFO GET...
5
+ #
6
+ class LogFormatter
7
+ def call(severity, timestamp, progname, msg)
8
+ severity_d = severity ? severity[0,5].rjust(5).upcase : "UNKNO"
9
+ timestamp_d = timestamp ? timestamp.localtime : Time.now.localtime
10
+ msg_d = (String === msg ? msg.strip.inspect : msg.inspect)
11
+
12
+ "[#{timestamp_d} #{progname}] #{severity_d} #{msg_d}\n"
13
+ end
14
+
15
+ # make the Rails logger use this class for the formatter
16
+ # and set the progname to be the app token
17
+ def self.setup
18
+ ::Rails.logger.formatter = LogFormatter.new
19
+
20
+ # ActiveSupport::TaggedLogging.new calls
21
+ #
22
+ # logger.formatter.extend(Formatter)
23
+ #
24
+ # in an undocumented submodule ActiveSupport::TaggedLogging::Formatter.
25
+ # So to modify a TaggedLogging logger with another formatter we must
26
+ # extend our formatter in the same way.
27
+ if defined?( ActiveSupport::TaggedLogging ) && ::Rails.logger.kind_of?( ActiveSupport::TaggedLogging )
28
+ ::Rails.logger.formatter.extend(ActiveSupport::TaggedLogging::Formatter)
29
+ end
30
+
31
+ ::Rails.logger.progname = ENV['APP_TOKEN'] if ENV['APP_TOKEN']
32
+ end
33
+ end
34
+ end
@@ -1,4 +1,4 @@
1
1
  module OodAppkit
2
2
  # The current version of OodAppkit
3
- VERSION = "0.0.3"
3
+ VERSION = "0.1.0"
4
4
  end
data/lib/ood_appkit.rb CHANGED
@@ -8,6 +8,7 @@ require 'ood_appkit/shell_url'
8
8
  require 'ood_appkit/files_url'
9
9
  require 'ood_appkit/files_rack_app'
10
10
  require 'ood_appkit/markdown_template_handler'
11
+ require 'ood_appkit/log_formatter'
11
12
 
12
13
  # The main namespace for OodAppkit. Provides a global configuration.
13
14
  module OodAppkit
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ood_appkit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Franz
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.2'
55
+ - !ruby/object:Gem::Dependency
56
+ name: lograge
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.3'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.3'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: sqlite3
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -93,6 +107,7 @@ files:
93
107
  - lib/ood_appkit/engine.rb
94
108
  - lib/ood_appkit/files_rack_app.rb
95
109
  - lib/ood_appkit/files_url.rb
110
+ - lib/ood_appkit/log_formatter.rb
96
111
  - lib/ood_appkit/markdown_template_handler.rb
97
112
  - lib/ood_appkit/public_url.rb
98
113
  - lib/ood_appkit/shell_url.rb
@@ -125,8 +140,6 @@ files:
125
140
  - test/dummy/config/initializers/wrap_parameters.rb
126
141
  - test/dummy/config/locales/en.yml
127
142
  - test/dummy/config/routes.rb
128
- - test/dummy/db/test.sqlite3
129
- - test/dummy/log/test.log
130
143
  - test/dummy/public/404.html
131
144
  - test/dummy/public/422.html
132
145
  - test/dummy/public/500.html
@@ -154,7 +167,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
154
167
  version: '0'
155
168
  requirements: []
156
169
  rubyforge_project:
157
- rubygems_version: 2.4.5
170
+ rubygems_version: 2.4.8
158
171
  signing_key:
159
172
  specification_version: 4
160
173
  summary: Open OnDemand gem to help build OOD apps and interface with other OOD apps.
@@ -167,32 +180,29 @@ test_files:
167
180
  - test/dummy/bin/bundle
168
181
  - test/dummy/bin/rails
169
182
  - test/dummy/bin/rake
183
+ - test/dummy/config/application.rb
184
+ - test/dummy/config/boot.rb
185
+ - test/dummy/config/database.yml
186
+ - test/dummy/config/environment.rb
170
187
  - test/dummy/config/environments/development.rb
171
188
  - test/dummy/config/environments/production.rb
172
189
  - test/dummy/config/environments/test.rb
173
- - test/dummy/config/initializers/filter_parameter_logging.rb
174
190
  - test/dummy/config/initializers/backtrace_silencers.rb
191
+ - test/dummy/config/initializers/filter_parameter_logging.rb
175
192
  - test/dummy/config/initializers/inflections.rb
176
193
  - test/dummy/config/initializers/mime_types.rb
177
194
  - test/dummy/config/initializers/secret_token.rb
178
195
  - test/dummy/config/initializers/session_store.rb
179
196
  - test/dummy/config/initializers/wrap_parameters.rb
180
197
  - test/dummy/config/locales/en.yml
181
- - test/dummy/config/application.rb
182
- - test/dummy/config/boot.rb
183
- - test/dummy/config/database.yml
184
- - test/dummy/config/environment.rb
185
198
  - test/dummy/config/routes.rb
186
- - test/dummy/db/test.sqlite3
187
- - test/dummy/log/test.log
199
+ - test/dummy/config.ru
188
200
  - test/dummy/public/404.html
189
201
  - test/dummy/public/422.html
190
202
  - test/dummy/public/500.html
191
203
  - test/dummy/public/favicon.ico
192
- - test/dummy/README.rdoc
193
204
  - test/dummy/Rakefile
194
- - test/dummy/config.ru
205
+ - test/dummy/README.rdoc
195
206
  - test/integration/navigation_test.rb
196
207
  - test/ood_appkit_test.rb
197
208
  - test/test_helper.rb
198
- has_rdoc:
File without changes
@@ -1,285 +0,0 @@
1
-  (4.3ms) begin transaction
2
- ---------------------------
3
- OodAppkitTest: test_files_urls
4
- ---------------------------
5
-  (0.1ms) rollback transaction
6
-  (0.1ms) begin transaction
7
- ---------------------------
8
- OodAppkitTest: test_shell_urls
9
- ---------------------------
10
-  (0.1ms) rollback transaction
11
-  (0.0ms) begin transaction
12
- ----------------------
13
- OodAppkitTest: test_truth
14
- ----------------------
15
-  (0.0ms) rollback transaction
16
-  (1.9ms) begin transaction
17
- ---------------------------
18
- OodAppkitTest: test_files_urls
19
- ---------------------------
20
-  (0.1ms) rollback transaction
21
-  (0.1ms) begin transaction
22
- ---------------------------
23
- OodAppkitTest: test_shell_urls
24
- ---------------------------
25
-  (0.1ms) rollback transaction
26
-  (0.1ms) begin transaction
27
- ----------------------
28
- OodAppkitTest: test_truth
29
- ----------------------
30
-  (0.0ms) rollback transaction
31
-  (1.9ms) begin transaction
32
- ---------------------------
33
- OodAppkitTest: test_files_urls
34
- ---------------------------
35
-  (0.1ms) rollback transaction
36
-  (0.1ms) begin transaction
37
- ---------------------------
38
- OodAppkitTest: test_shell_urls
39
- ---------------------------
40
-  (0.1ms) rollback transaction
41
-  (0.0ms) begin transaction
42
- ----------------------
43
- OodAppkitTest: test_truth
44
- ----------------------
45
-  (0.1ms) rollback transaction
46
-  (1.1ms) begin transaction
47
- ---------------------------
48
- OodAppkitTest: test_files_urls
49
- ---------------------------
50
-  (0.1ms) rollback transaction
51
-  (0.1ms) begin transaction
52
- ---------------------------
53
- OodAppkitTest: test_shell_urls
54
- ---------------------------
55
-  (0.1ms) rollback transaction
56
-  (0.1ms) begin transaction
57
- ----------------------
58
- OodAppkitTest: test_truth
59
- ----------------------
60
-  (0.0ms) rollback transaction
61
-  (2.5ms) begin transaction
62
- ---------------------------
63
- OodAppkitTest: test_files_urls
64
- ---------------------------
65
-  (0.1ms) rollback transaction
66
-  (0.1ms) begin transaction
67
- ---------------------------
68
- OodAppkitTest: test_shell_urls
69
- ---------------------------
70
-  (0.1ms) rollback transaction
71
-  (0.1ms) begin transaction
72
- ----------------------
73
- OodAppkitTest: test_truth
74
- ----------------------
75
-  (0.0ms) rollback transaction
76
-  (48.7ms) begin transaction
77
- ------------------------------------------------
78
- OodAppkit::WikiControllerTest: test_should_get_show
79
- ------------------------------------------------
80
-  (0.1ms) rollback transaction
81
-  (0.1ms) begin transaction
82
- ---------------------------
83
- OodAppkitTest: test_files_urls
84
- ---------------------------
85
-  (0.1ms) rollback transaction
86
-  (0.1ms) begin transaction
87
- ---------------------------
88
- OodAppkitTest: test_shell_urls
89
- ---------------------------
90
-  (0.1ms) rollback transaction
91
-  (0.1ms) begin transaction
92
- ----------------------
93
- OodAppkitTest: test_truth
94
- ----------------------
95
-  (0.0ms) rollback transaction
96
-  (2.6ms) begin transaction
97
- ------------------------------------------------
98
- OodAppkit::WikiControllerTest: test_should_get_show
99
- ------------------------------------------------
100
-  (0.1ms) rollback transaction
101
-  (0.1ms) begin transaction
102
- ---------------------------
103
- OodAppkitTest: test_files_urls
104
- ---------------------------
105
-  (0.1ms) rollback transaction
106
-  (0.1ms) begin transaction
107
- ---------------------------
108
- OodAppkitTest: test_shell_urls
109
- ---------------------------
110
-  (0.1ms) rollback transaction
111
-  (0.0ms) begin transaction
112
- ----------------------
113
- OodAppkitTest: test_truth
114
- ----------------------
115
-  (0.0ms) rollback transaction
116
-  (1.9ms) begin transaction
117
- ------------------------------------------------
118
- OodAppkit::WikiControllerTest: test_should_get_show
119
- ------------------------------------------------
120
-  (0.1ms) rollback transaction
121
-  (0.1ms) begin transaction
122
- ---------------------------
123
- OodAppkitTest: test_files_urls
124
- ---------------------------
125
-  (0.1ms) rollback transaction
126
-  (0.0ms) begin transaction
127
- ---------------------------
128
- OodAppkitTest: test_shell_urls
129
- ---------------------------
130
-  (0.1ms) rollback transaction
131
-  (0.0ms) begin transaction
132
- ----------------------
133
- OodAppkitTest: test_truth
134
- ----------------------
135
-  (0.1ms) rollback transaction
136
-  (2.5ms) begin transaction
137
- ------------------------------------------------
138
- OodAppkit::WikiControllerTest: test_should_get_show
139
- ------------------------------------------------
140
-  (0.1ms) rollback transaction
141
-  (0.1ms) begin transaction
142
- ---------------------------
143
- OodAppkitTest: test_files_urls
144
- ---------------------------
145
-  (0.1ms) rollback transaction
146
-  (0.0ms) begin transaction
147
- ---------------------------
148
- OodAppkitTest: test_shell_urls
149
- ---------------------------
150
-  (0.1ms) rollback transaction
151
-  (0.0ms) begin transaction
152
- ----------------------
153
- OodAppkitTest: test_truth
154
- ----------------------
155
-  (0.1ms) rollback transaction
156
-  (1.9ms) begin transaction
157
- ------------------------------------------------
158
- OodAppkit::WikiControllerTest: test_should_get_show
159
- ------------------------------------------------
160
-  (0.1ms) rollback transaction
161
-  (0.1ms) begin transaction
162
- ---------------------------
163
- OodAppkitTest: test_files_urls
164
- ---------------------------
165
-  (0.1ms) rollback transaction
166
-  (0.1ms) begin transaction
167
- ---------------------------
168
- OodAppkitTest: test_shell_urls
169
- ---------------------------
170
-  (0.1ms) rollback transaction
171
-  (0.0ms) begin transaction
172
- ----------------------
173
- OodAppkitTest: test_truth
174
- ----------------------
175
-  (0.1ms) rollback transaction
176
-  (2.7ms) begin transaction
177
- ------------------------------------------------
178
- OodAppkit::WikiControllerTest: test_should_get_show
179
- ------------------------------------------------
180
-  (0.1ms) rollback transaction
181
-  (0.1ms) begin transaction
182
- ---------------------------
183
- OodAppkitTest: test_files_urls
184
- ---------------------------
185
-  (0.1ms) rollback transaction
186
-  (0.0ms) begin transaction
187
- ---------------------------
188
- OodAppkitTest: test_shell_urls
189
- ---------------------------
190
-  (0.1ms) rollback transaction
191
-  (0.1ms) begin transaction
192
- ----------------------
193
- OodAppkitTest: test_truth
194
- ----------------------
195
-  (0.1ms) rollback transaction
196
-  (4.1ms) begin transaction
197
- ------------------------------------------------
198
- OodAppkit::WikiControllerTest: test_should_get_show
199
- ------------------------------------------------
200
-  (0.1ms) rollback transaction
201
-  (0.1ms) begin transaction
202
- ---------------------------
203
- OodAppkitTest: test_files_urls
204
- ---------------------------
205
-  (0.1ms) rollback transaction
206
-  (0.1ms) begin transaction
207
- ---------------------------
208
- OodAppkitTest: test_shell_urls
209
- ---------------------------
210
-  (0.1ms) rollback transaction
211
-  (0.1ms) begin transaction
212
- ----------------------
213
- OodAppkitTest: test_truth
214
- ----------------------
215
-  (0.0ms) rollback transaction
216
-  (2.4ms) begin transaction
217
- ------------------------------------------------
218
- OodAppkit::WikiControllerTest: test_should_get_show
219
- ------------------------------------------------
220
-  (0.1ms) rollback transaction
221
-  (0.1ms) begin transaction
222
- ---------------------------
223
- OodAppkitTest: test_files_urls
224
- ---------------------------
225
-  (0.1ms) rollback transaction
226
-  (0.1ms) begin transaction
227
- ---------------------------
228
- OodAppkitTest: test_shell_urls
229
- ---------------------------
230
-  (0.1ms) rollback transaction
231
-  (0.0ms) begin transaction
232
- ----------------------
233
- OodAppkitTest: test_truth
234
- ----------------------
235
-  (0.0ms) rollback transaction
236
-  (2.5ms) begin transaction
237
- ------------------------------------------------
238
- OodAppkit::WikiControllerTest: test_should_get_show
239
- ------------------------------------------------
240
-  (0.1ms) rollback transaction
241
-  (0.1ms) begin transaction
242
- ---------------------------
243
- OodAppkitTest: test_files_urls
244
- ---------------------------
245
-  (0.1ms) rollback transaction
246
-  (0.1ms) begin transaction
247
- ---------------------------
248
- OodAppkitTest: test_shell_urls
249
- ---------------------------
250
-  (0.1ms) rollback transaction
251
-  (0.0ms) begin transaction
252
- ----------------------
253
- OodAppkitTest: test_truth
254
- ----------------------
255
-  (0.1ms) rollback transaction
256
-  (2.5ms) begin transaction
257
- ---------------------------
258
- OodAppkitTest: test_files_urls
259
- ---------------------------
260
-  (0.1ms) rollback transaction
261
-  (0.1ms) begin transaction
262
- ---------------------------
263
- OodAppkitTest: test_shell_urls
264
- ---------------------------
265
-  (0.1ms) rollback transaction
266
-  (0.1ms) begin transaction
267
- ----------------------
268
- OodAppkitTest: test_truth
269
- ----------------------
270
-  (0.0ms) rollback transaction
271
-  (30.5ms) begin transaction
272
- ------------------------------
273
- OodAppkitTest: test_files_urls
274
- ------------------------------
275
-  (0.1ms) rollback transaction
276
-  (0.1ms) begin transaction
277
- ------------------------------
278
- OodAppkitTest: test_shell_urls
279
- ------------------------------
280
-  (0.1ms) rollback transaction
281
-  (0.0ms) begin transaction
282
- -------------------------
283
- OodAppkitTest: test_truth
284
- -------------------------
285
-  (0.0ms) rollback transaction