mini_logger 0.2.5 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/mini_logger.rb CHANGED
@@ -11,46 +11,34 @@ module MiniLogger
11
11
  ERROR = ::Logger::ERROR
12
12
  FATAL = ::Logger::FATAL
13
13
 
14
- DEFAULT_LOGCHANNEL = STDERR
15
- DEFAULT_LOGLEVEL = DEBUG
16
- VALID_METHODS = [ :debug, :info, :warn, :error, :fatal ]
14
+ DEFAULT_LOGCHANNEL = STDERR
15
+ DEFAULT_LOGLEVEL = DEBUG
16
+ DEFAULT_DATETIME_FORMAT = "%Y/%m/%d %H:%M:%S"
17
17
 
18
18
 
19
19
  def configure( atts = {} )
20
20
 
21
- atts[:log_channel] ||= DEFAULT_LOGCHANNEL
22
- atts[:log_channel] ||= DEFAULT_LOGLEVEL
23
-
24
- @logger ||= ::Logger.new( atts[:log_channel] )
25
- @logger.level ||= atts[:log_level]
21
+ @logger ||= ::Logger.new( atts[:log_channel] ? atts[:log_channel] : DEFAULT_LOGCHANNEL )
22
+ @logger.level = atts[:log_level] ? atts[:log_level] : DEFAULT_LOGLEVEL
23
+ @logger.datetime_format = atts[:dt_format] ? atts[:dt_format] : DEFAULT_DATETIME_FORMAT
26
24
 
27
25
  self
28
26
  end
29
27
 
30
- def debug?
31
- (@logger.level == DEBUG)
32
- end
33
-
34
- def level
35
- @logger.level
36
- end
37
-
38
-
39
- def level=( new_level )
40
- @logger.level=new_level
41
- end
42
-
43
28
 
44
29
  def method_missing( method, *arguments, &block )
45
30
 
46
31
  self.configure unless @logger
47
32
 
48
- if( VALID_METHODS.include?( method ) )
49
- if( block_given? )
50
- @logger.send( method, arguments.length == 1 ? arguments[0] : arguments, block )
33
+ return unless( [:debug, :debug?, :info, :info?, :warn, :warn?, :error, :error?, :fatal].include?( method ) )
34
+
35
+ case arguments.length
36
+ when 0
37
+ @logger.send( method )
38
+ when 1
39
+ @logger.send( method, arguments[0] )
51
40
  else
52
- @logger.send( method, arguments.length == 1 ? arguments[0] : arguments )
53
- end
41
+ @logger.send( method, arguments )
54
42
  end
55
43
  end
56
44
  end
data/lib/version.rb CHANGED
@@ -2,8 +2,8 @@ module MiniLogger
2
2
  module Version
3
3
  INFO = {
4
4
  :major =>0,
5
- :minor =>2,
6
- :patch =>5
5
+ :minor =>3,
6
+ :patch =>0
7
7
  }
8
8
 
9
9
  NAME = 'mini_logger'
@@ -11,13 +11,9 @@ class TestMiniLogger < Test::Unit::TestCase
11
11
  context "A Default Logger" do
12
12
 
13
13
  setup do
14
- MiniLogger.configure( :log_channel=>STDOUT, :log_level=>MiniLogger::DEBUG )
14
+ MiniLogger.configure( :log_channel=>"/dev/null", :log_level=>MiniLogger::DEBUG )
15
15
  end
16
16
 
17
- should "be level DEBUG" do
18
- assert( MiniLogger.debug? )
19
- end
20
-
21
17
  should "write a debug line" do
22
18
  assert( MiniLogger.debug( "debug" ) )
23
19
  end
@@ -38,9 +34,24 @@ class TestMiniLogger < Test::Unit::TestCase
38
34
  assert( MiniLogger.fatal( "fatal" ) )
39
35
  end
40
36
 
41
- should "change log level" do
42
- MiniLogger.level = MiniLogger::ERROR
43
- assert_equal( MiniLogger.level, MiniLogger::ERROR )
37
+ should "log level ERROR" do
38
+ MiniLogger.configure( :log_level=>MiniLogger::ERROR )
39
+ assert( MiniLogger.error? )
40
+ end
41
+
42
+ should "log level WARN" do
43
+ MiniLogger.configure( :log_level=>MiniLogger::WARN )
44
+ assert( MiniLogger.warn? )
45
+ end
46
+
47
+ should "log level INFO" do
48
+ MiniLogger.configure( :log_level=>MiniLogger::INFO )
49
+ assert( MiniLogger.info? )
50
+ end
51
+
52
+ should "log level DEBUG" do
53
+ MiniLogger.configure( :log_level=>MiniLogger::DEBUG )
54
+ assert( MiniLogger.debug? )
44
55
  end
45
56
  end
46
57
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: mini_logger
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.2.5
5
+ version: 0.3.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Javier Juarez
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-03-05 00:00:00 +01:00
13
+ date: 2011-03-06 00:00:00 +01:00
14
14
  default_executable:
15
15
  dependencies: []
16
16