mini_logger 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -21,9 +21,9 @@ The latest stable version is published in rubygems.org.
21
21
  :log_level => MiniLogger::DEBUG )
22
22
 
23
23
  MiniLogger.debug( "#{big_process()}" ) if MiniLogger.debug?
24
+ MiniLogger.level = MiniLogger::INFO
24
25
 
25
26
  == TODO
26
- * ???
27
27
 
28
28
  == License
29
29
 
data/lib/mini_logger.rb CHANGED
@@ -5,63 +5,60 @@ require 'logger'
5
5
  module MiniLogger
6
6
  extend self
7
7
 
8
- LOG_LEVEL_MAP = {
9
- :debug =>::Logger::DEBUG,
10
- :info =>::Logger::INFO,
11
- :warn =>::Logger::WARN,
12
- :error =>::Logger::ERROR,
13
- :faltal =>::Logger::FATAL
8
+ LLM = {
9
+ :debug =>Logger::DEBUG,
10
+ :info =>Logger::INFO,
11
+ :warn =>Logger::WARN,
12
+ :error =>Logger::ERROR,
13
+ :faltal =>Logger::FATAL
14
14
  }
15
15
 
16
- DEBUG = LOG_LEVEL_MAP[:debug]
17
- INFO = LOG_LEVEL_MAP[:info]
18
- WARN = LOG_LEVEL_MAP[:warn]
19
- ERROR = LOG_LEVEL_MAP[:error]
20
- FATAL = LOG_LEVEL_MAP[:fatal]
21
-
22
- DEFAULT_LOGCHANNEL = STDERR
23
- DEFAULT_LOGLEVEL = LOG_LEVEL_MAP[:info]
24
- DEFAULT_DATETIME_FORMAT = "%Y/%m/%d %H:%M:%S"
25
-
26
-
27
- def configure( atts = {} )
28
-
29
- log_channel = atts[:log_channel] ? atts[:log_channel] : DEFAULT_LOGCHANNEL
30
- log_level = LOG_LEVEL_MAP.has_value?( atts[:log_level] ) ? atts[:log_level] : DEFAULT_LOGLEVEL
31
- dt_format = atts[:dt_format] ? atts[:dt_format] : DEFAULT_DATETIME_FORMAT
32
-
33
- @logger ||= ::Logger.new( log_channel )
34
- @logger.level ||= log_level
35
- @logger.datetime_format ||= dt_format
16
+ DEBUG = :debug
17
+ INFO = :info
18
+ WARN = :warn
19
+ ERROR = :error
20
+ FATAL = :fatal
21
+
22
+ private
23
+ def validate_log_level?( log_level )
24
+ LLM.has_key?( log_level )
25
+ end
26
+
27
+ def get_log_level( log_level )
28
+ LLM[log_level]
29
+ end
30
+
31
+
32
+ public
33
+ def configure( atts = { } )
36
34
 
35
+ @logger = Logger.new( atts[:log_channel] ? atts[:log_channel] : STDERR )
36
+ @logger.level = validate_log_level?( atts[:log_level] ) ? get_log_level( atts[:log_level] ) : Logger::INFO
37
37
  self
38
38
  end
39
39
 
40
-
41
- def level( )
42
- self.configure unless @logger
43
-
40
+ def level( )
41
+ @logger || configure
44
42
  @logger.level
45
- end
46
-
43
+ end
47
44
 
48
45
  def level=( new_log_level )
49
46
 
50
- self.configure unless @logger
51
-
52
- if LOG_LEVEL_MAP.has_value?( new_log_level )
53
- @logger.level = new_log_level
54
- else
47
+ @logger || configure
48
+
49
+ if( validate_log_level?( new_log_level ) )
50
+ @logger.level = get_log_level( new_log_level )
51
+ else
55
52
  raise ArgumentError.new( "Bad log level: #{new_log_level}" )
56
- end
53
+ end
57
54
  end
58
55
 
59
-
60
56
  def method_missing( method, *arguments, &block )
61
57
 
62
- self.configure unless @logger
58
+ @logger || configure
63
59
 
64
- return unless( [:debug, :debug?, :info, :info?, :warn, :warn?, :error, :error?, :fatal].include?( method ) )
65
- @logger.send( method, *arguments, &block )
60
+ if( [ :debug, :debug?, :info, :info?, :warn, :warn?, :error, :error?, :fatal ].include?( method ) )
61
+ @logger.send( method, *arguments, &block )
62
+ end
66
63
  end
67
64
  end
data/lib/version.rb CHANGED
@@ -3,7 +3,7 @@ module MiniLogger
3
3
  INFO = {
4
4
  :major =>0,
5
5
  :minor =>4,
6
- :patch =>0
6
+ :patch =>1
7
7
  }
8
8
 
9
9
  NAME = 'mini_logger'
@@ -14,6 +14,10 @@ class TestMiniLogger < Test::Unit::TestCase
14
14
  @mini_logger_debug = MiniLogger.configure( :log_channel=>"/dev/null", :log_level=>MiniLogger::DEBUG )
15
15
  end
16
16
 
17
+ should "a info log level" do
18
+ assert( MiniLogger.configure.info? )
19
+ end
20
+
17
21
  should "write a debug line" do
18
22
  assert( @mini_logger_debug.debug( "debug" ) )
19
23
  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.4.0
5
+ version: 0.4.1
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-14 00:00:00 +01:00
13
+ date: 2011-03-16 00:00:00 +01:00
14
14
  default_executable:
15
15
  dependencies: []
16
16