fizx-loggable 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/README +22 -0
  2. data/lib/loggable.rb +54 -0
  3. data/test/test_loggable.rb +35 -0
  4. metadata +56 -0
data/README ADDED
@@ -0,0 +1,22 @@
1
+ Simple logging mix-in for Ruby.
2
+
3
+ Features:
4
+
5
+ 1. Global logger, overrideable at the class level.
6
+ 2. Logging methods mixed into your classes.
7
+
8
+ >> require "loggable"
9
+ => true
10
+ >> class Foo
11
+ >> include Loggable
12
+ >> end
13
+ => Foo
14
+ >> Foo.logger
15
+ => #<Logger:0x5ce874 @form... >
16
+ >> f = Foo.new
17
+ => #<Foo:0x5c5788>
18
+ >> f.info "info goes here"
19
+ I, [2008-09-26T16:41:20.780745 #14792] INFO -- : info goes here
20
+ => true
21
+ >> Loggable.default
22
+ => #<Logger:0x5ce874 @form... >
data/lib/loggable.rb ADDED
@@ -0,0 +1,54 @@
1
+ require "logger"
2
+ module Loggable
3
+ module ClassMethods
4
+ def logger
5
+ @logger || Loggable.default
6
+ end
7
+
8
+ def logger=(l)
9
+ @logger = l
10
+ end
11
+
12
+ alias_method :l, :logger
13
+ alias_method :l=, :logger=
14
+ end
15
+
16
+ module LoggableMethods
17
+ def default
18
+ @default_logger ||= Logger.new(STDOUT)
19
+ end
20
+ def default=(l)
21
+ @default_loffer = l
22
+ end
23
+ end
24
+
25
+ def l
26
+ self.class.logger
27
+ end
28
+
29
+ def fatal(*a, &b)
30
+ l.fatal(*a, &b)
31
+ end
32
+
33
+ def error(*a, &b)
34
+ l.error(*a, &b)
35
+ end
36
+
37
+ def warn(*a, &b)
38
+ l.warn(*a, &b)
39
+ end
40
+
41
+ def info(*a, &b)
42
+ l.info(*a, &b)
43
+ end
44
+
45
+ def debug(*a, &b)
46
+ l.debug(*a, &b)
47
+ end
48
+
49
+ def self.included(klass)
50
+ klass.extend(ClassMethods)
51
+ end
52
+
53
+ extend(LoggableMethods)
54
+ end
@@ -0,0 +1,35 @@
1
+ require "test/unit"
2
+ require "rubygems"
3
+ require "mocha"
4
+ require File.dirname(__FILE__) + "/../lib/loggable"
5
+
6
+ class TestLoggable < Test::Unit::TestCase
7
+ include Loggable
8
+
9
+ def test_calls
10
+ l = mock()
11
+ l.expects(:fatal).with("fatal").times(2)
12
+ l.expects(:error).with("error").times(2)
13
+ l.expects(:warn).with("warn").times(2)
14
+ l.expects(:info).with("info").times(2)
15
+ l.expects(:debug).with("debug").times(2)
16
+
17
+ assert_equal Loggable.default, self.class.logger
18
+ assert_kind_of Logger, Loggable.default
19
+
20
+ self.class.logger = l
21
+ assert_equal l, self.class.logger
22
+
23
+ fatal "fatal"
24
+ error "error"
25
+ warn "warn"
26
+ info "info"
27
+ debug "debug"
28
+
29
+ l.fatal "fatal"
30
+ l.error "error"
31
+ l.warn "warn"
32
+ l.info "info"
33
+ l.debug "debug"
34
+ end
35
+ end
metadata ADDED
@@ -0,0 +1,56 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fizx-loggable
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Kyle Maxwell
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-08-26 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: include Loggable!
17
+ email: kyle@kylemaxwell.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README
24
+ files:
25
+ - README
26
+ - lib/loggable.rb
27
+ - test/test_loggable.rb
28
+ has_rdoc: true
29
+ homepage: http://github.com/fizx/robots
30
+ post_install_message:
31
+ rdoc_options:
32
+ - --main
33
+ - README
34
+ require_paths:
35
+ - lib
36
+ required_ruby_version: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: "0"
41
+ version:
42
+ required_rubygems_version: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: "0"
47
+ version:
48
+ requirements: []
49
+
50
+ rubyforge_project:
51
+ rubygems_version: 1.2.0
52
+ signing_key:
53
+ specification_version: 2
54
+ summary: Easier mixins of logging
55
+ test_files: []
56
+