lager 0.0.1.2 → 0.0.1.3

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.md +22 -0
  2. data/VERSION +1 -1
  3. data/lib/lager.rb +27 -12
  4. metadata +1 -1
data/README.md CHANGED
@@ -1,3 +1,25 @@
1
1
  Lager
2
2
  =====
3
3
  Lager is a logging mixin. It is designed to add class methods for logging
4
+
5
+ How it works
6
+ ------------
7
+ Lager is a mixin. By design, it mixes in class methods.
8
+
9
+ require 'lager'
10
+
11
+ class Foo
12
+ extend Lager
13
+ end
14
+
15
+ Now, within Foo, you can use the class variable @@lager for logging.
16
+
17
+ class Foo
18
+ extend Lager
19
+
20
+ def self.bar(baz)
21
+ lager unless defined?(@@lager)
22
+ unless baz.is_a?(String)
23
+ @@lager.debug { "baz: #{baz} is not a string" }
24
+ end
25
+ end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1.2
1
+ 0.0.1.3
data/lib/lager.rb CHANGED
@@ -1,7 +1,22 @@
1
1
  require 'logger'
2
2
 
3
3
  module Lager
4
- def self.log_to dest=nil
4
+ def self.version
5
+ vpath = File.join(File.dirname(__FILE__), '..', 'VERSION')
6
+ File.read(vpath).chomp
7
+ end
8
+
9
+
10
+ # this module is meant to be mixed in at a class level
11
+ # e.g.
12
+ # class Foo
13
+ # extend Lager
14
+ # ...
15
+ # end
16
+ #
17
+ # Foo.lager
18
+ #
19
+ def lager dest=nil
5
20
  case dest
6
21
  when nil, 'stderr', 'STDERR'
7
22
  dest = $stderr
@@ -14,27 +29,27 @@ module Lager
14
29
  else
15
30
  raise "unable to log_to #{dest} (#{dest.class})"
16
31
  end
17
- if defined?(@@log)
32
+ if defined?(@@lager)
18
33
  l = Logger.new dest
19
- l.formatter = @@log.formatter
20
- l.level = @@log.level
21
- @@log = l
34
+ l.formatter = @@lager.formatter
35
+ l.level = @@lager.level
36
+ @@lager = l
22
37
  else
23
- @@log = Logger.new dest
24
- @@log.formatter = proc { |sev, time, progname, msg|
38
+ @@lager = Logger.new dest
39
+ @@lager.formatter = proc { |sev, time, progname, msg|
25
40
  line = "[#{time.strftime('%Y-%m-%d %H:%M:%S')}] #{sev.to_s.upcase}: "
26
41
  line << "(#{progname}) " if progname
27
42
  line << msg << "\n"
28
43
  }
29
- @@log.level = Logger::WARN
44
+ @@lager.level = Logger::WARN
30
45
  end
31
- @@log
46
+ @@lager
32
47
  end
33
48
 
34
- def self.log_level=(sym)
35
- log_to unless defined?(@@log)
49
+ def log_level=(sym)
50
+ log_to unless defined?(@@lager)
36
51
  level = Logger.const_get(sym.to_s.upcase)
37
52
  raise "unknown log level #{sym}" unless level
38
- @@log.level = level
53
+ @@lager.level = level
39
54
  end
40
55
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lager
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1.2
4
+ version: 0.0.1.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: