log-me 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +1 -0
- data/.travis.yml +6 -0
- data/CHANGELOG.rdoc +4 -0
- data/Gemfile +1 -1
- data/README.rdoc +25 -6
- data/Rakefile +1 -25
- data/lib/log-me.rb +8 -10
- data/lib/logme/configuration.rb +7 -0
- data/lib/logme/version.rb +1 -2
- data/log-me.gemspec +7 -5
- data/spec/log-me_spec.rb +56 -27
- data/spec/spec_helper.rb +5 -8
- metadata +42 -26
- data/.document +0 -5
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c9341d345fdaea0e92971d20b2ecb4d339d3040f
|
4
|
+
data.tar.gz: 38aab7a27f126a223968cfde1a6153a21e88f01f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 44c0f529ec28f735bc7c63aa3293facf587a360f57770f52d3e173fac13eca39cba0df29c0bb8305ccbdd871ec38b3194d1fcd8f0774eb2df083ea06029820ee
|
7
|
+
data.tar.gz: d66794d8cd55d822b9efb9b82e86dc7e8aafc6023c8c2763505f7204659eed943eed55534282f890d69bcef42e6060ec0b712f95235acd2b52eccdcb30cc0db3
|
data/.rspec
CHANGED
data/.travis.yml
ADDED
data/CHANGELOG.rdoc
CHANGED
data/Gemfile
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
source
|
1
|
+
source "http://rubygems.org"
|
2
2
|
gemspec
|
data/README.rdoc
CHANGED
@@ -35,22 +35,41 @@ Using your gem:
|
|
35
35
|
some.do_something
|
36
36
|
|
37
37
|
By default will be logged in STDOUT using log level :info:
|
38
|
-
I, [2011-08-24T01:22:52.677395 #3026] INFO -- : I am logging something here.
|
38
|
+
I, [2011-08-24T01:22:52.677395 #3026] INFO -- : [CoolGem] I am logging something here.
|
39
39
|
|
40
40
|
Your gem consumer can configure the logger:
|
41
41
|
CoolGem.configure do |config|
|
42
|
-
config.log_enabled = false
|
43
|
-
config.log_level = :debug
|
44
|
-
config.
|
42
|
+
config.log_enabled = false # Disable log
|
43
|
+
config.log_level = :debug # Change the log level
|
44
|
+
config.log_label = "CoolLabel" # Change label to log messages
|
45
|
+
config.logger = Rails.logger # Use the Rails logger
|
45
46
|
end
|
46
47
|
|
48
|
+
== Author
|
49
|
+
- {Fernando Hamasaki de Amorim (prodis)}[http://prodis.blog.br]
|
50
|
+
|
51
|
+
|
52
|
+
== Contributing to log-me
|
53
|
+
|
54
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
55
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
56
|
+
* Fork the project.
|
57
|
+
* Start a feature/bugfix branch.
|
58
|
+
* Commit and push until you are happy with your contribution.
|
59
|
+
* Don't forget to rebase with branch master in main project before submit the pull request.
|
60
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
61
|
+
* 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.
|
62
|
+
|
63
|
+
|
47
64
|
== Copyright
|
48
65
|
|
49
66
|
(The MIT License)
|
50
67
|
|
51
|
-
{Prodis a.k.a. Fernando Hamasaki}[http://prodis.blog.br]
|
68
|
+
{Prodis a.k.a. Fernando Hamasaki de Amorim}[http://prodis.blog.br]
|
69
|
+
|
70
|
+
http://prodis.net.br/images/prodis_150.gif
|
52
71
|
|
53
|
-
Copyright (c) 2011-
|
72
|
+
Copyright (c) 2011-2014 Prodis
|
54
73
|
|
55
74
|
Permission is hereby granted, free of charge, to any person obtaining
|
56
75
|
a copy of this software and associated documentation files (the
|
data/Rakefile
CHANGED
@@ -1,25 +1 @@
|
|
1
|
-
|
2
|
-
require 'bundler/gem_tasks'
|
3
|
-
|
4
|
-
require 'rspec/core/rake_task'
|
5
|
-
RSpec::Core::RakeTask.new(:spec) do |spec|
|
6
|
-
spec.pattern = FileList["spec/**/*_spec.rb"]
|
7
|
-
end
|
8
|
-
|
9
|
-
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
10
|
-
spec.pattern = "spec/**/*_spec.rb"
|
11
|
-
spec.rcov = true
|
12
|
-
end
|
13
|
-
|
14
|
-
task :default => :spec
|
15
|
-
|
16
|
-
require 'rdoc/task'
|
17
|
-
Rake::RDocTask.new do |rdoc|
|
18
|
-
version = File.exist?("VERSION") ? File.read("VERSION") : ""
|
19
|
-
|
20
|
-
rdoc.rdoc_dir = "rdoc"
|
21
|
-
rdoc.title = "log-me #{version}"
|
22
|
-
rdoc.rdoc_files.include("README*")
|
23
|
-
rdoc.rdoc_files.include("CHANGELOG*")
|
24
|
-
rdoc.rdoc_files.include("lib/**/*.rb")
|
25
|
-
end
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/log-me.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
require 'rubygems'
|
3
1
|
require 'logger'
|
2
|
+
require 'logme/configuration'
|
4
3
|
|
5
4
|
module LogMe
|
6
5
|
attr_writer :log_enabled
|
7
6
|
attr_writer :log_level
|
7
|
+
attr_writer :log_label
|
8
8
|
attr_writer :logger
|
9
9
|
|
10
10
|
def log_enabled?
|
@@ -15,21 +15,19 @@ module LogMe
|
|
15
15
|
@log_level ||= :info
|
16
16
|
end
|
17
17
|
|
18
|
+
def log_label
|
19
|
+
@log_label ||= self.name
|
20
|
+
end
|
21
|
+
|
18
22
|
def logger
|
19
23
|
@logger ||= ::Logger.new STDOUT
|
20
24
|
end
|
21
25
|
|
22
26
|
def log(message)
|
23
|
-
logger.send log_level, "#{message}\n" if log_enabled?
|
27
|
+
logger.send log_level, "[#{log_label}] #{message}\n" if log_enabled?
|
24
28
|
end
|
25
29
|
|
26
30
|
def self.extended(base)
|
27
|
-
base.send :extend, Configuration
|
28
|
-
end
|
29
|
-
|
30
|
-
module Configuration
|
31
|
-
def configure
|
32
|
-
yield self if block_given?
|
33
|
-
end
|
31
|
+
base.send :extend, LogMe::Configuration
|
34
32
|
end
|
35
33
|
end
|
data/lib/logme/version.rb
CHANGED
data/log-me.gemspec
CHANGED
@@ -1,10 +1,11 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'logme/version'
|
3
4
|
|
4
5
|
Gem::Specification.new do |gem|
|
5
6
|
gem.name = "log-me"
|
6
7
|
gem.version = LogMe::VERSION
|
7
|
-
gem.authors = ["Prodis a.k.a. Fernando Hamasaki"]
|
8
|
+
gem.authors = ["Prodis a.k.a. Fernando Hamasaki de Amorim"]
|
8
9
|
gem.email = ["prodis@gmail.com"]
|
9
10
|
gem.summary = "A simple way to configure log in your gem."
|
10
11
|
gem.description = "LogMe is a simple way to configure log in your gem. It's especially useful when you need to log Web Service calls or HTTP requests and responses."
|
@@ -17,8 +18,9 @@ Gem::Specification.new do |gem|
|
|
17
18
|
gem.require_paths = ["lib"]
|
18
19
|
|
19
20
|
gem.platform = Gem::Platform::RUBY
|
20
|
-
gem.required_ruby_version = Gem::Requirement.new(">= 1.
|
21
|
+
gem.required_ruby_version = Gem::Requirement.new(">= 1.9.3")
|
21
22
|
|
23
|
+
gem.add_development_dependency "pry"
|
22
24
|
gem.add_development_dependency "rake"
|
23
|
-
gem.add_development_dependency "rspec", "~> 2.
|
25
|
+
gem.add_development_dependency "rspec", "~> 2.14"
|
24
26
|
end
|
data/spec/log-me_spec.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
# encoding: UTF-8
|
2
1
|
require 'spec_helper'
|
3
2
|
|
4
3
|
module FakeModule
|
@@ -6,97 +5,127 @@ module FakeModule
|
|
6
5
|
end
|
7
6
|
|
8
7
|
describe LogMe do
|
8
|
+
let(:subject) { FakeModule }
|
9
|
+
|
9
10
|
describe "#log_enabled?" do
|
10
11
|
it "default is true" do
|
11
|
-
|
12
|
+
expect(subject).to be_log_enabled
|
12
13
|
end
|
13
14
|
|
14
15
|
context "when log is disabled" do
|
15
16
|
around do |example|
|
16
|
-
|
17
|
+
subject.configure { |config| config.log_enabled = false }
|
17
18
|
example.run
|
18
|
-
|
19
|
+
subject.configure { |config| config.log_enabled = true }
|
19
20
|
end
|
20
21
|
|
21
22
|
it "returns false" do
|
22
|
-
|
23
|
+
expect(subject).to_not be_log_enabled
|
23
24
|
end
|
24
25
|
end
|
25
26
|
end
|
26
27
|
|
27
28
|
describe "#log_level" do
|
28
29
|
it "default is info" do
|
29
|
-
|
30
|
+
expect(subject.log_level).to eq :info
|
30
31
|
end
|
31
32
|
|
32
33
|
context "when log level is set" do
|
33
34
|
around do |example|
|
34
|
-
|
35
|
+
subject.configure { |config| config.log_level = :debug }
|
35
36
|
example.run
|
36
|
-
|
37
|
+
subject.configure { |config| config.log_level = :info }
|
37
38
|
end
|
38
39
|
|
39
40
|
it "returns set level" do
|
40
|
-
|
41
|
+
expect(subject.log_level).to eq :debug
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "#log_label" do
|
47
|
+
it "default is current module name" do
|
48
|
+
expect(subject.log_label).to eq subject.name
|
49
|
+
end
|
50
|
+
|
51
|
+
context "when set label" do
|
52
|
+
let(:label) { "Prodis #15" }
|
53
|
+
|
54
|
+
around do |example|
|
55
|
+
subject.configure { |config| config.log_label = label }
|
56
|
+
example.run
|
57
|
+
subject.configure { |config| config.log_label = subject.name }
|
58
|
+
end
|
59
|
+
|
60
|
+
it "returns label" do
|
61
|
+
expect(subject.log_label).to eq label
|
41
62
|
end
|
42
63
|
end
|
43
64
|
end
|
44
65
|
|
45
66
|
describe "#logger" do
|
46
67
|
it "default is Logger" do
|
47
|
-
|
68
|
+
expect(subject.logger).to be_a(::Logger)
|
48
69
|
end
|
49
70
|
|
50
71
|
context "when set logger" do
|
51
72
|
it "returns set logger" do
|
52
73
|
fake_logger = Class.new
|
53
|
-
|
54
|
-
|
74
|
+
subject.configure { |config| config.logger = fake_logger }
|
75
|
+
expect(subject.logger).to eq fake_logger
|
55
76
|
end
|
56
77
|
end
|
57
78
|
end
|
58
79
|
|
59
80
|
describe "#log" do
|
60
|
-
|
61
|
-
|
62
|
-
|
81
|
+
let(:log_stream) { StringIO.new }
|
82
|
+
let(:label) { "Cool Label" }
|
83
|
+
|
84
|
+
before do
|
85
|
+
subject.configure { |config| config.logger = ::Logger.new(log_stream) }
|
86
|
+
end
|
87
|
+
|
88
|
+
around do |example|
|
89
|
+
subject.configure { |config| config.log_label = label }
|
90
|
+
example.run
|
91
|
+
subject.configure { |config| config.log_label = subject.name }
|
63
92
|
end
|
64
93
|
|
65
94
|
context "when log is enabled" do
|
66
95
|
it "logs the message" do
|
67
|
-
|
68
|
-
|
96
|
+
subject.log "Some message to log."
|
97
|
+
expect(log_stream.string).to include "[#{label}] Some message to log.\n"
|
69
98
|
end
|
70
99
|
|
71
100
|
it "calls log level method" do
|
72
|
-
|
73
|
-
|
101
|
+
expect(subject.logger).to receive(:info).with("[#{label}] Some message to log.\n")
|
102
|
+
subject.log "Some message to log."
|
74
103
|
end
|
75
104
|
end
|
76
105
|
|
77
106
|
context "when log is disabled" do
|
78
107
|
around do |example|
|
79
|
-
|
108
|
+
subject.configure { |config| config.log_enabled = false }
|
80
109
|
example.run
|
81
|
-
|
110
|
+
subject.configure { |config| config.log_enabled = true }
|
82
111
|
end
|
83
112
|
|
84
113
|
it "does not log the message" do
|
85
|
-
|
86
|
-
|
114
|
+
subject.log "Some message to log."
|
115
|
+
expect(log_stream.string).to be_empty
|
87
116
|
end
|
88
117
|
end
|
89
118
|
|
90
119
|
context "when log level is set" do
|
91
120
|
around do |example|
|
92
|
-
|
121
|
+
subject.configure { |config| config.log_level = :debug }
|
93
122
|
example.run
|
94
|
-
|
123
|
+
subject.configure { |config| config.log_level = :info }
|
95
124
|
end
|
96
125
|
|
97
126
|
it "calls log level set method" do
|
98
|
-
|
99
|
-
|
127
|
+
expect(subject.logger).to receive(:debug).with("[#{label}] Some message to log.\n")
|
128
|
+
subject.log "Some message to log."
|
100
129
|
end
|
101
130
|
end
|
102
131
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,12 +1,9 @@
|
|
1
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
-
require 'rspec'
|
4
1
|
require 'log-me'
|
5
2
|
|
6
|
-
#
|
7
|
-
# in ./support/ and its subdirectories.
|
8
|
-
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
9
|
-
|
3
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
10
4
|
RSpec.configure do |config|
|
11
|
-
|
5
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
6
|
+
config.run_all_when_everything_filtered = true
|
7
|
+
config.filter_run :focus
|
8
|
+
config.order = "random"
|
12
9
|
end
|
metadata
CHANGED
@@ -1,38 +1,57 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: log-me
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.5
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
|
-
- Prodis a.k.a. Fernando Hamasaki
|
7
|
+
- Prodis a.k.a. Fernando Hamasaki de Amorim
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2014-02-19 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: pry
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
14
27
|
- !ruby/object:Gem::Dependency
|
15
28
|
name: rake
|
16
|
-
requirement:
|
17
|
-
none: false
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
18
30
|
requirements:
|
19
|
-
- -
|
31
|
+
- - ">="
|
20
32
|
- !ruby/object:Gem::Version
|
21
33
|
version: '0'
|
22
34
|
type: :development
|
23
35
|
prerelease: false
|
24
|
-
version_requirements:
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
25
41
|
- !ruby/object:Gem::Dependency
|
26
42
|
name: rspec
|
27
|
-
requirement:
|
28
|
-
none: false
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
29
44
|
requirements:
|
30
|
-
- - ~>
|
45
|
+
- - "~>"
|
31
46
|
- !ruby/object:Gem::Version
|
32
|
-
version: '2.
|
47
|
+
version: '2.14'
|
33
48
|
type: :development
|
34
49
|
prerelease: false
|
35
|
-
version_requirements:
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.14'
|
36
55
|
description: LogMe is a simple way to configure log in your gem. It's especially useful
|
37
56
|
when you need to log Web Service calls or HTTP requests and responses.
|
38
57
|
email:
|
@@ -41,14 +60,15 @@ executables: []
|
|
41
60
|
extensions: []
|
42
61
|
extra_rdoc_files: []
|
43
62
|
files:
|
44
|
-
- .
|
45
|
-
- .
|
46
|
-
- .
|
63
|
+
- ".gitignore"
|
64
|
+
- ".rspec"
|
65
|
+
- ".travis.yml"
|
47
66
|
- CHANGELOG.rdoc
|
48
67
|
- Gemfile
|
49
68
|
- README.rdoc
|
50
69
|
- Rakefile
|
51
70
|
- lib/log-me.rb
|
71
|
+
- lib/logme/configuration.rb
|
52
72
|
- lib/logme/version.rb
|
53
73
|
- log-me.gemspec
|
54
74
|
- spec/log-me_spec.rb
|
@@ -56,30 +76,26 @@ files:
|
|
56
76
|
homepage: http://github.com/prodis/log-me
|
57
77
|
licenses:
|
58
78
|
- MIT
|
79
|
+
metadata: {}
|
59
80
|
post_install_message:
|
60
81
|
rdoc_options: []
|
61
82
|
require_paths:
|
62
83
|
- lib
|
63
84
|
required_ruby_version: !ruby/object:Gem::Requirement
|
64
|
-
none: false
|
65
85
|
requirements:
|
66
|
-
- -
|
86
|
+
- - ">="
|
67
87
|
- !ruby/object:Gem::Version
|
68
|
-
version: 1.
|
88
|
+
version: 1.9.3
|
69
89
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
-
none: false
|
71
90
|
requirements:
|
72
|
-
- -
|
91
|
+
- - ">="
|
73
92
|
- !ruby/object:Gem::Version
|
74
93
|
version: '0'
|
75
|
-
segments:
|
76
|
-
- 0
|
77
|
-
hash: -940858029
|
78
94
|
requirements: []
|
79
95
|
rubyforge_project:
|
80
|
-
rubygems_version:
|
96
|
+
rubygems_version: 2.2.2
|
81
97
|
signing_key:
|
82
|
-
specification_version:
|
98
|
+
specification_version: 4
|
83
99
|
summary: A simple way to configure log in your gem.
|
84
100
|
test_files:
|
85
101
|
- spec/log-me_spec.rb
|