rumbrl 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d5ed542d2cf2c1f5c60ace389fc31b6a1193f3b4
4
+ data.tar.gz: 56739345db59ef3d3f9099da0b5a1690a6f24a4f
5
+ SHA512:
6
+ metadata.gz: 9f8e21cfb001c4b183cffc44037fc65958b0cdb350bac281c18524b86ad6029c4da9caf18ed79953b5da88a60bf2917c3091fe2ae4addc8be25ecf0f25730199
7
+ data.tar.gz: 83593613546ba256221a364cb5dece3c7605eca8b0e1b17a4b676933a3a91dfb5ef03debd6fc5c94de6ed5fd424ff5f695f415b2d093bbf5425c12de97c9e1fc
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ .vendor
2
+ vendor
3
+ .ruby-version
data/.singularityrc ADDED
@@ -0,0 +1,3 @@
1
+ shelltask { command 'bundle' }
2
+ rubocop
3
+ rspec
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ # encoding: utf-8
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in rumbrl.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,63 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ rumbrl (0.0.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ activesupport (4.1.8)
10
+ i18n (~> 0.6, >= 0.6.9)
11
+ json (~> 1.7, >= 1.7.7)
12
+ minitest (~> 5.1)
13
+ thread_safe (~> 0.1)
14
+ tzinfo (~> 1.1)
15
+ ast (2.0.0)
16
+ astrolabe (1.3.0)
17
+ parser (>= 2.2.0.pre.3, < 3.0)
18
+ diff-lcs (1.2.5)
19
+ gem-release (0.7.3)
20
+ i18n (0.6.11)
21
+ json (1.8.1)
22
+ minitest (5.5.0)
23
+ parser (2.2.0.pre.8)
24
+ ast (>= 1.1, < 3.0)
25
+ slop (~> 3.4, >= 3.4.5)
26
+ powerpack (0.0.9)
27
+ rainbow (2.0.0)
28
+ rspec (3.1.0)
29
+ rspec-core (~> 3.1.0)
30
+ rspec-expectations (~> 3.1.0)
31
+ rspec-mocks (~> 3.1.0)
32
+ rspec-core (3.1.7)
33
+ rspec-support (~> 3.1.0)
34
+ rspec-expectations (3.1.2)
35
+ diff-lcs (>= 1.2.0, < 2.0)
36
+ rspec-support (~> 3.1.0)
37
+ rspec-mocks (3.1.3)
38
+ rspec-support (~> 3.1.0)
39
+ rspec-support (3.1.2)
40
+ rubocop (0.28.0)
41
+ astrolabe (~> 1.3)
42
+ parser (>= 2.2.0.pre.7, < 3.0)
43
+ powerpack (~> 0.0.6)
44
+ rainbow (>= 1.99.1, < 3.0)
45
+ ruby-progressbar (~> 1.4)
46
+ ruby-progressbar (1.7.0)
47
+ shoulda-matchers (2.7.0)
48
+ activesupport (>= 3.0.0)
49
+ slop (3.6.0)
50
+ thread_safe (0.3.4)
51
+ tzinfo (1.2.2)
52
+ thread_safe (~> 0.1)
53
+
54
+ PLATFORMS
55
+ ruby
56
+
57
+ DEPENDENCIES
58
+ bundler (~> 1.3)
59
+ gem-release
60
+ rspec (~> 3.0)
61
+ rubocop (~> 0.24)
62
+ rumbrl!
63
+ shoulda-matchers (~> 2.7)
data/README.md ADDED
@@ -0,0 +1,44 @@
1
+ rumbrl
2
+ ======
3
+
4
+ **R**eally d**UMB** **R**uby **L**ogger
5
+
6
+ So dumb you'll cry.
7
+
8
+ ### API
9
+
10
+ Methods Delegated to `::Logger`:
11
+
12
+ - `datetime_format=`
13
+ - `log`
14
+ - `debug?`
15
+ - `error?`
16
+ - `fatal?`
17
+ - `info?`
18
+
19
+ Wrapped `::Logger` Methods:
20
+
21
+ - `debug`
22
+ - `info`
23
+ - `warn`
24
+ - `error`
25
+ - `fatal`
26
+ - `unknown`
27
+
28
+ ### ENV vars
29
+
30
+ #### `LOG_PATH`
31
+
32
+ Directory where logs go
33
+
34
+ #### `LOG_SHIFT_SIZE` & `LOG_SHIFT_AGE`
35
+
36
+ Passed into [::Logger](http://www.ruby-doc.org/stdlib-2.1.0/libdoc/logger/rdoc/Logger.html) (as `shift_age` & `shift_size`). Defaults to `1048576` & `weekly`, respectively.
37
+
38
+ #### `LOG_TIME_FORMAT`
39
+
40
+ Time format (`::Logger#datetime_format`). Defaults to `"[%F %T %z]"`
41
+
42
+ #### `LOG_DATA_FORMAT`
43
+
44
+ How to format log data. Defaults to `[%s] [%s]`
data/lib/rumbrl.rb ADDED
@@ -0,0 +1,5 @@
1
+ require 'rumbrl/version'
2
+
3
+ require 'rumbrl/env'
4
+ require 'rumbrl/factory'
5
+ require 'rumbrl/log'
data/lib/rumbrl/env.rb ADDED
@@ -0,0 +1,24 @@
1
+ module Rumbrl
2
+ # insanely dumb env for an insanely dumb log
3
+ class Env
4
+ def self.log_path
5
+ ENV.fetch('LOG_PATH', ::Dir.getwd)
6
+ end
7
+
8
+ def self.shift_size
9
+ ENV.fetch('LOG_SHIFT_SIZE', '1048576').to_i
10
+ end
11
+
12
+ def self.shift_age
13
+ ENV.fetch('LOG_SHIFT_AGE', 'weekly')
14
+ end
15
+
16
+ def self.time_format
17
+ ENV.fetch('LOG_TIME_FORMAT', '[%F %T %z]')
18
+ end
19
+
20
+ def self.log_format
21
+ ENV.fetch('LOG_DATA_FORMAT', '[%s] [%s]')
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,50 @@
1
+ require 'logger'
2
+ require 'rumbrl/env'
3
+
4
+ module Rumbrl
5
+ # an insanely dumb logger creator
6
+ # broken regulations & underaged workers abound
7
+ class Factory
8
+ attr_reader :dest, :name
9
+ attr_accessor :size, :age, :level, :log_format, :time_format
10
+
11
+ def self.create(nm, path: nil, age: nil, size: nil, level: nil)
12
+ new(nm, path: path, age: age, size: size, level: level).generate
13
+ end
14
+
15
+ def initialize(nm, path: nil, age: nil, size: nil, level: nil)
16
+ @name = nm
17
+ @log_format = Env.log_format
18
+ @time_format = Env.time_format
19
+ @size ||= (size || Env.shift_size)
20
+ @age ||= (age || Env.shift_age)
21
+ @level ||= (level || ::Logger::INFO)
22
+ @dest = log_dest path, nm
23
+ end
24
+
25
+ def generate
26
+ init_path dest
27
+ generate_logger
28
+ end
29
+
30
+ private
31
+
32
+ def generate_logger
33
+ logger = Log.new(dest, age, size, log_format)
34
+ logger.level = level
35
+ logger.datetime_format = time_format
36
+ logger
37
+ end
38
+
39
+ def log_dest(dir, name)
40
+ return name unless name.is_a? ::String
41
+ dir ||= Env.log_path
42
+ ::File.join dir, name
43
+ end
44
+
45
+ def init_path(path)
46
+ dir = ::File.dirname path
47
+ ::Dir.mkdir(dir) unless ::File.directory? dir
48
+ end
49
+ end
50
+ end
data/lib/rumbrl/log.rb ADDED
@@ -0,0 +1,49 @@
1
+ require 'forwardable'
2
+ require 'logger'
3
+
4
+ module Rumbrl
5
+ # an insanely dumb file log
6
+ class Log
7
+ extend Forwardable
8
+
9
+ ALLOWED_METHODS = [:debug, :info, :warn, :error, :fatal, :unknown]
10
+
11
+ attr_reader :logger, :data_format
12
+
13
+ def_delegators :logger,
14
+ :datetime_format=,
15
+ :level=,
16
+ :log,
17
+ :debug?,
18
+ :error?,
19
+ :fatal?,
20
+ :info?
21
+
22
+ def initialize(path, age, size, data_format)
23
+ @logger = ::Logger.new(log_file(path), shift_age: age, shift_size: size)
24
+ @data_format = data_format
25
+ end
26
+
27
+ def method_missing(name, *args)
28
+ name = name.to_sym
29
+ return super(name, *args) unless ALLOWED_METHODS.member? name
30
+ fail 'requires a message and data' unless args.size == 2
31
+ write(args[0], data: args[1], level: name)
32
+ end
33
+
34
+ private
35
+
36
+ def log_file(path)
37
+ # TODO: make this...less hacky
38
+ ::File.open(path, File::WRONLY | File::APPEND | File::CREAT)
39
+ end
40
+
41
+ def write(message, level: :info, data: {})
42
+ @logger.method(level).call { format_message message, data }
43
+ end
44
+
45
+ def format_message(message, data)
46
+ sprintf @data_format, message, data
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,6 @@
1
+ # encoding: utf-8
2
+
3
+ # version const for gem
4
+ module Rumbrl
5
+ VERSION = '0.0.1'
6
+ end
data/rumbrl.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rumbrl/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'rumbrl'
8
+ spec.version = Rumbrl::VERSION
9
+ spec.authors = ['chr0n1x']
10
+ spec.email = ['heilong24@gmail.com']
11
+ spec.description = 'Really_dUMB_Ruby_Logger'
12
+ spec.summary = ''
13
+ spec.homepage = ''
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
17
+ spec.executables = spec.files.grep(/^bin\//) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(/^(test|spec|features)\//)
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_development_dependency 'rubocop', '~> 0.24'
22
+ spec.add_development_dependency 'shoulda-matchers', '~> 2.7'
23
+ spec.add_development_dependency 'rspec', '~> 3.0'
24
+ spec.add_development_dependency 'bundler', '~> 1.3'
25
+ spec.add_development_dependency 'gem-release'
26
+ end
@@ -0,0 +1,78 @@
1
+ require_relative '../spec_helper'
2
+
3
+ describe Rumbrl::Factory do
4
+ describe '.create' do
5
+ it 'is just a dumb wrapper for .new and #generate' do
6
+ instance = double
7
+ expect(Rumbrl::Factory).to receive(:new)
8
+ .with('foo', path: nil, age: nil, size: nil, level: nil)
9
+ .and_return(instance)
10
+ expect(instance).to receive(:generate)
11
+
12
+ Rumbrl::Factory.create 'foo'
13
+ end
14
+ end
15
+
16
+ describe '#initialize' do
17
+ it 'sets proper default values' do
18
+ expect(Rumbrl::Env).to receive(:log_format).and_return(nil)
19
+ expect(Rumbrl::Env).to receive(:time_format).and_return(nil)
20
+ expect(Rumbrl::Env).to receive(:shift_size).and_return(nil)
21
+ expect(Rumbrl::Env).to receive(:shift_age).and_return(nil)
22
+
23
+ factory = Rumbrl::Factory.new 'foo'
24
+
25
+ expect(factory.name).to eql 'foo'
26
+ expect(factory.log_format).to eql nil
27
+ expect(factory.time_format).to eql nil
28
+ expect(factory.size).to eql nil
29
+ expect(factory.age).to eql nil
30
+ expect(factory.level).to eql ::Logger::INFO
31
+ expect(factory.dest).to eql ::File.join(::Dir.getwd, 'foo')
32
+ end
33
+
34
+ it 'respects user-defined log overrides' do
35
+ expect(Rumbrl::Env).to_not receive(:shift_size)
36
+ expect(Rumbrl::Env).to_not receive(:shift_age)
37
+
38
+ factory = Rumbrl::Factory.new 'foo',
39
+ path: 'some/path',
40
+ age: 5,
41
+ size: 2,
42
+ level: ::Logger::DEBUG
43
+ factory.time_format = 'WOO'
44
+ factory.log_format = 'BLAH'
45
+
46
+ expect(factory.name).to eql 'foo'
47
+ expect(factory.log_format).to eql 'BLAH'
48
+ expect(factory.time_format).to eql 'WOO'
49
+ expect(factory.size).to eql 2
50
+ expect(factory.age).to eql 5
51
+ expect(factory.level).to eql ::Logger::DEBUG
52
+ expect(factory.dest).to eql ::File.join('some/path', 'foo')
53
+ end
54
+
55
+ it 'respects non-file log paths' do
56
+ factory = Rumbrl::Factory.new STDOUT, path: 'wont/work'
57
+
58
+ expect(factory.dest).to eql STDOUT
59
+ end
60
+ end
61
+
62
+ describe '#generate' do
63
+ it 'creates the log path if it does not exist' do
64
+ path = 'this/should/not/exist'
65
+ expect(::Dir).to receive(:mkdir).with(path)
66
+ allow(::File).to receive(:directory?)
67
+ .with(path)
68
+ .and_return(false)
69
+
70
+ log_double = double
71
+ expect(Rumbrl::Log).to receive(:new).and_return(log_double)
72
+ expect(log_double).to receive(:level=)
73
+ expect(log_double).to receive(:datetime_format=)
74
+
75
+ Rumbrl::Factory.create 'foo.log', path: path
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,47 @@
1
+ require_relative '../spec_helper'
2
+
3
+ describe Rumbrl::Log do
4
+ let(:log) { Rumbrl::Log.new 'path/to/log', 'weekly', 123, '%s %s' }
5
+ let!(:logger_double) { double }
6
+
7
+ before(:each) do
8
+ allow(logger_double).to receive(:level=)
9
+ allow(logger_double).to receive(:datetime_format=)
10
+ allow(::Logger).to receive(:new).and_return logger_double
11
+ # TODO: make this...less hacky
12
+ allow(::File).to receive(:open).and_return(STDOUT)
13
+ end
14
+
15
+ describe 'delegates' do
16
+ it { expect(log).to delegate_method(:log).to(:logger) }
17
+ it { expect(log).to delegate_method(:debug?).to(:logger) }
18
+ it { expect(log).to delegate_method(:error?).to(:logger) }
19
+ it { expect(log).to delegate_method(:fatal?).to(:logger) }
20
+ it { expect(log).to delegate_method(:info?).to(:logger) }
21
+ it do
22
+ expect(log).to delegate_method(:datetime_format=)
23
+ .with_arguments('').to(:logger)
24
+ end
25
+ end
26
+
27
+ describe '#method_missing' do
28
+ context 'unknown method is called' do
29
+ it 'fails on unknown method call' do
30
+ expect { log.this_is_a_missing_method 'sadtimes log' }
31
+ .to raise_error(NoMethodError)
32
+ end
33
+ end
34
+
35
+ context 'method is known' do
36
+ it 'fails when less than 2 args given' do
37
+ expect { log.debug('boo') }
38
+ .to raise_error(RuntimeError, /message and data/)
39
+ end
40
+
41
+ it 'does things woo' do
42
+ expect(logger_double).to receive(:info)
43
+ log.info('message', ['data'])
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,2 @@
1
+ require 'rumbrl'
2
+ require 'shoulda/matchers'
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rumbrl
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - chr0n1x
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rubocop
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '0.24'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '0.24'
27
+ - !ruby/object:Gem::Dependency
28
+ name: shoulda-matchers
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '2.7'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '2.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '1.3'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '1.3'
69
+ - !ruby/object:Gem::Dependency
70
+ name: gem-release
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Really_dUMB_Ruby_Logger
84
+ email:
85
+ - heilong24@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - .gitignore
91
+ - .ruby-version
92
+ - .singularityrc
93
+ - Gemfile
94
+ - Gemfile.lock
95
+ - README.md
96
+ - lib/rumbrl.rb
97
+ - lib/rumbrl/env.rb
98
+ - lib/rumbrl/factory.rb
99
+ - lib/rumbrl/log.rb
100
+ - lib/rumbrl/version.rb
101
+ - rumbrl.gemspec
102
+ - spec/rumbrl/factory_spec.rb
103
+ - spec/rumbrl/log_spec.rb
104
+ - spec/spec_helper.rb
105
+ homepage: ''
106
+ licenses:
107
+ - MIT
108
+ metadata: {}
109
+ post_install_message:
110
+ rdoc_options: []
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - '>='
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ requirements: []
124
+ rubyforge_project:
125
+ rubygems_version: 2.4.5
126
+ signing_key:
127
+ specification_version: 4
128
+ summary: ''
129
+ test_files:
130
+ - spec/rumbrl/factory_spec.rb
131
+ - spec/rumbrl/log_spec.rb
132
+ - spec/spec_helper.rb