Class: Log4r::Outputter
- Inherits:
-
Monitor
- Object
- Monitor
- Log4r::Outputter
- Defined in:
- lib/log4r/outputter/outputter.rb,
lib/log4r/outputter/staticoutputter.rb,
lib/log4r/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
-
#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.
-
.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.
-
#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/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
#formatter ⇒ Object
Returns the value of attribute formatter.
19 20 21 |
# File 'lib/log4r/outputter/outputter.rb', line 19 def formatter @formatter end |
#level ⇒ Object
Returns the value of attribute level.
19 20 21 |
# File 'lib/log4r/outputter/outputter.rb', line 19 def level @level end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
19 20 21 |
# File 'lib/log4r/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 |
# File 'lib/log4r/outputter/staticoutputter.rb', line 6 def self.[](name) out = @@outputters[name] if out.nil? return case name when 'stdout' then StdoutOutputter.new 'stdout' when 'stderr' then StderrOutputter.new 'stderr' else nil end end out end |
.[]=(name, outputter) ⇒ Object
Set an outputter.
19 20 21 |
# File 'lib/log4r/outputter/staticoutputter.rb', line 19 def self.[]=(name, outputter) @@outputters[name] = outputter end |
.each ⇒ Object
Yields each outputter’s name and reference.
23 24 25 |
# File 'lib/log4r/outputter/staticoutputter.rb', line 23 def self.each @@outputters.each {|name, outputter| yield name, outputter} end |
.each_outputter ⇒ Object
26 27 28 |
# File 'lib/log4r/outputter/staticoutputter.rb', line 26 def self.each_outputter @@outputters.each_value {|outputter| yield outputter} end |
.stderr ⇒ Object
17 |
# File 'lib/log4r/outputter/staticoutputter.rb', line 17 def self.stderr; Outputter['stderr'] end |
.stdout ⇒ Object
16 |
# File 'lib/log4r/outputter/staticoutputter.rb', line 16 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.
81 82 |
# File 'lib/log4r/outputter/outputter.rb', line 81 def flush 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/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 |