logjam 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. metadata +2 -3
  2. data/lib/logjam/logjam-original.rb +0 -129
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: logjam
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.2
5
+ version: 0.0.3
6
6
  platform: ruby
7
7
  authors:
8
8
  - Black North
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2012-02-11 00:00:00 Z
13
+ date: 2012-02-12 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: json
@@ -33,7 +33,6 @@ extra_rdoc_files: []
33
33
 
34
34
  files:
35
35
  - lib/logjam/logjam_logger.rb
36
- - lib/logjam/logjam-original.rb
37
36
  - lib/logjam/logjam.rb
38
37
  - lib/logjam/exceptions.rb
39
38
  - lib/logjam.rb
@@ -1,129 +0,0 @@
1
- #! /usr/bin/env ruby
2
- #
3
- # Copyright (c), 2012 Peter Wood
4
- # See the license.txt for details of the licensing of the code in this file.
5
-
6
- require 'logger'
7
-
8
- # This module defines the name space to be used by all code within the
9
- # LogJam library.
10
- module LogJam
11
- # Module constants.
12
- LOG_FILE = :log_file
13
- LOG_ROLL = :log_roll_period
14
- LOG_LEVEL = :log_level
15
-
16
- # Module wide property declarations.
17
- @@logjam_logger = nil
18
-
19
- # This method fetches the module logger, initializing it and creating it if
20
- # it doesn't yet exist.
21
- #
22
- # ==== Parameters
23
- # configuration:: The configuration to use in setting up the logging.
24
- # Defaults to nil to indicate the creation of a logger based
25
- # on STDOUT.
26
- def log(configuration=nil)
27
- LogJam.configure(configuration) if !configuration.nil? || @@logjam_logger.nil?
28
- @@logjam_logger
29
- end
30
-
31
- # This method updates the logger associated with the module.
32
- #
33
- # ==== Parameters
34
- # logger:: The new logger for the module.
35
- def log=(logger)
36
- LogJam.log = logger
37
- end
38
-
39
- # This method updates the logger associated with the module.
40
- #
41
- # ==== Parameters
42
- # logger:: The new logger for the module.
43
- def self.log=(logger)
44
- @@logjam_logger.logger = logger
45
- end
46
-
47
- # This method is used to install the LogJam capabilities into a target class.
48
- #
49
- # ==== Parameters
50
- # target:: The class that is to be 'logified'.
51
- def self.logify(target)
52
- target.extend(self)
53
- end
54
-
55
- # This method sets up the module logging from configuration.
56
- #
57
- # ==== Parameters
58
- # configuration:: The configuration to use when setting up logging.
59
- def self.configure(configuration)
60
- if !configuration.nil?
61
- if @@logjam_logger.nil?
62
- # Create the logger.
63
- if LogJam.is_configured?(configuration, LOG_FILE)
64
- file_name = LogJam.get_value(configuration, LOG_FILE)
65
- period = LogJam.get_value(configuration, LOG_ROLL)
66
- @@logjam_logger = LogJamLogger.new(file_name, period)
67
- else
68
- @@logjam_logger = LogJamLogger.new(STDOUT)
69
- end
70
- else
71
- # Change the internally held logger.
72
- if LogJam.is_configured?(configuration, LOG_FILE)
73
- file_name = LogJam.get_value(configuration, LOG_FILE)
74
- period = LogJam.get_value(configuration, LOG_ROLL)
75
- @@logjam_logger.logger = Logger.new(file_name, period)
76
- else
77
- @@logjam_logger.logger = Logger.new(STDOUT)
78
- end
79
- end
80
- else
81
- if @@logjam_logger.nil?
82
- @@logjam_logger = LogJamLogger.new(STDOUT)
83
- else
84
- @@logjam_logger.logger = Logger.new(STDOUT)
85
- end
86
- end
87
-
88
- # Set the logger level.
89
- level = LogJam.get_value(configuration, LOG_LEVEL, "DEBUG")
90
- case level.downcase
91
- when "info"
92
- level = Logger::INFO
93
- when "warn"
94
- level = Logger::WARN
95
- when "error"
96
- level = Logger::ERROR
97
- when "fatal"
98
- level = Logger::FATAL
99
- when "unknown"
100
- level = Logger::UNKNOWN
101
- else
102
- level = Logger::DEBUG
103
- end
104
- @@logjam_logger.level = level
105
- @@logjam_logger
106
- end
107
-
108
- private
109
-
110
- # This method encapsulates the functionality for extracting named value from
111
- # a Hash given a key.
112
- def self.get_value(configuration, name, default=nil)
113
- value = default
114
- if !configuration.nil?
115
- if configuration.include?(name)
116
- value = configuration[name]
117
- elsif configuration.include?(name.to_s)
118
- value = configuration[name.to_s]
119
- end
120
- end
121
- value
122
- end
123
-
124
- # This method is used internally by the module to determine whether a
125
- # configuration setting has been provided.
126
- def self.is_configured?(configuration, name)
127
- configuration.include?(name) || configuration.include?(name.to_s)
128
- end
129
- end