logem 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.irbrc +6 -0
- data/.rspec +1 -0
- data/Gemfile +13 -0
- data/Gemfile.lock +31 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +26 -0
- data/Rakefile +49 -0
- data/VERSION +1 -0
- data/lib/logem.rb +1 -0
- data/lib/logem/logger.rb +96 -0
- data/spec/logem_spec.rb +7 -0
- data/spec/spec_helper.rb +12 -0
- metadata +142 -0
data/.document
ADDED
data/.irbrc
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
# Add dependencies to develop your gem here.
|
7
|
+
# Include everything needed to run rake, tests, features, etc.
|
8
|
+
group :development do
|
9
|
+
gem "rspec", "~> 2.8.0"
|
10
|
+
gem "rdoc", "~> 3.12"
|
11
|
+
gem "bundler", ">= 1.0.0"
|
12
|
+
gem "jeweler", "~> 1.8.4"
|
13
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
diff-lcs (1.1.3)
|
5
|
+
git (1.2.5)
|
6
|
+
jeweler (1.8.4)
|
7
|
+
bundler (~> 1.0)
|
8
|
+
git (>= 1.2.5)
|
9
|
+
rake
|
10
|
+
rdoc
|
11
|
+
json (1.7.5)
|
12
|
+
rake (0.9.2.2)
|
13
|
+
rdoc (3.12)
|
14
|
+
json (~> 1.4)
|
15
|
+
rspec (2.8.0)
|
16
|
+
rspec-core (~> 2.8.0)
|
17
|
+
rspec-expectations (~> 2.8.0)
|
18
|
+
rspec-mocks (~> 2.8.0)
|
19
|
+
rspec-core (2.8.0)
|
20
|
+
rspec-expectations (2.8.0)
|
21
|
+
diff-lcs (~> 1.1.2)
|
22
|
+
rspec-mocks (2.8.0)
|
23
|
+
|
24
|
+
PLATFORMS
|
25
|
+
ruby
|
26
|
+
|
27
|
+
DEPENDENCIES
|
28
|
+
bundler (>= 1.0.0)
|
29
|
+
jeweler (~> 1.8.4)
|
30
|
+
rdoc (~> 3.12)
|
31
|
+
rspec (~> 2.8.0)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 Guoliang Cao
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
= logem
|
2
|
+
|
3
|
+
A simple logger for ruby
|
4
|
+
|
5
|
+
== Usage
|
6
|
+
|
7
|
+
require 'logem'
|
8
|
+
|
9
|
+
logger = Logem::Logger.new klass
|
10
|
+
logger.trace 'method_name', 'args', 'etc'
|
11
|
+
|
12
|
+
== Contributing to logem
|
13
|
+
|
14
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
15
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
16
|
+
* Fork the project.
|
17
|
+
* Start a feature/bugfix branch.
|
18
|
+
* Commit and push until you are happy with your contribution.
|
19
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
20
|
+
* 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.
|
21
|
+
|
22
|
+
== Copyright
|
23
|
+
|
24
|
+
Copyright (c) 2012 Guoliang Cao. See LICENSE.txt for
|
25
|
+
further details.
|
26
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "logem"
|
18
|
+
gem.homepage = "http://github.com/gcao/logem"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{A simple logger for Ruby}
|
21
|
+
gem.description = %Q{A simple logger for Ruby}
|
22
|
+
gem.email = "gcao99@gmail.com"
|
23
|
+
gem.authors = ["Guoliang Cao"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rspec/core'
|
29
|
+
require 'rspec/core/rake_task'
|
30
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
31
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
32
|
+
end
|
33
|
+
|
34
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
35
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
36
|
+
spec.rcov = true
|
37
|
+
end
|
38
|
+
|
39
|
+
task :default => :spec
|
40
|
+
|
41
|
+
require 'rdoc/task'
|
42
|
+
Rake::RDocTask.new do |rdoc|
|
43
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
44
|
+
|
45
|
+
rdoc.rdoc_dir = 'rdoc'
|
46
|
+
rdoc.title = "logem #{version}"
|
47
|
+
rdoc.rdoc_files.include('README*')
|
48
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
49
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/lib/logem.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'logem/logger'
|
data/lib/logem/logger.rb
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
module Logem
|
2
|
+
class Logger
|
3
|
+
# Log levels
|
4
|
+
ERROR = 50
|
5
|
+
WARN = 40
|
6
|
+
INFO = 30
|
7
|
+
DEBUG = 20
|
8
|
+
TRACE = 10
|
9
|
+
|
10
|
+
DEFAULT_VISIBLE_LEVEL = INFO
|
11
|
+
DEFAULT_LOG_LEVEL_ENV = "LOGEM_LOG_LEVEL"
|
12
|
+
|
13
|
+
attr :log_level_env
|
14
|
+
attr_accessor :visible_level
|
15
|
+
|
16
|
+
def initialize context, options = {}
|
17
|
+
@context = context
|
18
|
+
@log_level_env = options[:log_level_env ] || DEFAULT_LOG_LEVEL_ENV
|
19
|
+
@visible_level = options[:visible_level ] || self.class.string_to_level(ENV[@log_level_env]) || DEFAULT_VISIBLE_LEVEL
|
20
|
+
@output = options[:output ] || $stdout
|
21
|
+
@time_formatter = options[:time_formatter]
|
22
|
+
@output_supports_logem = @output.respond_to? :logem
|
23
|
+
end
|
24
|
+
|
25
|
+
def log level, *args
|
26
|
+
return if @visible_level > level
|
27
|
+
|
28
|
+
_log_ level, *args
|
29
|
+
end
|
30
|
+
|
31
|
+
def visible? level
|
32
|
+
@visible_level <= level
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.level_to_string level
|
36
|
+
case level
|
37
|
+
when ERROR then "ERROR"
|
38
|
+
when WARN then "WARN "
|
39
|
+
when INFO then "INFO "
|
40
|
+
when DEBUG then "DEBUG"
|
41
|
+
when TRACE then "TRACE"
|
42
|
+
else level.to_s
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.string_to_level level_string
|
47
|
+
return DEFAULT_VISIBLE_LEVEL if level_string.nil? or level_string.strip == ''
|
48
|
+
|
49
|
+
case level_string.strip.downcase
|
50
|
+
when 'error' then ERROR
|
51
|
+
when 'warn' then WARN
|
52
|
+
when 'info' then INFO
|
53
|
+
when 'debug' then DEBUG
|
54
|
+
when 'trace' then TRACE
|
55
|
+
else
|
56
|
+
$stdout.puts "Logem warning: #{level_string} is not a valid log level, " +
|
57
|
+
"default to #{level_to_string(DEFAULT_VISIBLE_LEVEL).strip}"
|
58
|
+
DEFAULT_VISIBLE_LEVEL
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
%w[error warn info debug trace].each do |level_str|
|
63
|
+
level = string_to_level(level_str)
|
64
|
+
|
65
|
+
define_method level_str do |*args|
|
66
|
+
return if @visible_level > level
|
67
|
+
|
68
|
+
_log_ level, *args
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
private
|
73
|
+
|
74
|
+
def _log_ level, *args
|
75
|
+
time = Time.now
|
76
|
+
|
77
|
+
if @output_supports_logem
|
78
|
+
@output.logem time, self.class.level_to_string(level), @context, *args
|
79
|
+
else
|
80
|
+
time_str = @time_formatter ? @time_formatter.call(time) : time.to_s
|
81
|
+
|
82
|
+
parts = [time_str, self.class.level_to_string(level), @context.to_s]
|
83
|
+
args.each {|arg| parts << (arg.nil? ? 'nil' : arg.to_s) }
|
84
|
+
|
85
|
+
@output.puts parts.join(' | ')
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
ERROR = Logger::ERROR
|
91
|
+
WARN = Logger::WARN
|
92
|
+
INFO = Logger::INFO
|
93
|
+
DEBUG = Logger::DEBUG
|
94
|
+
TRACE = Logger::TRACE
|
95
|
+
end
|
96
|
+
|
data/spec/logem_spec.rb
ADDED
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 'logem'
|
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,142 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: logem
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Guoliang Cao
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2012-09-19 00:00:00 -04:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
prerelease: false
|
23
|
+
type: :development
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 47
|
30
|
+
segments:
|
31
|
+
- 2
|
32
|
+
- 8
|
33
|
+
- 0
|
34
|
+
version: 2.8.0
|
35
|
+
name: rspec
|
36
|
+
version_requirements: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
prerelease: false
|
39
|
+
type: :development
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
hash: 31
|
46
|
+
segments:
|
47
|
+
- 3
|
48
|
+
- 12
|
49
|
+
version: "3.12"
|
50
|
+
name: rdoc
|
51
|
+
version_requirements: *id002
|
52
|
+
- !ruby/object:Gem::Dependency
|
53
|
+
prerelease: false
|
54
|
+
type: :development
|
55
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
56
|
+
none: false
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
hash: 23
|
61
|
+
segments:
|
62
|
+
- 1
|
63
|
+
- 0
|
64
|
+
- 0
|
65
|
+
version: 1.0.0
|
66
|
+
name: bundler
|
67
|
+
version_requirements: *id003
|
68
|
+
- !ruby/object:Gem::Dependency
|
69
|
+
prerelease: false
|
70
|
+
type: :development
|
71
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ~>
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
hash: 63
|
77
|
+
segments:
|
78
|
+
- 1
|
79
|
+
- 8
|
80
|
+
- 4
|
81
|
+
version: 1.8.4
|
82
|
+
name: jeweler
|
83
|
+
version_requirements: *id004
|
84
|
+
description: A simple logger for Ruby
|
85
|
+
email: gcao99@gmail.com
|
86
|
+
executables: []
|
87
|
+
|
88
|
+
extensions: []
|
89
|
+
|
90
|
+
extra_rdoc_files:
|
91
|
+
- LICENSE.txt
|
92
|
+
- README.rdoc
|
93
|
+
files:
|
94
|
+
- .document
|
95
|
+
- .irbrc
|
96
|
+
- .rspec
|
97
|
+
- Gemfile
|
98
|
+
- Gemfile.lock
|
99
|
+
- LICENSE.txt
|
100
|
+
- README.rdoc
|
101
|
+
- Rakefile
|
102
|
+
- VERSION
|
103
|
+
- lib/logem.rb
|
104
|
+
- lib/logem/logger.rb
|
105
|
+
- spec/logem_spec.rb
|
106
|
+
- spec/spec_helper.rb
|
107
|
+
has_rdoc: true
|
108
|
+
homepage: http://github.com/gcao/logem
|
109
|
+
licenses:
|
110
|
+
- MIT
|
111
|
+
post_install_message:
|
112
|
+
rdoc_options: []
|
113
|
+
|
114
|
+
require_paths:
|
115
|
+
- lib
|
116
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
117
|
+
none: false
|
118
|
+
requirements:
|
119
|
+
- - ">="
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
hash: 3
|
122
|
+
segments:
|
123
|
+
- 0
|
124
|
+
version: "0"
|
125
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
126
|
+
none: false
|
127
|
+
requirements:
|
128
|
+
- - ">="
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
hash: 3
|
131
|
+
segments:
|
132
|
+
- 0
|
133
|
+
version: "0"
|
134
|
+
requirements: []
|
135
|
+
|
136
|
+
rubyforge_project:
|
137
|
+
rubygems_version: 1.6.2
|
138
|
+
signing_key:
|
139
|
+
specification_version: 3
|
140
|
+
summary: A simple logger for Ruby
|
141
|
+
test_files: []
|
142
|
+
|