skylight 0.1.6 → 0.1.7.alpha1

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: 41a4af63fb1c46db8c3937d7d9db2dc65a541195
4
- data.tar.gz: 82649e3004eb5e499201a92a9bc1066286b2e9f7
3
+ metadata.gz: db1b0ac1268ea2ee9d131e07bd233d1865f5ff7b
4
+ data.tar.gz: b42da292696538f036387909cdb44331ca32494a
5
5
  SHA512:
6
- metadata.gz: cc2c68a79fab693e19130c5668cbf22abecf02bb7cd0096b46b1e4393aa2548ee414e412eb8361348b63f2a983eb3dd45b2b9aadf6efd56f5315e4aaa57fcf31
7
- data.tar.gz: 54d50ade36a0bd2c1687e22f4add7b86d970eeaf65df1dfad9a6e235b234f40411513be4f7b71b6cffb980c46cfe751d2033cefbb9ce2a70826f28366442c449
6
+ metadata.gz: 2c59dceb8da40478a4e7a6ccb1b7d069268449ffbfe8aa61634f50e15296951f103ae3d5aa4cffce2eded0f4a7714c0ac9019f8ae75493487bfb5040fa6dab96
7
+ data.tar.gz: bd2f355e06b37128932b2ed61a03ee7340caaec31c2531cf293c65276832444962be7464f88daf91154a52e61684b12a36cfce040a0f01380b4cd3ebcf28074c
@@ -1,5 +1,7 @@
1
1
  ## unreleased ##
2
2
 
3
+ * Add the ability to configure logging from railtie
4
+
3
5
  ## 0.1.6 (June 11, 2013)
4
6
 
5
7
  * [BUG] Fix unix domain socket write function in standalone agent
@@ -1,13 +1,16 @@
1
1
  require 'yaml'
2
2
  require 'fileutils'
3
3
  require 'logger'
4
+ require 'thread'
4
5
 
5
6
  module Skylight
6
7
  class Config
8
+ MUTEX = Mutex.new
7
9
 
8
10
  # Map environment variable keys with Skylight configuration keys
9
11
  ENV_TO_KEY = {
10
- 'SK_LOG' => :'log',
12
+ 'SK_ROOT' => :'root',
13
+ 'SK_LOG_FILE' => :'log_file',
11
14
  'SK_LOG_LEVEL' => :'log_level',
12
15
  'SK_APPLICATION' => :'application',
13
16
  'SK_AUTHENTICATION' => :'authentication',
@@ -29,7 +32,7 @@ module Skylight
29
32
 
30
33
  # Default values for Skylight configuration keys
31
34
  DEFAULTS = {
32
- :'log' => '-'.freeze,
35
+ :'log_file' => '-'.freeze,
33
36
  :'log_level' => 'INFO'.freeze,
34
37
  :'agent.keepalive' => 60,
35
38
  :'agent.interval' => 5,
@@ -138,6 +141,11 @@ module Skylight
138
141
  true
139
142
  end
140
143
 
144
+ def key?(key)
145
+ key = key.to_sym
146
+ @priority.key?(key) || @values.key?(key)
147
+ end
148
+
141
149
  def get(key, default = nil, &blk)
142
150
  key = key.to_sym
143
151
 
@@ -231,25 +239,35 @@ authentication: #{self[:authentication]}
231
239
  @gc ||= GC.new(self, get('gc.profiler', VM::GC.new))
232
240
  end
233
241
 
242
+ def root
243
+ self[:root] || Dir.pwd
244
+ end
245
+
234
246
  def logger
235
247
  @logger ||=
236
248
  begin
237
- out = get(:'log')
238
- out = STDOUT if out == '-'
249
+ MUTEX.synchronize do
250
+ unless l = @logger
251
+ out = get(:'log_file')
252
+ out = STDOUT if out == '-'
253
+
254
+ unless IO === out
255
+ out = File.expand_path(out, root)
256
+ FileUtils.mkdir_p(File.dirname(out))
257
+ end
258
+
259
+ l = Logger.new(out)
260
+ l.level =
261
+ case get(:'log_level')
262
+ when /^debug$/i then Logger::DEBUG
263
+ when /^info$/i then Logger::INFO
264
+ when /^warn$/i then Logger::WARN
265
+ when /^error$/i then Logger::ERROR
266
+ end
267
+ end
239
268
 
240
- unless IO === out
241
- FileUtils.mkdir_p(File.dirname(out))
269
+ l
242
270
  end
243
-
244
- l = Logger.new(out)
245
- l.level =
246
- case get(:'log_level')
247
- when /^debug$/i then Logger::DEBUG
248
- when /^info$/i then Logger::INFO
249
- when /^warn$/i then Logger::WARN
250
- when /^error$/i then Logger::ERROR
251
- end
252
- l
253
271
  end
254
272
  end
255
273
 
@@ -34,7 +34,10 @@ module Skylight
34
34
  end
35
35
 
36
36
  config = Config.load(path, Rails.env.to_s, ENV)
37
- config.logger = Rails.logger
37
+ config['root'] = Rails.root
38
+
39
+ configure_logging(config, app)
40
+
38
41
  config['agent.sockfile_path'] = tmp
39
42
  config['normalizers.render.view_paths'] = app.config.paths["app/views"].existent
40
43
  config.validate!
@@ -45,6 +48,28 @@ module Skylight
45
48
  nil
46
49
  end
47
50
 
51
+ def configure_logging(config, app)
52
+ if logger = app.config.skylight.logger
53
+ config.logger = logger
54
+ else
55
+ # Configure the log file destination
56
+ if log_file = app.config.skylight.log_file
57
+ config['log_file'] = log_file
58
+ elsif !config.key?('log_file')
59
+ config['log_file'] = File.join(Rails.root, 'log/skylight.log')
60
+ end
61
+
62
+ # Configure the log level
63
+ if level = app.config.skylight.log_level
64
+ config['log_level'] = level
65
+ elsif !config.key?('log_level')
66
+ if level = app.config.log_level
67
+ config['log_level'] = level
68
+ end
69
+ end
70
+ end
71
+ end
72
+
48
73
  def config_path(app)
49
74
  File.expand_path(config.skylight.config_path, app.root)
50
75
  end
@@ -1,4 +1,4 @@
1
1
  module Skylight
2
- VERSION = '0.1.6'
2
+ VERSION = '0.1.7.alpha1'
3
3
  end
4
4
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: skylight
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7.alpha1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tilde, Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-06-11 00:00:00.000000000 Z
11
+ date: 2013-06-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -143,9 +143,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
143
143
  version: 1.9.2
144
144
  required_rubygems_version: !ruby/object:Gem::Requirement
145
145
  requirements:
146
- - - '>='
146
+ - - '>'
147
147
  - !ruby/object:Gem::Version
148
- version: '0'
148
+ version: 1.3.1
149
149
  requirements: []
150
150
  rubyforge_project:
151
151
  rubygems_version: 2.0.3