log-me 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +8 -0
- data/Gemfile.lock +28 -0
- data/README.rdoc +73 -0
- data/Rakefile +52 -0
- data/lib/log-me.rb +35 -0
- data/lib/logme/version.rb +9 -0
- data/log-me.gemspec +59 -0
- data/spec/log-me_spec.rb +103 -0
- data/spec/spec_helper.rb +12 -0
- metadata +109 -0
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
diff-lcs (1.1.2)
|
5
|
+
git (1.2.5)
|
6
|
+
jeweler (1.6.4)
|
7
|
+
bundler (~> 1.0)
|
8
|
+
git (>= 1.2.5)
|
9
|
+
rake
|
10
|
+
rake (0.9.2)
|
11
|
+
rcov (0.9.10)
|
12
|
+
rspec (2.6.0)
|
13
|
+
rspec-core (~> 2.6.0)
|
14
|
+
rspec-expectations (~> 2.6.0)
|
15
|
+
rspec-mocks (~> 2.6.0)
|
16
|
+
rspec-core (2.6.4)
|
17
|
+
rspec-expectations (2.6.0)
|
18
|
+
diff-lcs (~> 1.1.2)
|
19
|
+
rspec-mocks (2.6.0)
|
20
|
+
|
21
|
+
PLATFORMS
|
22
|
+
ruby
|
23
|
+
|
24
|
+
DEPENDENCIES
|
25
|
+
bundler (~> 1.0.0)
|
26
|
+
jeweler (~> 1.6.2)
|
27
|
+
rcov
|
28
|
+
rspec (~> 2.6.0)
|
data/README.rdoc
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
= LogMe
|
2
|
+
|
3
|
+
A simple way to configure log in your gem.
|
4
|
+
|
5
|
+
LogMe is especially useful when you need to log Web Service calls or HTTP requests and responses.
|
6
|
+
|
7
|
+
== Instalation
|
8
|
+
|
9
|
+
=== Gemfile
|
10
|
+
gem 'log-me'
|
11
|
+
|
12
|
+
=== Command line
|
13
|
+
$ gem install log-me
|
14
|
+
|
15
|
+
== Usage
|
16
|
+
|
17
|
+
In your gem:
|
18
|
+
require 'log-me'
|
19
|
+
|
20
|
+
module CoolGem
|
21
|
+
extend LogMe
|
22
|
+
end
|
23
|
+
|
24
|
+
module CoolGem
|
25
|
+
class SomeClass
|
26
|
+
def do_something
|
27
|
+
# do something and log
|
28
|
+
CoolGem.log "I am logging something here."
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
Using your gem:
|
34
|
+
some = CoolGem.SomeClass.new
|
35
|
+
some.do_something
|
36
|
+
|
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.
|
39
|
+
|
40
|
+
Your gem consumer can configure the logger:
|
41
|
+
CoolGem.configure_me do |config|
|
42
|
+
config.log_enabled = false # Disable log
|
43
|
+
config.log_level = :debug # Change the log level
|
44
|
+
config.logger = Rails.logger # Use the Rails logger
|
45
|
+
end
|
46
|
+
|
47
|
+
== Copyright
|
48
|
+
|
49
|
+
(The MIT License)
|
50
|
+
|
51
|
+
{Prodis a.k.a. Fernando Hamasaki}[http://prodis.blog.br]
|
52
|
+
|
53
|
+
Copyright (c) 2011 Prodis
|
54
|
+
|
55
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
56
|
+
a copy of this software and associated documentation files (the
|
57
|
+
"Software"), to deal in the Software without restriction, including
|
58
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
59
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
60
|
+
permit persons to whom the Software is furnished to do so, subject to
|
61
|
+
the following conditions:
|
62
|
+
|
63
|
+
The above copyright notice and this permission notice shall be
|
64
|
+
included in all copies or substantial portions of the Software.
|
65
|
+
|
66
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
67
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
68
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
69
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
70
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
71
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
72
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
73
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'rubygems'
|
3
|
+
require 'rake'
|
4
|
+
require './lib/logme/version'
|
5
|
+
|
6
|
+
require 'bundler'
|
7
|
+
begin
|
8
|
+
Bundler.setup(:default, :development)
|
9
|
+
rescue Bundler::BundlerError => e
|
10
|
+
$stderr.puts e.message
|
11
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
12
|
+
exit e.status_code
|
13
|
+
end
|
14
|
+
|
15
|
+
require 'jeweler'
|
16
|
+
Jeweler::Tasks.new do |gem|
|
17
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
18
|
+
gem.name = "log-me"
|
19
|
+
gem.homepage = "http://github.com/prodis/log-me"
|
20
|
+
gem.license = "MIT"
|
21
|
+
gem.summary = %Q{A simple way to configure log in your gem.}
|
22
|
+
gem.description = %Q{LogMe is especially useful when you need to log Web Service calls or HTTP requests and responses.}
|
23
|
+
gem.email = "prodis@gmail.com"
|
24
|
+
gem.authors = ["Prodis a.k.a. Fernando Hamasaki"]
|
25
|
+
gem.version = LogMe::Version::VERSION
|
26
|
+
gem.required_ruby_version = ">= 1.8.7"
|
27
|
+
# dependencies defined in Gemfile
|
28
|
+
end
|
29
|
+
Jeweler::RubygemsDotOrgTasks.new
|
30
|
+
|
31
|
+
require 'rspec/core'
|
32
|
+
require 'rspec/core/rake_task'
|
33
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
34
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
35
|
+
end
|
36
|
+
|
37
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
38
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
39
|
+
spec.rcov = true
|
40
|
+
end
|
41
|
+
|
42
|
+
task :default => :spec
|
43
|
+
|
44
|
+
require 'rake/rdoctask'
|
45
|
+
Rake::RDocTask.new do |rdoc|
|
46
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
47
|
+
|
48
|
+
rdoc.rdoc_dir = 'rdoc'
|
49
|
+
rdoc.title = "log-me #{version}"
|
50
|
+
rdoc.rdoc_files.include('README*')
|
51
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
52
|
+
end
|
data/lib/log-me.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'rubygems'
|
3
|
+
require 'logger'
|
4
|
+
|
5
|
+
module LogMe
|
6
|
+
attr_writer :log_enabled
|
7
|
+
attr_writer :log_level
|
8
|
+
attr_writer :logger
|
9
|
+
|
10
|
+
def log_enabled?
|
11
|
+
@log_enabled != false
|
12
|
+
end
|
13
|
+
|
14
|
+
def log_level
|
15
|
+
@log_level ||= :info
|
16
|
+
end
|
17
|
+
|
18
|
+
def logger
|
19
|
+
@logger ||= ::Logger.new STDOUT
|
20
|
+
end
|
21
|
+
|
22
|
+
def log(message)
|
23
|
+
logger.send log_level, message if log_enabled?
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.extended(base)
|
27
|
+
base.send :extend, Configuration
|
28
|
+
end
|
29
|
+
|
30
|
+
module Configuration
|
31
|
+
def configure_me
|
32
|
+
yield self if block_given?
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/log-me.gemspec
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{log-me}
|
8
|
+
s.version = "0.0.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Prodis a.k.a. Fernando Hamasaki"]
|
12
|
+
s.date = %q{2011-08-24}
|
13
|
+
s.description = %q{LogMe is especially useful when you need to log Web Service calls or HTTP requests and responses.}
|
14
|
+
s.email = %q{prodis@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"README.rdoc"
|
17
|
+
]
|
18
|
+
s.files = [
|
19
|
+
".document",
|
20
|
+
".rspec",
|
21
|
+
"Gemfile",
|
22
|
+
"Gemfile.lock",
|
23
|
+
"README.rdoc",
|
24
|
+
"Rakefile",
|
25
|
+
"lib/log-me.rb",
|
26
|
+
"lib/logme/version.rb",
|
27
|
+
"log-me.gemspec",
|
28
|
+
"spec/log-me_spec.rb",
|
29
|
+
"spec/spec_helper.rb"
|
30
|
+
]
|
31
|
+
s.homepage = %q{http://github.com/prodis/log-me}
|
32
|
+
s.licenses = ["MIT"]
|
33
|
+
s.require_paths = ["lib"]
|
34
|
+
s.required_ruby_version = Gem::Requirement.new(">= 1.8.7")
|
35
|
+
s.rubygems_version = %q{1.6.1}
|
36
|
+
s.summary = %q{A simple way to configure log in your gem.}
|
37
|
+
|
38
|
+
if s.respond_to? :specification_version then
|
39
|
+
s.specification_version = 3
|
40
|
+
|
41
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
42
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.6.0"])
|
43
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
44
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.6.2"])
|
45
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
46
|
+
else
|
47
|
+
s.add_dependency(%q<rspec>, ["~> 2.6.0"])
|
48
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
49
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.2"])
|
50
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
51
|
+
end
|
52
|
+
else
|
53
|
+
s.add_dependency(%q<rspec>, ["~> 2.6.0"])
|
54
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
55
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.2"])
|
56
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
data/spec/log-me_spec.rb
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
module FakeModule
|
5
|
+
extend LogMe
|
6
|
+
end
|
7
|
+
|
8
|
+
describe LogMe do
|
9
|
+
describe "#log_enabled?" do
|
10
|
+
it "default is true" do
|
11
|
+
FakeModule.log_enabled?.should be_true
|
12
|
+
end
|
13
|
+
|
14
|
+
context "when log is disabled" do
|
15
|
+
around do |example|
|
16
|
+
FakeModule.configure_me { |config| config.log_enabled = false }
|
17
|
+
example.run
|
18
|
+
FakeModule.configure_me { |config| config.log_enabled = true }
|
19
|
+
end
|
20
|
+
|
21
|
+
it "returns false" do
|
22
|
+
FakeModule.log_enabled?.should be_false
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "#log_level" do
|
28
|
+
it "default is info" do
|
29
|
+
FakeModule.log_level.should == :info
|
30
|
+
end
|
31
|
+
|
32
|
+
context "when log level is set" do
|
33
|
+
around do |example|
|
34
|
+
FakeModule.configure_me { |config| config.log_level = :debug }
|
35
|
+
example.run
|
36
|
+
FakeModule.configure_me { |config| config.log_level = :info }
|
37
|
+
end
|
38
|
+
|
39
|
+
it "returns set level" do
|
40
|
+
FakeModule.log_level.should == :debug
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "#logger" do
|
46
|
+
it "default is Logger" do
|
47
|
+
FakeModule.logger.should be_a(::Logger)
|
48
|
+
end
|
49
|
+
|
50
|
+
context "when set logger" do
|
51
|
+
it "returns set logger" do
|
52
|
+
fake_logger = Class.new
|
53
|
+
FakeModule.configure_me { |config| config.logger = fake_logger }
|
54
|
+
FakeModule.logger.should == fake_logger
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe "#log" do
|
60
|
+
before :each do
|
61
|
+
@log_stream = StringIO.new
|
62
|
+
FakeModule.configure_me { |config| config.logger = ::Logger.new(@log_stream) }
|
63
|
+
end
|
64
|
+
|
65
|
+
context "when log is enabled" do
|
66
|
+
it "logs the message" do
|
67
|
+
FakeModule.log("Some message to log.")
|
68
|
+
@log_stream.string.should include("Some message to log.")
|
69
|
+
end
|
70
|
+
|
71
|
+
it "calls log level method" do
|
72
|
+
FakeModule.logger.should_receive(:info).with("Some message to log.")
|
73
|
+
FakeModule.log("Some message to log.")
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
context "when log is disabled" do
|
78
|
+
around do |example|
|
79
|
+
FakeModule.configure_me { |config| config.log_enabled = false }
|
80
|
+
example.run
|
81
|
+
FakeModule.configure_me { |config| config.log_enabled = true }
|
82
|
+
end
|
83
|
+
|
84
|
+
it "does not log the message" do
|
85
|
+
FakeModule.log("Some message to log.")
|
86
|
+
@log_stream.string.should be_empty
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
context "when log level is set" do
|
91
|
+
around do |example|
|
92
|
+
FakeModule.configure_me { |config| config.log_level = :debug }
|
93
|
+
example.run
|
94
|
+
FakeModule.configure_me { |config| config.log_level = :info }
|
95
|
+
end
|
96
|
+
|
97
|
+
it "calls log level set method" do
|
98
|
+
FakeModule.logger.should_receive(:debug).with("Some message to log.")
|
99
|
+
FakeModule.log("Some message to log.")
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'log-me'
|
5
|
+
|
6
|
+
# Requires supporting files with custom matchers and macros, etc,
|
7
|
+
# in ./support/ and its subdirectories.
|
8
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
|
12
|
+
end
|
metadata
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: log-me
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.0
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Prodis a.k.a. Fernando Hamasaki
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-08-24 00:00:00 -03:00
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: rspec
|
18
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ~>
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 2.6.0
|
24
|
+
type: :development
|
25
|
+
prerelease: false
|
26
|
+
version_requirements: *id001
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
31
|
+
requirements:
|
32
|
+
- - ~>
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 1.0.0
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: *id002
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: jeweler
|
40
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 1.6.2
|
46
|
+
type: :development
|
47
|
+
prerelease: false
|
48
|
+
version_requirements: *id003
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: rcov
|
51
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: "0"
|
57
|
+
type: :development
|
58
|
+
prerelease: false
|
59
|
+
version_requirements: *id004
|
60
|
+
description: LogMe is especially useful when you need to log Web Service calls or HTTP requests and responses.
|
61
|
+
email: prodis@gmail.com
|
62
|
+
executables: []
|
63
|
+
|
64
|
+
extensions: []
|
65
|
+
|
66
|
+
extra_rdoc_files:
|
67
|
+
- README.rdoc
|
68
|
+
files:
|
69
|
+
- .document
|
70
|
+
- .rspec
|
71
|
+
- Gemfile
|
72
|
+
- Gemfile.lock
|
73
|
+
- README.rdoc
|
74
|
+
- Rakefile
|
75
|
+
- lib/log-me.rb
|
76
|
+
- lib/logme/version.rb
|
77
|
+
- log-me.gemspec
|
78
|
+
- spec/log-me_spec.rb
|
79
|
+
- spec/spec_helper.rb
|
80
|
+
has_rdoc: true
|
81
|
+
homepage: http://github.com/prodis/log-me
|
82
|
+
licenses:
|
83
|
+
- MIT
|
84
|
+
post_install_message:
|
85
|
+
rdoc_options: []
|
86
|
+
|
87
|
+
require_paths:
|
88
|
+
- lib
|
89
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
90
|
+
none: false
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: 1.8.7
|
95
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
|
+
none: false
|
97
|
+
requirements:
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: "0"
|
101
|
+
requirements: []
|
102
|
+
|
103
|
+
rubyforge_project:
|
104
|
+
rubygems_version: 1.6.1
|
105
|
+
signing_key:
|
106
|
+
specification_version: 3
|
107
|
+
summary: A simple way to configure log in your gem.
|
108
|
+
test_files: []
|
109
|
+
|