Class: Rex::Logging::Sinks::Flatfile
- Inherits:
-
Object
- Object
- Rex::Logging::Sinks::Flatfile
- Includes:
- LogSink
- Defined in:
- lib/rex/logging/sinks/flatfile.rb
Overview
This class implements the LogSink interface and backs it against a file on disk.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#fd ⇒ Object
protected
:nodoc:.
Instance Method Summary collapse
-
#cleanup ⇒ Object
:nodoc:.
-
#initialize(file) ⇒ Flatfile
constructor
Creates a flatfile log sink instance that will be configured to log to the supplied file path.
-
#log(sev, src, level, msg) ⇒ Object
:nodoc:.
Methods included from LogSink
Constructor Details
#initialize(file) ⇒ Flatfile
Creates a flatfile log sink instance that will be configured to log to the supplied file path.
20 21 22 |
# File 'lib/rex/logging/sinks/flatfile.rb', line 20 def initialize(file) self.fd = File.new(file, "a") end |
Instance Attribute Details
#fd ⇒ Object (protected)
:nodoc:
52 53 54 |
# File 'lib/rex/logging/sinks/flatfile.rb', line 52 def fd @fd end |
Instance Method Details
#cleanup ⇒ Object
:nodoc:
24 25 26 |
# File 'lib/rex/logging/sinks/flatfile.rb', line 24 def cleanup # :nodoc: fd.close end |
#log(sev, src, level, msg) ⇒ Object
:nodoc:
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/rex/logging/sinks/flatfile.rb', line 28 def log(sev, src, level, msg) # :nodoc: if (sev == LOG_RAW) fd.write(msg) else code = 'i' case sev when LOG_DEBUG code = 'd' when LOG_ERROR code = 'e' when LOG_INFO code = 'i' when LOG_WARN code = 'w' end fd.write("[#{}] [#{code}(#{level})] #{src}: #{msg}\n") end fd.flush end |