quandl_logger 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +3 -1
- data/README.md +25 -1
- data/UPGRADE.md +7 -1
- data/development.log +1 -0
- data/examples/graylog.rb +19 -0
- data/examples/logger.rb +8 -0
- data/lib/quandl/configuration.rb +75 -0
- data/lib/quandl/logger/graylog2.rb +38 -0
- data/lib/quandl/logger/version.rb +1 -1
- data/lib/quandl/logger.rb +14 -4
- data/quandl_logger.gemspec +3 -0
- data/spec/fixtures/config/graylog2.yml +4 -0
- data/spec/lib/quandl/logger/graylog2_spec.rb +48 -0
- data/spec/lib/quandl/logger_spec.rb +22 -0
- data/spec/spec_helper.rb +21 -0
- metadata +61 -18
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2daf464eccd4bab4435ee8e3413249830f10e609
|
4
|
+
data.tar.gz: 5b23255401743582835db28440282f8cfd3e1d13
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 504be25a3329ddf185f1372e50eca7b20430dbca7e04bafcbe50a60a614f9aebe8cecc0f431cdc3074fddd081e99957284d03a602f01287abcd35b2c0ceef83a
|
7
|
+
data.tar.gz: 249e179dc509c4c3916ebb80faa04074218168de6d7983b1a8e365baea4557664bd131bfdcb4797706fc7bda4756bcb91ac1c9eb4133db27cf31eeb6f74631b6
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -1 +1,25 @@
|
|
1
|
-
|
1
|
+
# Installation
|
2
|
+
|
3
|
+
```ruby
|
4
|
+
|
5
|
+
gem 'quandl_logger'
|
6
|
+
|
7
|
+
```
|
8
|
+
|
9
|
+
|
10
|
+
|
11
|
+
|
12
|
+
# Configuration
|
13
|
+
|
14
|
+
|
15
|
+
## Logger
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
|
19
|
+
require 'quandl/logger'
|
20
|
+
|
21
|
+
file = ::Logger.new('/path/to/development.log')
|
22
|
+
Quandl::Logger.use(file)
|
23
|
+
|
24
|
+
|
25
|
+
```
|
data/UPGRADE.md
CHANGED
data/development.log
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Logfile created on 2013-10-21 13:57:00 -0400 by logger.rb/36483
|
data/examples/graylog.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'quandl/logger'
|
2
|
+
|
3
|
+
# configure with block
|
4
|
+
# configures :host, :port, :max_size, :facility, :version, :level
|
5
|
+
Quandl::Logger::GrayLog2.configure do |c|
|
6
|
+
c.facility = 'quandl_logger:test'
|
7
|
+
end
|
8
|
+
|
9
|
+
# or configure from file
|
10
|
+
# Quandl::Logger::GrayLog2.configuration.from_file('config/graylog2.yml', 'development')
|
11
|
+
|
12
|
+
# use graylog2 class directly
|
13
|
+
Quandl::Logger::GrayLog2.info('hi')
|
14
|
+
|
15
|
+
# or replace quandl logger with GrayLog2
|
16
|
+
Quandl::Logger.use( Quandl::Logger::GrayLog2 )
|
17
|
+
|
18
|
+
# send your message
|
19
|
+
Quandl::Logger.info('hello')
|
data/examples/logger.rb
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
module Quandl
|
4
|
+
class Configuration
|
5
|
+
class << self
|
6
|
+
|
7
|
+
def configures(*names)
|
8
|
+
define_attributes(*names)
|
9
|
+
end
|
10
|
+
|
11
|
+
def define_attributes(*names)
|
12
|
+
Array(names).each{|name| define_attribute(name) }
|
13
|
+
end
|
14
|
+
|
15
|
+
def define_attribute(name)
|
16
|
+
name = name.to_sym
|
17
|
+
define_method(name) do
|
18
|
+
read_attribute(name)
|
19
|
+
end
|
20
|
+
define_method("#{name}=") do |value|
|
21
|
+
write_attribute(name, value)
|
22
|
+
end
|
23
|
+
define_method("#{name}?") do
|
24
|
+
read_attribute(name).present?
|
25
|
+
end
|
26
|
+
# store an array of defined attriubte names
|
27
|
+
attribute_names << name unless attribute_names.include?(name)
|
28
|
+
end
|
29
|
+
|
30
|
+
def attribute_names
|
31
|
+
@attribute_names ||= []
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
def from_file(path, env)
|
37
|
+
config = YAML.load_file( path )[ env ]
|
38
|
+
config.each{|k,v| self.send("#{k}=",v) if respond_to?("#{k}=") }
|
39
|
+
end
|
40
|
+
|
41
|
+
def initialize(*args)
|
42
|
+
attrs = args.extract_options!
|
43
|
+
self.attributes
|
44
|
+
# assign attributes
|
45
|
+
self.assign_attributes(attrs)
|
46
|
+
end
|
47
|
+
|
48
|
+
def assign_attributes(hash)
|
49
|
+
hash.each do |k,v|
|
50
|
+
send("#{k}=", v) if self.class.attribute_names.include?(k) && respond_to?("#{k}=")
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def inspect
|
55
|
+
"#{self.class.name} " + attributes.inspect
|
56
|
+
end
|
57
|
+
|
58
|
+
def attributes
|
59
|
+
@attributes ||= self.class.attribute_names.inject({}){|m,k| m[k] ||= nil; m }
|
60
|
+
end
|
61
|
+
|
62
|
+
def attributes=(value)
|
63
|
+
@attributes = value.symbolize_keys! if value.is_a?(Hash)
|
64
|
+
end
|
65
|
+
|
66
|
+
def write_attribute(attribute, value)
|
67
|
+
@attributes[:"#{attribute}"] = value
|
68
|
+
end
|
69
|
+
|
70
|
+
def read_attribute(attribute)
|
71
|
+
@attributes[:"#{attribute}"]
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'gelf'
|
2
|
+
require 'quandl/configuration'
|
3
|
+
|
4
|
+
class Quandl::Logger::GrayLog2
|
5
|
+
class << self
|
6
|
+
|
7
|
+
def method_missing(method_sym, *args, &block)
|
8
|
+
gelf.send(method_sym, *args)
|
9
|
+
end
|
10
|
+
|
11
|
+
def gelf
|
12
|
+
@gelf ||= GELF::Notifier.new( configuration.host, configuration.port, configuration.max_size, configuration.options )
|
13
|
+
end
|
14
|
+
|
15
|
+
def configure
|
16
|
+
yield(configuration)
|
17
|
+
end
|
18
|
+
|
19
|
+
def configuration
|
20
|
+
@configuration ||= Quandl::Logger::GrayLog2::Configuration.new({
|
21
|
+
host: 'metrics.quandl.com',
|
22
|
+
port: '12201',
|
23
|
+
max_size: 'WAN',
|
24
|
+
})
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
class Configuration < Quandl::Configuration
|
30
|
+
configures :host, :port, :max_size, :facility, :version, :level
|
31
|
+
|
32
|
+
def options
|
33
|
+
[:facility, :version, :level].inject({}){|m,k| m[k] = attributes[k] if attributes[k].present?; m }
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
data/lib/quandl/logger.rb
CHANGED
@@ -7,6 +7,8 @@ require "active_support/inflector"
|
|
7
7
|
require "active_support/core_ext/hash"
|
8
8
|
require "active_support/core_ext/object"
|
9
9
|
|
10
|
+
require 'quandl/logger/graylog2'
|
11
|
+
|
10
12
|
module Quandl
|
11
13
|
class Logger
|
12
14
|
class << self
|
@@ -21,6 +23,10 @@ module Quandl
|
|
21
23
|
@@logger if defined?(@@logger)
|
22
24
|
end
|
23
25
|
|
26
|
+
def use(value)
|
27
|
+
return use_file(value) if value.kind_of?( ::Logger ) || value.kind_of?(String)
|
28
|
+
end
|
29
|
+
|
24
30
|
def info_with_elapsed(message=nil, &block)
|
25
31
|
timer = Time.now
|
26
32
|
result = block.call
|
@@ -28,11 +34,15 @@ module Quandl
|
|
28
34
|
result
|
29
35
|
end
|
30
36
|
|
31
|
-
|
32
|
-
|
33
|
-
|
37
|
+
protected
|
38
|
+
|
39
|
+
def use_file(file)
|
40
|
+
# convert string to logger
|
41
|
+
file = ::Logger.new(file) if file.kind_of?(String)
|
42
|
+
# assign Logger
|
43
|
+
@@logger = file
|
34
44
|
end
|
35
|
-
|
45
|
+
|
36
46
|
end
|
37
47
|
|
38
48
|
end
|
data/quandl_logger.gemspec
CHANGED
@@ -19,8 +19,11 @@ Gem::Specification.new do |s|
|
|
19
19
|
|
20
20
|
s.add_development_dependency "rake", "~> 10.0"
|
21
21
|
s.add_development_dependency "rspec", "~> 2.13"
|
22
|
+
s.add_development_dependency "factory_girl_rails"
|
22
23
|
s.add_development_dependency "fivemat", "~> 1.2"
|
23
24
|
s.add_development_dependency "pry"
|
25
|
+
s.add_development_dependency "simplecov"
|
24
26
|
|
25
27
|
s.add_runtime_dependency "activesupport", ">= 3.0.0"
|
28
|
+
s.add_runtime_dependency "gelf", "~> 1.3.2"
|
26
29
|
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe Quandl::Logger::GrayLog2 do
|
5
|
+
let(:logger){ Quandl::Logger::GrayLog2 }
|
6
|
+
subject{ logger }
|
7
|
+
|
8
|
+
config_path = Pathname.new("spec/fixtures/config/graylog2.yml")
|
9
|
+
config_env = 'test'
|
10
|
+
config = YAML.load_file( config_path )[config_env]
|
11
|
+
|
12
|
+
[:debug, :info, :warn, :error, :fatal, :unknown].each do |level|
|
13
|
+
it ".#{level}('message')" do
|
14
|
+
subject.send(level, 'message')
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe ".configure" do
|
19
|
+
before(:each){
|
20
|
+
logger.configure do |c|
|
21
|
+
config.each do |key, value|
|
22
|
+
c.send("#{key}=", value)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
}
|
26
|
+
subject{ logger.configuration }
|
27
|
+
|
28
|
+
config.each do |key, value|
|
29
|
+
its(key){ should eq value }
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe ".configuration" do
|
34
|
+
subject{ logger.configuration }
|
35
|
+
|
36
|
+
describe "#from_file" do
|
37
|
+
|
38
|
+
before(:each){ logger.configuration.from_file( config_path, config_env) }
|
39
|
+
subject{ logger.configuration.attributes }
|
40
|
+
|
41
|
+
config.each do |key, value|
|
42
|
+
its([key.to_sym]){ should eq value }
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe Quandl::Logger do
|
5
|
+
|
6
|
+
describe "#use" do
|
7
|
+
|
8
|
+
subject{ Quandl::Logger }
|
9
|
+
|
10
|
+
context "given String" do
|
11
|
+
before(:each){ subject.use('development.log') }
|
12
|
+
its(:logger){ should be_a ::Logger }
|
13
|
+
end
|
14
|
+
|
15
|
+
context "given Logger" do
|
16
|
+
before(:each){ subject.use( ::Logger.new('development.log') ) }
|
17
|
+
its(:logger){ should be_a ::Logger }
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
if ENV['COVERAGE']
|
2
|
+
require 'simplecov'
|
3
|
+
SimpleCov.start
|
4
|
+
end
|
5
|
+
|
6
|
+
$:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
|
7
|
+
|
8
|
+
require "rspec"
|
9
|
+
require 'factory_girl'
|
10
|
+
require 'pry'
|
11
|
+
|
12
|
+
factory_dir = File.join( File.dirname(__FILE__), 'factories/**/*.rb' )
|
13
|
+
Dir.glob( factory_dir ).each{|f| require(f); puts f }
|
14
|
+
|
15
|
+
require "quandl/logger"
|
16
|
+
|
17
|
+
RSpec.configure do |config|
|
18
|
+
config.include FactoryGirl::Syntax::Methods
|
19
|
+
end
|
20
|
+
|
21
|
+
# binding.pry
|
metadata
CHANGED
@@ -1,20 +1,18 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: quandl_logger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.2.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Blake Hilscher
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-
|
11
|
+
date: 2013-11-14 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: rake
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
17
|
- - ~>
|
20
18
|
- !ruby/object:Gem::Version
|
@@ -22,7 +20,6 @@ dependencies:
|
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
24
|
- - ~>
|
28
25
|
- !ruby/object:Gem::Version
|
@@ -30,7 +27,6 @@ dependencies:
|
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: rspec
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
31
|
- - ~>
|
36
32
|
- !ruby/object:Gem::Version
|
@@ -38,15 +34,27 @@ dependencies:
|
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
38
|
- - ~>
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: '2.13'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: factory_girl_rails
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
46
55
|
- !ruby/object:Gem::Dependency
|
47
56
|
name: fivemat
|
48
57
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
58
|
requirements:
|
51
59
|
- - ~>
|
52
60
|
- !ruby/object:Gem::Version
|
@@ -54,7 +62,6 @@ dependencies:
|
|
54
62
|
type: :development
|
55
63
|
prerelease: false
|
56
64
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
65
|
requirements:
|
59
66
|
- - ~>
|
60
67
|
- !ruby/object:Gem::Version
|
@@ -62,7 +69,6 @@ dependencies:
|
|
62
69
|
- !ruby/object:Gem::Dependency
|
63
70
|
name: pry
|
64
71
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
72
|
requirements:
|
67
73
|
- - '>='
|
68
74
|
- !ruby/object:Gem::Version
|
@@ -70,7 +76,20 @@ dependencies:
|
|
70
76
|
type: :development
|
71
77
|
prerelease: false
|
72
78
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: simplecov
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
74
93
|
requirements:
|
75
94
|
- - '>='
|
76
95
|
- !ruby/object:Gem::Version
|
@@ -78,7 +97,6 @@ dependencies:
|
|
78
97
|
- !ruby/object:Gem::Dependency
|
79
98
|
name: activesupport
|
80
99
|
requirement: !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
82
100
|
requirements:
|
83
101
|
- - '>='
|
84
102
|
- !ruby/object:Gem::Version
|
@@ -86,11 +104,24 @@ dependencies:
|
|
86
104
|
type: :runtime
|
87
105
|
prerelease: false
|
88
106
|
version_requirements: !ruby/object:Gem::Requirement
|
89
|
-
none: false
|
90
107
|
requirements:
|
91
108
|
- - '>='
|
92
109
|
- !ruby/object:Gem::Version
|
93
110
|
version: 3.0.0
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: gelf
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ~>
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 1.3.2
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ~>
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 1.3.2
|
94
125
|
description: Quandl logger class for use in quandl gems.
|
95
126
|
email:
|
96
127
|
- blake@hilscher.ca
|
@@ -104,32 +135,44 @@ files:
|
|
104
135
|
- README.md
|
105
136
|
- Rakefile
|
106
137
|
- UPGRADE.md
|
138
|
+
- development.log
|
139
|
+
- examples/graylog.rb
|
140
|
+
- examples/logger.rb
|
141
|
+
- lib/quandl/configuration.rb
|
107
142
|
- lib/quandl/logger.rb
|
143
|
+
- lib/quandl/logger/graylog2.rb
|
108
144
|
- lib/quandl/logger/version.rb
|
109
145
|
- quandl_logger.gemspec
|
146
|
+
- spec/fixtures/config/graylog2.yml
|
147
|
+
- spec/lib/quandl/logger/graylog2_spec.rb
|
148
|
+
- spec/lib/quandl/logger_spec.rb
|
149
|
+
- spec/spec_helper.rb
|
110
150
|
homepage: http://blake.hilscher.ca/
|
111
151
|
licenses:
|
112
152
|
- MIT
|
153
|
+
metadata: {}
|
113
154
|
post_install_message:
|
114
155
|
rdoc_options: []
|
115
156
|
require_paths:
|
116
157
|
- lib
|
117
158
|
required_ruby_version: !ruby/object:Gem::Requirement
|
118
|
-
none: false
|
119
159
|
requirements:
|
120
160
|
- - '>='
|
121
161
|
- !ruby/object:Gem::Version
|
122
162
|
version: '0'
|
123
163
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
124
|
-
none: false
|
125
164
|
requirements:
|
126
165
|
- - '>='
|
127
166
|
- !ruby/object:Gem::Version
|
128
167
|
version: '0'
|
129
168
|
requirements: []
|
130
169
|
rubyforge_project:
|
131
|
-
rubygems_version: 1.
|
170
|
+
rubygems_version: 2.1.10
|
132
171
|
signing_key:
|
133
|
-
specification_version:
|
172
|
+
specification_version: 4
|
134
173
|
summary: Quandl logger class for use in quandl gems.
|
135
|
-
test_files:
|
174
|
+
test_files:
|
175
|
+
- spec/fixtures/config/graylog2.yml
|
176
|
+
- spec/lib/quandl/logger/graylog2_spec.rb
|
177
|
+
- spec/lib/quandl/logger_spec.rb
|
178
|
+
- spec/spec_helper.rb
|