growl-logger 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.rdoc ADDED
@@ -0,0 +1,75 @@
1
+ = growl-logger
2
+
3
+ http://github.com/jugyo/growl-logger
4
+
5
+ == DESCRIPTION:
6
+
7
+ Logger using Growl.
8
+
9
+ == FEATURES/PROBLEMS:
10
+
11
+ * You can output logs as growl notification so easily!
12
+
13
+ That's all.
14
+
15
+ == SYNOPSIS:
16
+
17
+ require 'rubygems'
18
+ require 'growl-logger'
19
+
20
+ log = GrowlLogger.new :level => Logger::DEBUG
21
+
22
+ log.debug('debug')
23
+ log.info('info')
24
+ log.warn('warn')
25
+ log.error('error')
26
+ log.fatal('fatal')
27
+
28
+ == SCREENSHOTS:
29
+
30
+ http://farm4.static.flickr.com/3632/3384656890_446c1cd6e2_o.png
31
+
32
+ http://farm4.static.flickr.com/3639/3383843581_8e97858fd7_o.png
33
+
34
+ == REQUIREMENTS:
35
+
36
+ * growlnotify command
37
+
38
+ or
39
+
40
+ * ruby-growl
41
+
42
+ === See also
43
+
44
+ * http://growl.info/documentation/growlnotify.php
45
+ * http://segment7.net/projects/ruby/growl/
46
+
47
+ == INSTALL:
48
+
49
+ gem source -a http://gems.github.com
50
+ sudo gem install jugyo-growl-logger
51
+
52
+ == LICENSE:
53
+
54
+ (The MIT License)
55
+
56
+ Copyright (c) 2008-2009 jugyo
57
+
58
+ Permission is hereby granted, free of charge, to any person obtaining
59
+ a copy of this software and associated documentation files (the
60
+ 'Software'), to deal in the Software without restriction, including
61
+ without limitation the rights to use, copy, modify, merge, publish,
62
+ distribute, sublicense, and/or sell copies of the Software, and to
63
+ permit persons to whom the Software is furnished to do so, subject to
64
+ the following conditions:
65
+
66
+ The above copyright notice and this permission notice shall be
67
+ included in all copies or substantial portions of the Software.
68
+
69
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
70
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
71
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
72
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
73
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
74
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
75
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,38 @@
1
+ $:.unshift File.dirname(__FILE__) + '/lib/'
2
+ require 'growl-logger'
3
+ require 'spec/rake/spectask'
4
+
5
+ desc 'run all specs'
6
+ Spec::Rake::SpecTask.new do |t|
7
+ t.spec_files = FileList['spec/**/*_spec.rb']
8
+ t.spec_opts = ['-c']
9
+ end
10
+
11
+ desc 'Generate gemspec'
12
+ task :gemspec do |t|
13
+ open('growl-logger.gemspec', "wb" ) do |file|
14
+ file << <<-EOS
15
+ Gem::Specification.new do |s|
16
+ s.name = 'growl-logger'
17
+ s.version = '#{GrowlLogger::VERSION}'
18
+ s.summary = "Logger using Growl."
19
+ s.description = "Logger using Growl. You can output logs as growl notification so easily!"
20
+ s.files = %w( #{Dir['lib/**/*.rb'].join(' ')}
21
+ #{Dir['spec/**/*.rb'].join(' ')}
22
+ #{Dir['examples/**/*.rb'].join(' ')}
23
+ README.rdoc
24
+ Rakefile )
25
+ s.author = 'jugyo'
26
+ s.email = 'jugyo.org@gmail.com'
27
+ s.homepage = 'http://github.com/jugyo/growl-logger'
28
+ s.rubyforge_project = 'growl-logger'
29
+ end
30
+ EOS
31
+ end
32
+ puts "Generate gemspec"
33
+ end
34
+
35
+ desc 'Generate gem'
36
+ task :gem => :gemspec do |t|
37
+ system 'gem', 'build', 'growl-logger.gemspec'
38
+ end
@@ -0,0 +1,11 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require File.dirname(__FILE__) + '/../lib/growl-logger'
4
+
5
+ log = GrowlLogger.new
6
+
7
+ log.debug 'debug'
8
+ log.info 'info'
9
+ log.warn 'warn'
10
+ log.error 'error'
11
+ log.fatal 'fatal'
@@ -0,0 +1,60 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'rubygems'
3
+ require 'logger'
4
+
5
+ class GrowlLogger < Logger
6
+ VERSION = '0.1.2'
7
+
8
+ def initialize(args = {})
9
+ super(GrowlLogger::LogDevice.new(
10
+ args[:name] || 'growl-logger',
11
+ args[:growlnotify] || false
12
+ ))
13
+ self.level = args[:level] if args[:level]
14
+ self.datetime_format = args[:datetime_format] || '%X'
15
+ self.formatter = lambda { |severity, time, progname, message| "#{severity}: #{message}" }
16
+ end
17
+
18
+ class LogDevice
19
+ def initialize(name, growlnotify_mode = true, &block)
20
+ @name = name
21
+ @growlnotify_mode = growlnotify_mode
22
+ unless @growlnotify_mode
23
+ begin
24
+ require 'ruby-growl'
25
+ @growl = Growl.new "localhost", @name, ["log"]
26
+ rescue LoadError
27
+ end
28
+ end
29
+ @formatter = block if block_given?
30
+ end
31
+
32
+ def write(message)
33
+ priority = get_priority(message)
34
+ if @growl
35
+ @growl.notify "log", @name, message, priority
36
+ else
37
+ system 'growlnotify', @name, '-p', priority.to_s, '-m', message
38
+ end
39
+ end
40
+
41
+ def get_priority(message)
42
+ case message
43
+ when /^DEBUG/
44
+ -2
45
+ when /^INFO/
46
+ -1
47
+ when /^WARN/
48
+ 0
49
+ when /^ERROR/
50
+ 1
51
+ when /^FATAL/
52
+ 2
53
+ else
54
+ 0
55
+ end
56
+ end
57
+
58
+ def close;end
59
+ end
60
+ end
@@ -0,0 +1,58 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require File.dirname(__FILE__) + '/spec_helper'
4
+
5
+ describe GrowlLogger do
6
+ it 'init' do
7
+ logger = GrowlLogger.new
8
+
9
+ logger.level.should == Logger::DEBUG
10
+ logdev = logger.instance_eval{@logdev}.dev
11
+ logdev.class.should == GrowlLogger::LogDevice
12
+ logdev.instance_eval{@name}.should == 'growl-logger'
13
+ logger.datetime_format.should == '%X'
14
+ logger.formatter.call('DEBUG', Time.now, 'foo', 'message').should == "DEBUG: message"
15
+ logdev.instance_eval{@growlnotify_mode}.should == false
16
+ end
17
+
18
+ it 'init with name option' do
19
+ logger = GrowlLogger.new :name => 'foo'
20
+ logdev = logger.instance_eval{@logdev}.dev
21
+ logdev.instance_eval{@name}.should == 'foo'
22
+ end
23
+
24
+ it 'init with growlnotify option' do
25
+ logger = GrowlLogger.new :growlnotify => true
26
+ logdev = logger.instance_eval{@logdev}.dev
27
+ logdev.instance_eval{@growlnotify_mode}.should == true
28
+ end
29
+
30
+ it 'init with datetime_format option' do
31
+ logger = GrowlLogger.new :datetime_format => '%H'
32
+ logger.datetime_format.should == '%H'
33
+ end
34
+
35
+ it 'call log' do
36
+ logger = GrowlLogger.new
37
+ logdev = logger.instance_eval{@logdev}.dev
38
+ logdev.should_receive(:write).with('DEBUG: test')
39
+ logger.debug('test')
40
+ end
41
+
42
+ it 'call log that under threshold' do
43
+ logger = GrowlLogger.new :level => Logger::WARN
44
+ logdev = logger.instance_eval{@logdev}.dev
45
+ logdev.should_not_receive(:write)
46
+ logger.debug('test')
47
+ logger.info('test')
48
+ end
49
+
50
+ it 'get_priority' do
51
+ logdev = GrowlLogger::LogDevice.new('foo')
52
+ logdev.get_priority('DEBUG: test').should == -2
53
+ logdev.get_priority('INFO: test').should == -1
54
+ logdev.get_priority('WARN: test').should == 0
55
+ logdev.get_priority('ERROR: test').should == 1
56
+ logdev.get_priority('FATAL: test').should == 2
57
+ end
58
+ end
@@ -0,0 +1,4 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ $:.unshift(File.dirname(__FILE__) + '/../lib')
4
+ require 'growl-logger'
metadata ADDED
@@ -0,0 +1,58 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: growl-logger
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - jugyo
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-03-26 00:00:00 +09:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: Logger using Growl. You can output logs as growl notification so easily!
17
+ email: jugyo.org@gmail.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - lib/growl-logger.rb
26
+ - spec/growl-logger_spec.rb
27
+ - spec/spec_helper.rb
28
+ - examples/example.rb
29
+ - README.rdoc
30
+ - Rakefile
31
+ has_rdoc: false
32
+ homepage: http://github.com/jugyo/growl-logger
33
+ post_install_message:
34
+ rdoc_options: []
35
+
36
+ require_paths:
37
+ - lib
38
+ required_ruby_version: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: "0"
43
+ version:
44
+ required_rubygems_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: "0"
49
+ version:
50
+ requirements: []
51
+
52
+ rubyforge_project: growl-logger
53
+ rubygems_version: 1.3.1
54
+ signing_key:
55
+ specification_version: 2
56
+ summary: Logger using Growl.
57
+ test_files: []
58
+