rails-labeled_log 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +28 -0
- data/.rspec +2 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +2 -0
- data/LICENSE +22 -0
- data/README.md +94 -0
- data/Rakefile +2 -0
- data/lib/rails/labeled_log/levels.rb +5 -0
- data/lib/rails/labeled_log/logger.rb +29 -0
- data/lib/rails/labeled_log/logging.rb +41 -0
- data/lib/rails/labeled_log/version.rb +5 -0
- data/lib/rails-labeled-log.rb +1 -0
- data/lib/rails-labeled_log.rb +3 -0
- data/lib/rails_labeled-log.rb +1 -0
- data/lib/rails_labeled_log.rb +1 -0
- data/rails-labeled_log.gemspec +28 -0
- data/spec/rails/labeled_log/logger_spec.rb +23 -0
- data/spec/rails/labeled_log/logging_spec.rb +44 -0
- data/spec/spec_helper.rb +12 -0
- metadata +132 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ed22b778f0ef5fbc0010af12991a4c57bc1635b7
|
4
|
+
data.tar.gz: 859bd6d98f0e98b8573e09cdf820ea321a129f00
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b511c221332d1887f5542a7eb8dbd8721e8c3162a9d3dcde933687f02e710c70e40b9c143281f15886c6618038a0db7758aaaf2a8dfa90a5df640e86d610278a
|
7
|
+
data.tar.gz: 5d764e179e741966a7cfacf6df115a0ba70d7fe6fabb80ec3bb11e73e515e7136fd038f638adea88c187fbc459993f3b0d6589a8e9f064014d83de752dbeaa1a
|
data/.gitignore
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
TODO
|
19
|
+
|
20
|
+
# For MacOS:
|
21
|
+
.DS_Store
|
22
|
+
|
23
|
+
# For vim:
|
24
|
+
*.sw*
|
25
|
+
|
26
|
+
# RVM
|
27
|
+
.ruby-gemset
|
28
|
+
.ruby-version
|
data/.rspec
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
+
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
|
6
|
+
|
7
|
+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
+
|
9
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
+
|
11
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
+
|
13
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Fernando Hamasaki de Amorim
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
22
|
+
|
data/README.md
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
# Rails Labeled Log
|
2
|
+
A tool to use easily Rails Tagged Logging in your Ruby classes.
|
3
|
+
|
4
|
+
## Installing
|
5
|
+
|
6
|
+
### Gemfile
|
7
|
+
|
8
|
+
```ruby
|
9
|
+
gem 'rails-labeled_log'
|
10
|
+
```
|
11
|
+
|
12
|
+
### Direct installation
|
13
|
+
|
14
|
+
```console
|
15
|
+
$ gem install rails-labeled_log
|
16
|
+
```
|
17
|
+
|
18
|
+
|
19
|
+
## Using
|
20
|
+
|
21
|
+
### Rails::LabeledLog::Logging module
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
require 'rails-labeled_log'
|
25
|
+
|
26
|
+
# Include Rails::LabeledLog::Logging module in your class
|
27
|
+
module FakeModule
|
28
|
+
class FakeClass
|
29
|
+
include Rails::LabeledLog::Logging
|
30
|
+
|
31
|
+
def do_something
|
32
|
+
# Log some info here
|
33
|
+
log_info 'I did something'
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
fake = FakeModule::FakeClass.new
|
39
|
+
fake.do_something
|
40
|
+
|
41
|
+
# You also can use class methods
|
42
|
+
FakeModule::FakeClass.log_error 'Something was wrong'
|
43
|
+
```
|
44
|
+
|
45
|
+
Rails log will be labeled with the class name:
|
46
|
+
```
|
47
|
+
[FakeModule::FakeClass] I did something at 2015-09-21 00:33:17 -0300
|
48
|
+
[FakeModule::FakeClass] Something was wrong at 2015-09-21 00:33:18 -0300
|
49
|
+
```
|
50
|
+
|
51
|
+
##### Available (private) instance methods and class methods
|
52
|
+
- log_info
|
53
|
+
- log_error
|
54
|
+
- log_warn
|
55
|
+
- log_debug
|
56
|
+
- log_fatal
|
57
|
+
|
58
|
+
### Rails::LabeledLog::Logger class
|
59
|
+
|
60
|
+
```ruby
|
61
|
+
require 'rails-labeled_log'
|
62
|
+
|
63
|
+
logger = Rails::LabeledLog::Logger.new('One', 'Two')
|
64
|
+
logger.info 'My info message'
|
65
|
+
```
|
66
|
+
In the Rails Log:
|
67
|
+
```
|
68
|
+
[One] [Two] My info message at 2015-09-21 01:01:43 -0300
|
69
|
+
```
|
70
|
+
|
71
|
+
##### Available methods
|
72
|
+
- info
|
73
|
+
- error
|
74
|
+
- warn
|
75
|
+
- debug
|
76
|
+
- fatal
|
77
|
+
|
78
|
+
## Author
|
79
|
+
[Fernando Hamasaki de Amorim (prodis)](http://prodis.blog.br)
|
80
|
+
|
81
|
+
![Prodis Logo](http://prodis.net.br/images/prodis_150.gif)
|
82
|
+
|
83
|
+
|
84
|
+
## Contributing to Rails Labeled Log
|
85
|
+
|
86
|
+
- Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
87
|
+
- Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
88
|
+
- Fork the project.
|
89
|
+
- Start a feature/bugfix branch.
|
90
|
+
- Commit and push until you are happy with your contribution.
|
91
|
+
- Don't forget to rebase with branch master in main project before submit the pull request.
|
92
|
+
- Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
93
|
+
- Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
94
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
module Rails
|
2
|
+
module LabeledLog
|
3
|
+
class Logger
|
4
|
+
attr_reader :labels
|
5
|
+
|
6
|
+
def initialize(*labels)
|
7
|
+
@labels = labels
|
8
|
+
end
|
9
|
+
|
10
|
+
LabeledLog::LEVELS.each do |level|
|
11
|
+
define_method(level) do |message|
|
12
|
+
log(level, message)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def log(level, message)
|
19
|
+
Rails.logger.tagged(*labels) do
|
20
|
+
Rails.logger.send(level, format_message(message))
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def format_message(message)
|
25
|
+
"#{message} at #{Time.now}"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module Rails
|
2
|
+
module LabeledLog
|
3
|
+
module Logging
|
4
|
+
def self.included(base)
|
5
|
+
base.extend(ClassMethods)
|
6
|
+
base.send(:prepend, InstanceMethods)
|
7
|
+
end
|
8
|
+
|
9
|
+
module ClassMethods
|
10
|
+
Rails::LabeledLog::LEVELS.each do |level|
|
11
|
+
define_method("log_#{level}".to_sym) do |message|
|
12
|
+
log_labeled(level, message)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def log_labeled(level, message)
|
19
|
+
Rails::LabeledLog::Logger.new(self.name).send(level, message)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
module InstanceMethods
|
24
|
+
attr_reader :logger
|
25
|
+
|
26
|
+
def initialize(*args)
|
27
|
+
@logger = Rails::LabeledLog::Logger.new(self.class.name)
|
28
|
+
super
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
Rails::LabeledLog::LEVELS.each do |level|
|
34
|
+
define_method("log_#{level}".to_sym) do |message|
|
35
|
+
logger.send(level, message)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'rails-labeled_log'
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'rails-labeled_log'
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'rails-labeled_log'
|
@@ -0,0 +1,28 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'rails/labeled_log/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'rails-labeled_log'
|
7
|
+
spec.version = Rails::LabeledLog::VERSION
|
8
|
+
spec.author = 'Prodis a.k.a. Fernando Hamasaki de Amorim'
|
9
|
+
spec.email = 'prodis@gmail.com'
|
10
|
+
spec.summary = 'A tool to use easily Rails Tagged Logging in your Ruby classes.'
|
11
|
+
spec.description = spec.summary
|
12
|
+
spec.homepage = 'https://github.com/prodis/rails-labeled_log'
|
13
|
+
spec.license = 'MIT'
|
14
|
+
|
15
|
+
spec.files = `git ls-files`.split($/)
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.require_paths = ['lib']
|
18
|
+
|
19
|
+
spec.platform = Gem::Platform::RUBY
|
20
|
+
spec.required_ruby_version = '>= 2.0.0'
|
21
|
+
|
22
|
+
spec.add_runtime_dependency 'rails', '>= 3.2'
|
23
|
+
|
24
|
+
spec.add_development_dependency 'coveralls'
|
25
|
+
spec.add_development_dependency 'pry'
|
26
|
+
spec.add_development_dependency 'rake'
|
27
|
+
spec.add_development_dependency 'rspec'
|
28
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Rails::LabeledLog::Logger do
|
4
|
+
subject { described_class.new('Chefe', 'Pixel') }
|
5
|
+
|
6
|
+
before(:all) do
|
7
|
+
@log_stream = StringIO.new
|
8
|
+
Rails.logger = ActiveSupport::TaggedLogging.new(Logger.new(@log_stream))
|
9
|
+
end
|
10
|
+
|
11
|
+
after(:all) do
|
12
|
+
Rails.logger = nil
|
13
|
+
end
|
14
|
+
|
15
|
+
Rails::LabeledLog::LEVELS.each do |level|
|
16
|
+
describe "##{level}" do
|
17
|
+
it 'logs with labels' do
|
18
|
+
subject.send(level, "Message for #{level}")
|
19
|
+
expect(@log_stream.string).to include("[Chefe] [Pixel] Message for #{level} at ")
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module FakeModule
|
4
|
+
class FakeClass
|
5
|
+
include Rails::LabeledLog::Logging
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
describe Rails::LabeledLog::Logging do
|
10
|
+
before(:all) do
|
11
|
+
@log_stream = StringIO.new
|
12
|
+
Rails.logger = ActiveSupport::TaggedLogging.new(Logger.new(@log_stream))
|
13
|
+
end
|
14
|
+
|
15
|
+
after(:all) do
|
16
|
+
Rails.logger = nil
|
17
|
+
end
|
18
|
+
|
19
|
+
context 'class methods' do
|
20
|
+
subject { FakeModule::FakeClass }
|
21
|
+
|
22
|
+
Rails::LabeledLog::LEVELS.each do |level|
|
23
|
+
describe "#log_#{level}" do
|
24
|
+
it 'logs with class name' do
|
25
|
+
subject.send("log_#{level}", "Message for #{level} in class methods")
|
26
|
+
expect(@log_stream.string).to include("[FakeModule::FakeClass] Message for #{level} in class methods at ")
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context 'instance methods' do
|
33
|
+
subject { FakeModule::FakeClass.new }
|
34
|
+
|
35
|
+
Rails::LabeledLog::LEVELS.each do |level|
|
36
|
+
describe "#log_#{level}" do
|
37
|
+
it 'logs with class name' do
|
38
|
+
subject.send("log_#{level}", "Message for #{level} in instance methods")
|
39
|
+
expect(@log_stream.string).to include("[FakeModule::FakeClass] Message for #{level} in instance methods at ")
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'rails-labeled_log'
|
2
|
+
require 'coveralls'
|
3
|
+
require 'rails'
|
4
|
+
|
5
|
+
Coveralls.wear!
|
6
|
+
|
7
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
8
|
+
RSpec.configure do |config|
|
9
|
+
config.run_all_when_everything_filtered = true
|
10
|
+
config.filter_run :focus
|
11
|
+
config.order = 'random'
|
12
|
+
end
|
metadata
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rails-labeled_log
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Prodis a.k.a. Fernando Hamasaki de Amorim
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-09-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: coveralls
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: pry
|
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'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
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: A tool to use easily Rails Tagged Logging in your Ruby classes.
|
84
|
+
email: prodis@gmail.com
|
85
|
+
executables: []
|
86
|
+
extensions: []
|
87
|
+
extra_rdoc_files: []
|
88
|
+
files:
|
89
|
+
- ".gitignore"
|
90
|
+
- ".rspec"
|
91
|
+
- CODE_OF_CONDUCT.md
|
92
|
+
- Gemfile
|
93
|
+
- LICENSE
|
94
|
+
- README.md
|
95
|
+
- Rakefile
|
96
|
+
- lib/rails-labeled-log.rb
|
97
|
+
- lib/rails-labeled_log.rb
|
98
|
+
- lib/rails/labeled_log/levels.rb
|
99
|
+
- lib/rails/labeled_log/logger.rb
|
100
|
+
- lib/rails/labeled_log/logging.rb
|
101
|
+
- lib/rails/labeled_log/version.rb
|
102
|
+
- lib/rails_labeled-log.rb
|
103
|
+
- lib/rails_labeled_log.rb
|
104
|
+
- rails-labeled_log.gemspec
|
105
|
+
- spec/rails/labeled_log/logger_spec.rb
|
106
|
+
- spec/rails/labeled_log/logging_spec.rb
|
107
|
+
- spec/spec_helper.rb
|
108
|
+
homepage: https://github.com/prodis/rails-labeled_log
|
109
|
+
licenses:
|
110
|
+
- MIT
|
111
|
+
metadata: {}
|
112
|
+
post_install_message:
|
113
|
+
rdoc_options: []
|
114
|
+
require_paths:
|
115
|
+
- lib
|
116
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: 2.0.0
|
121
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - ">="
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
requirements: []
|
127
|
+
rubyforge_project:
|
128
|
+
rubygems_version: 2.4.5.1
|
129
|
+
signing_key:
|
130
|
+
specification_version: 4
|
131
|
+
summary: A tool to use easily Rails Tagged Logging in your Ruby classes.
|
132
|
+
test_files: []
|