em-logger 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gemtest ADDED
File without changes
data/.gitignore ADDED
@@ -0,0 +1,40 @@
1
+ *.gem
2
+ *.rbc
3
+ *.sw[a-p]
4
+ *.tmproj
5
+ *.tmproject
6
+ *.un~
7
+ *~
8
+ .DS_Store
9
+ .Spotlight-V100
10
+ .Trashes
11
+ ._*
12
+ .bundle
13
+ .config
14
+ .directory
15
+ .elc
16
+ .emacs.desktop
17
+ .emacs.desktop.lock
18
+ .redcar
19
+ .yardoc
20
+ Desktop.ini
21
+ Gemfile.lock
22
+ Icon?
23
+ InstalledFiles
24
+ Session.vim
25
+ Thumbs.db
26
+ \#*\#
27
+ _yardoc
28
+ auto-save-list
29
+ coverage
30
+ doc
31
+ lib/bundler/man
32
+ pkg
33
+ pkg/*
34
+ rdoc
35
+ spec/reports
36
+ test/tmp
37
+ test/version_tmp
38
+ tmp
39
+ tmtags
40
+ tramp
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --format=nested
3
+ --backtrace
data/.simplecov ADDED
@@ -0,0 +1 @@
1
+ SimpleCov.start
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ rvm:
2
+ - 1.8.7
3
+ - 1.9.2
4
+ - 1.9.3
5
+ - jruby
6
+ - rbx
7
+ - ree
8
+ - ruby-head
data/.yardopts ADDED
@@ -0,0 +1,3 @@
1
+ --markup markdown
2
+ -
3
+ LICENSE.md
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gemspec
data/LICENSE.md ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Steve Agalloco
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.md ADDED
@@ -0,0 +1,29 @@
1
+ # EventMachine Logger
2
+
3
+ An experimental logger class for EventMachine applications.
4
+
5
+ ## Usage
6
+
7
+ EM::Logger is a simple delegator around the ruby logger class. It responds to all the log levels you are familiar with from existing loggers (info, debug, warn, etc.). The only difference is that it's instantiated by passing an existing logger in when initializing
8
+
9
+ require 'eventmachine'
10
+ require 'logger'
11
+ require 'em-logger'
12
+
13
+ log = Logger.new(STDOUT)
14
+ logger = EM::Logger.new(log)
15
+
16
+ EM.run do
17
+ logger.info('ohai')
18
+
19
+ EM.stop
20
+ end
21
+
22
+
23
+ ## Contributing
24
+
25
+ Pull requests welcome: fork, make a topic branch, commit (squash when possible) *with tests* and I'll happily consider.
26
+
27
+ ## Copyright
28
+
29
+ Copyright (c) 2012 Steve Agalloco. See [LICENSE](https://github.com/spagalloco/em-logger/blob/master/LICENSE.md) for detail
data/Rakefile ADDED
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env rake
2
+
3
+ require 'bundler/gem_tasks'
4
+
5
+ require 'rspec/core/rake_task'
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task :default => :spec
9
+ task :test => :spec
10
+
11
+ require 'yard'
12
+ namespace :doc do
13
+ YARD::Rake::YardocTask.new do |task|
14
+ task.files = ['LICENSE.md', 'lib/**/*.rb']
15
+ task.options = ['--markup', 'markdown']
16
+ end
17
+ end
data/em-logger.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ # encoding: utf-8
2
+ require File.expand_path('../lib/em-logger/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.name = 'em-logger'
6
+ gem.version = EventMachine::Logger::VERSION
7
+ gem.homepage = 'https://github.com/spagalloco/em-logger'
8
+
9
+ gem.author = "Steve Agalloco"
10
+ gem.email = 'steve.agalloco@gmail.com'
11
+ gem.description = 'An experimental logger class for EventMachine applications.'
12
+ gem.summary = 'An experimental logger class for EventMachine applications.'
13
+
14
+ gem.add_dependency "eventmachine", ">= 0.12.10"
15
+
16
+ gem.add_development_dependency 'rake', '~> 0.9'
17
+ gem.add_development_dependency 'rdiscount', '~> 1.6'
18
+ gem.add_development_dependency 'rspec', '~> 2.7'
19
+ gem.add_development_dependency 'simplecov', '~> 0.5'
20
+ gem.add_development_dependency 'yard', '~> 0.7'
21
+ gem.add_development_dependency 'em-ventually'
22
+
23
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{|f| File.basename(f)}
24
+ gem.files = `git ls-files`.split("\n")
25
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
26
+
27
+ gem.require_paths = ['lib']
28
+ end
@@ -0,0 +1,90 @@
1
+ require 'eventmachine'
2
+
3
+ module EventMachine
4
+ class LogMessage
5
+ attr_accessor :severity, :message, :progname
6
+
7
+ def initialize(severity, message=nil, progname=nil)
8
+ @severity = severity
9
+ @message = message
10
+ @progname = progname
11
+ end
12
+
13
+ end
14
+
15
+ class Logger
16
+
17
+ attr_reader :logger
18
+ attr_reader :logger_queue
19
+
20
+ def initialize(logger)
21
+ @logger = logger
22
+ @logger_queue = EM::Queue.new
23
+
24
+ queue_processor = Proc.new do |log_message|
25
+ @logger.add(log_message.severity, log_message.message, log_message.progname)
26
+ EM.defer { @logger_queue.pop(&queue_processor) }
27
+ end
28
+
29
+ @logger_queue.pop(&queue_processor)
30
+ end
31
+
32
+ def add(severity, message = nil, progname = nil, &block)
33
+ return true if severity < @logger.level
34
+ if message.nil?
35
+ if block_given?
36
+ message = yield
37
+ else
38
+ message = progname
39
+ progname = @logger.progname
40
+ end
41
+ end
42
+ @logger_queue.push(LogMessage.new(severity, message, progname))
43
+ end
44
+ alias log add
45
+
46
+ # Log a +DEBUG+ message.
47
+ def debug(progname = nil, &block)
48
+ add(::Logger::DEBUG, nil, progname, &block)
49
+ end
50
+
51
+ # Log a +INFO+ message.
52
+ def info(progname = nil, &block)
53
+ add(::Logger::INFO, nil, progname, &block)
54
+ end
55
+
56
+ # Log a +WARN+ message.
57
+ def warn(progname = nil, &block)
58
+ add(::Logger::WARN, nil, progname, &block)
59
+ end
60
+
61
+ # Log a +ERROR+ message.
62
+ def error(progname = nil, &block)
63
+ add(::Logger::ERROR, nil, progname, &block)
64
+ end
65
+
66
+ # Log a +FATAL+ message.
67
+ def fatal(progname = nil, &block)
68
+ add(::Logger::FATAL, nil, progname, &block)
69
+ end
70
+
71
+ # Log an +UNKNOWN+ message.
72
+ def unknown(progname = nil, &block)
73
+ add(::Logger::UNKNOWN, nil, progname, &block)
74
+ end
75
+
76
+ def <<(data)
77
+ @logger_queue.push(LogMessage.new(nil,data))
78
+ end
79
+
80
+ def method_missing(method, *args, &block)
81
+ return super unless @logger.respond_to?(method)
82
+ @logger.send(method, *args, &block)
83
+ end
84
+
85
+ def respond_to?(method, include_private = false)
86
+ @logger.respond_to?(method, include_private) || super(method, include_private)
87
+ end
88
+
89
+ end
90
+ end
@@ -0,0 +1,5 @@
1
+ module EventMachine
2
+ class Logger
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
data/lib/em-logger.rb ADDED
@@ -0,0 +1 @@
1
+ require 'em-logger/logger'
@@ -0,0 +1,104 @@
1
+ require 'spec_helper'
2
+
3
+ describe EventMachine::Logger do
4
+ let(:loggr) { ::Logger.new(STDOUT) }
5
+
6
+ context 'creating' do
7
+ it 'instatiates with a logger' do
8
+ EM.run_block do
9
+ eml = EventMachine::Logger.new(loggr)
10
+ eml.logger.should eq(loggr)
11
+ end
12
+ end
13
+
14
+ it 'starts the queue processor' do
15
+ eml = EventMachine::Logger.new(loggr)
16
+ loggr.should_receive('add').once
17
+
18
+ EM.run_block do
19
+ eml.debug('this is a test')
20
+ EM.stop
21
+ end
22
+ end
23
+ end
24
+
25
+ context 'log statements' do
26
+ let(:eml) { EventMachine::Logger.new(loggr) }
27
+
28
+ %w(debug info warn error fatal).each do |l|
29
+ describe "##{l}" do
30
+ it 'pushes the log message onto the logger_queue' do
31
+ eml.logger_queue.should_receive('push').once
32
+ eml.send("#{l}", 'this is a test')
33
+ end
34
+ end
35
+ end
36
+
37
+ describe "#unknown" do
38
+ it 'pushes the log message onto the logger_queue' do
39
+ eml.logger_queue.should_receive('push').once
40
+ eml.unknown('this is a test')
41
+ end
42
+ end
43
+
44
+ describe '#<<' do
45
+ it 'pushes the log message onto the logger_queue' do
46
+ eml.logger_queue.should_receive('push').once
47
+ eml << 'this is a test'
48
+ end
49
+ end
50
+ end
51
+
52
+ context 'queuing' do
53
+ describe '#add' do
54
+ context 'when logging below the defined level' do
55
+ it 'pushes the log message onto the logger_queue' do
56
+ loggr.level = ::Logger::WARN
57
+ eml = EventMachine::Logger.new(loggr)
58
+ eml.logger_queue.should_not_receive('push')
59
+ eml.add(::Logger::INFO, 'this is a test').should be_true
60
+ end
61
+ end
62
+
63
+ context 'when logging above the defined level' do
64
+ it 'pushes the log message onto the logger_queue' do
65
+ eml = EventMachine::Logger.new(loggr)
66
+ eml.logger_queue.should_receive('push').once
67
+ eml.add(::Logger::INFO, 'this is a test')
68
+ end
69
+ end
70
+
71
+ context 'when using a block' do
72
+ it 'evaluates the block' do
73
+ eml = EventMachine::Logger.new(loggr)
74
+ eml.logger_queue.should_receive('push').once
75
+ eml.add(::Logger::INFO) { 'ohai' }
76
+ end
77
+ end
78
+ end
79
+ end
80
+
81
+ context 'delegating to logger' do
82
+ describe 'method_missing' do
83
+ it 'passes through to the underlying logger' do
84
+ eml = EventMachine::Logger.new(loggr)
85
+ loggr.should_receive("level").once
86
+ eml.level
87
+ end
88
+
89
+ it 'returns the underlying loggers value' do
90
+ loggr.level = ::Logger::WARN
91
+ eml = EventMachine::Logger.new(loggr)
92
+ eml.level.should eq(::Logger::WARN)
93
+ end
94
+ end
95
+
96
+ describe 'respond_to?' do
97
+ it 'responds to methods defined on the logger' do
98
+ eml = EventMachine::Logger.new(loggr)
99
+ eml.respond_to?('level').should be_true
100
+ end
101
+ end
102
+ end
103
+
104
+ end
@@ -0,0 +1,6 @@
1
+ # encoding: utf-8
2
+ require 'simplecov'
3
+
4
+ require 'em-logger'
5
+ require 'rspec'
6
+ require 'logger'
metadata ADDED
@@ -0,0 +1,140 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: em-logger
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Steve Agalloco
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-02-25 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: eventmachine
16
+ requirement: &70252667255620 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 0.12.10
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70252667255620
25
+ - !ruby/object:Gem::Dependency
26
+ name: rake
27
+ requirement: &70252667255100 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: '0.9'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70252667255100
36
+ - !ruby/object:Gem::Dependency
37
+ name: rdiscount
38
+ requirement: &70252667254500 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: '1.6'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70252667254500
47
+ - !ruby/object:Gem::Dependency
48
+ name: rspec
49
+ requirement: &70252667253740 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '2.7'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70252667253740
58
+ - !ruby/object:Gem::Dependency
59
+ name: simplecov
60
+ requirement: &70252667252980 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ~>
64
+ - !ruby/object:Gem::Version
65
+ version: '0.5'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *70252667252980
69
+ - !ruby/object:Gem::Dependency
70
+ name: yard
71
+ requirement: &70252667252440 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ~>
75
+ - !ruby/object:Gem::Version
76
+ version: '0.7'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *70252667252440
80
+ - !ruby/object:Gem::Dependency
81
+ name: em-ventually
82
+ requirement: &70252667252060 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: *70252667252060
91
+ description: An experimental logger class for EventMachine applications.
92
+ email: steve.agalloco@gmail.com
93
+ executables: []
94
+ extensions: []
95
+ extra_rdoc_files: []
96
+ files:
97
+ - .gemtest
98
+ - .gitignore
99
+ - .rspec
100
+ - .simplecov
101
+ - .travis.yml
102
+ - .yardopts
103
+ - Gemfile
104
+ - LICENSE.md
105
+ - README.md
106
+ - Rakefile
107
+ - em-logger.gemspec
108
+ - lib/em-logger.rb
109
+ - lib/em-logger/logger.rb
110
+ - lib/em-logger/version.rb
111
+ - spec/logger_spec.rb
112
+ - spec/spec_helper.rb
113
+ homepage: https://github.com/spagalloco/em-logger
114
+ licenses: []
115
+ post_install_message:
116
+ rdoc_options: []
117
+ require_paths:
118
+ - lib
119
+ required_ruby_version: !ruby/object:Gem::Requirement
120
+ none: false
121
+ requirements:
122
+ - - ! '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ required_rubygems_version: !ruby/object:Gem::Requirement
126
+ none: false
127
+ requirements:
128
+ - - ! '>='
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ requirements: []
132
+ rubyforge_project:
133
+ rubygems_version: 1.8.16
134
+ signing_key:
135
+ specification_version: 3
136
+ summary: An experimental logger class for EventMachine applications.
137
+ test_files:
138
+ - spec/logger_spec.rb
139
+ - spec/spec_helper.rb
140
+ has_rdoc: