Class: Log4r::Outputter
- Inherits:
-
Monitor
- Object
- Monitor
- Log4r::Outputter
- Defined in:
- lib/log4r-color/outputter/outputter.rb,
lib/log4r-color/outputter/staticoutputter.rb,
lib/log4r-color/outputter/outputterfactory.rb
Direct Known Subclasses
EmailOutputter, IOOutputter, RemoteOutputter, ScribeOutputter, SyslogOutputter, UDPOutputter
Defined Under Namespace
Classes: OutputterFactory
Constant Summary collapse
- @@outputters =
Hash.new
Instance Attribute Summary collapse
-
#colors ⇒ Object
Returns the value of attribute colors.
-
#formatter ⇒ Object
Returns the value of attribute formatter.
-
#level ⇒ Object
Returns the value of attribute level.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
-
.[](name) ⇒ Object
Retrieve an outputter.
-
.[]=(name, outputter) ⇒ Object
Set an outputter.
- .color ⇒ Object
-
.each ⇒ Object
Yields each outputter’s name and reference.
- .each_outputter ⇒ Object
- .stderr ⇒ Object
- .stdout ⇒ Object
Instance Method Summary collapse
-
#flush ⇒ Object
Call flush to force an outputter to write out any buffered log events.
-
#initialize(_name, hash = {}) ⇒ Outputter
constructor
An Outputter needs a name.
- #level_key(lv) ⇒ Object
-
#only_at(*levels) ⇒ Object
Set the levels to log.
Constructor Details
#initialize(_name, hash = {}) ⇒ Outputter
An Outputter needs a name. RootLogger will be loaded if not already done. The hash arguments are as follows:
:level
-
Logger level. Optional, defaults to root level
:formatter
-
A Formatter. Defaults to DefaultFormatter
28 29 30 31 32 33 34 35 36 |
# File 'lib/log4r-color/outputter/outputter.rb', line 28 def initialize(_name, hash={}) super() if _name.nil? raise ArgumentError, "Bad arguments. Name and IO expected.", caller end @name = _name validate_hash(hash) @@outputters[@name] = self end |
Instance Attribute Details
#colors ⇒ Object
Returns the value of attribute colors.
19 20 21 |
# File 'lib/log4r-color/outputter/outputter.rb', line 19 def colors @colors end |
#formatter ⇒ Object
Returns the value of attribute formatter.
19 20 21 |
# File 'lib/log4r-color/outputter/outputter.rb', line 19 def formatter @formatter end |
#level ⇒ Object
Returns the value of attribute level.
19 20 21 |
# File 'lib/log4r-color/outputter/outputter.rb', line 19 def level @level end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
19 20 21 |
# File 'lib/log4r-color/outputter/outputter.rb', line 19 def name @name end |
Class Method Details
.[](name) ⇒ Object
Retrieve an outputter.
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/log4r-color/outputter/staticoutputter.rb', line 6 def self.[](name) out = @@outputters[name] if out.nil? return case name when 'color' then ColorOutputter.new 'color' when 'stdout' then StdoutOutputter.new 'stdout' when 'stderr' then StderrOutputter.new 'stderr' else nil end end out end |
.[]=(name, outputter) ⇒ Object
Set an outputter.
21 22 23 |
# File 'lib/log4r-color/outputter/staticoutputter.rb', line 21 def self.[]=(name, outputter) @@outputters[name] = outputter end |
.color ⇒ Object
17 |
# File 'lib/log4r-color/outputter/staticoutputter.rb', line 17 def self.color; Outputter['color'] end |
.each ⇒ Object
Yields each outputter’s name and reference.
25 26 27 |
# File 'lib/log4r-color/outputter/staticoutputter.rb', line 25 def self.each @@outputters.each {|name, outputter| yield name, outputter} end |
.each_outputter ⇒ Object
28 29 30 |
# File 'lib/log4r-color/outputter/staticoutputter.rb', line 28 def self.each_outputter @@outputters.each_value {|outputter| yield outputter} end |
.stderr ⇒ Object
19 |
# File 'lib/log4r-color/outputter/staticoutputter.rb', line 19 def self.stderr; Outputter['stderr'] end |
.stdout ⇒ Object
18 |
# File 'lib/log4r-color/outputter/staticoutputter.rb', line 18 def self.stdout; Outputter['stdout'] end |
Instance Method Details
#flush ⇒ Object
Call flush to force an outputter to write out any buffered log events. Similar to IO#flush, so use in a similar fashion.
92 93 |
# File 'lib/log4r-color/outputter/outputter.rb', line 92 def flush end |
#level_key(lv) ⇒ Object
59 60 61 |
# File 'lib/log4r-color/outputter/outputter.rb', line 59 def level_key lv Log4rTools.level_key(lv) end |
#only_at(*levels) ⇒ Object
Set the levels to log. All others will be ignored
47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/log4r-color/outputter/outputter.rb', line 47 def only_at(*levels) raise ArgumentError, "Gimme some levels!", caller if levels.empty? raise ArgumentError, "Can't log only_at ALL", caller if levels.include? ALL levels.each {|level| Log4rTools.validate_level(level)} @level = levels.sort.first OutputterFactory.create_methods self, levels Logger.log_internal { "Outputter '#{@name}' writes only on " +\ levels.collect{|l| LNAMES[l]}.join(", ") } end |