has_active_logger 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.
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Droidlabs
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,29 @@
1
+ # DroidServices
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'has_active_logger'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install has_active_logger
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,5 @@
1
+ require "has_active_logger/version"
2
+ require "has_active_logger/mixin.rb"
3
+
4
+ module HasActiveLogger
5
+ end
@@ -0,0 +1,60 @@
1
+ require 'yell'
2
+ require 'active_support'
3
+ require 'active_support/core_ext/kernel/reporting'
4
+ require 'active_support/inflector'
5
+ require 'json'
6
+
7
+ module HasActiveLogger
8
+ module Mixin
9
+ extend ActiveSupport::Concern
10
+
11
+ silence_warnings do
12
+ Yell::Formatter::PatternRegexp = /([^%]*)(%\d*)?(#{Yell::Formatter::PatternTable.keys.join('|')})?(.*)/m
13
+ end
14
+
15
+ included do
16
+ class << self
17
+ def logger
18
+ @logger ||= Yell.new do |l|
19
+ l.adapter :datefile, log_file,
20
+ level: (:debug..:fatal),
21
+ format: Yell.format( "%d [%5L] #%M at %F:%n\n%m\n\n", "%H:%M:%S" ),
22
+ date_pattern: "%Y-week-%V",
23
+ symlink_original_filename: true,
24
+ keep: 4
25
+ end
26
+ end
27
+
28
+ def format_message(message)
29
+ case message
30
+ when String
31
+ message
32
+ when Hash, Array
33
+ JSON::pretty_generate message
34
+ else message.inspect
35
+ end
36
+ end
37
+
38
+ private
39
+ def log_file
40
+ path = File.join(rails_log_path, "#{self.name.underscore}.log")
41
+ FileUtils.mkdir_p File.dirname(path)
42
+ path.to_s
43
+ end
44
+
45
+ def rails_log_path
46
+ File.join(Rails.root, 'log', Rails.env)
47
+ end
48
+ end
49
+
50
+ def logger
51
+ self.class.logger
52
+ end
53
+
54
+ def format_message(message)
55
+ self.class.format_message(message)
56
+ end
57
+ end
58
+
59
+ end
60
+ end
@@ -0,0 +1,3 @@
1
+ module HasActiveLogger
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+
3
+ module HasActiveLogger
4
+ describe HasActiveLogger::Mixin do
5
+ include HasActiveLogger::Mixin
6
+
7
+ before { self.class.stub!(:rails_log_path).and_return('./log') }
8
+
9
+ describe '#logger' do
10
+ it { logger.should be_kind_of(Yell::Logger) }
11
+ end
12
+
13
+ describe '#format_message' do
14
+ context 'when String' do
15
+ let(:message) { 'Some test' }
16
+ it { format_message(message).should be_kind_of(String) }
17
+ it { format_message(message).should eq('Some test')}
18
+ end
19
+
20
+ context 'when Hash' do
21
+ let(:message) { {'dog' => 'canine', 'cat' => 'feline', 12 => 'number', user: {nick: 'Guru', 'name' => 'User'}} }
22
+ it { format_message(message).should be_kind_of(String) }
23
+ it { format_message(message).should eq("{\n \"dog\": \"canine\",\n \"cat\": \"feline\",\n \"12\": \"number\",\n \"user\": {\n \"nick\": \"Guru\",\n \"name\": \"User\"\n }\n}") }
24
+ end
25
+
26
+ context 'when Array' do
27
+ let(:message) { ['dog', 'cat', 'number'] }
28
+ it { format_message(message).should be_kind_of(String) }
29
+ it { format_message(message).should eq("[\n \"dog\",\n \"cat\",\n \"number\"\n]") }
30
+ end
31
+
32
+ context 'when some object' do
33
+ let(:message) { mock }
34
+ it 'should inspect object' do
35
+ message.should_receive(:inspect)
36
+ format_message(message)
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,6 @@
1
+ if ENV['COVERAGE']
2
+ require 'simplecov'
3
+ SimpleCov.start
4
+ end
5
+
6
+ require 'has_active_logger'
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: has_active_logger
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Droidlabs
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-05-05 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: yell
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: json
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: activesupport
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rspec
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ description: HasActiveLogger
79
+ email:
80
+ executables: []
81
+ extensions: []
82
+ extra_rdoc_files: []
83
+ files:
84
+ - lib/has_active_logger/mixin.rb
85
+ - lib/has_active_logger/version.rb
86
+ - lib/has_active_logger.rb
87
+ - LICENSE.txt
88
+ - Rakefile
89
+ - README.md
90
+ - spec/has_active_logger/mixin_spec.rb
91
+ - spec/spec_helper.rb
92
+ homepage:
93
+ licenses:
94
+ - MIT
95
+ post_install_message:
96
+ rdoc_options: []
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ none: false
101
+ requirements:
102
+ - - ! '>='
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ! '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ requirements: []
112
+ rubyforge_project:
113
+ rubygems_version: 1.8.25
114
+ signing_key:
115
+ specification_version: 3
116
+ summary: HasActiveLogger
117
+ test_files:
118
+ - spec/has_active_logger/mixin_spec.rb
119
+ - spec/spec_helper.rb