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.
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, from) ⇒ Object
:nodoc:.
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 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, from) ⇒ 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, from) # :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 |