Sha256: 241183fd42c970371ebee67d643f57a3db059d3a48850b00ea3e2e467c34de1c

Contents?: true

Size: 821 Bytes

Versions: 42

Compression:

Stored size: 821 Bytes

Contents

module Rex
module Logging
module Sinks

###
#
# This class implements the LogSink interface and backs it against a 
# file on disk.
#
###
class Flatfile

	include Rex::Logging::LogSink

	#
	# Creates a flatfile log sink instance that will be configured to log to
	# the supplied file path.
	#
	def initialize(file)
		self.fd = File.new(file, "a")
	end

	def cleanup # :nodoc:
		fd.close
	end

	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("[#{get_current_timestamp}] [#{code}(#{level})] #{src}: #{msg}\n")
		end
			
		fd.flush
	end

protected

	attr_accessor :fd # :nodoc:

end

end end end

Version data entries

42 entries across 42 versions & 1 rubygems

Version Path
librex-0.0.65 lib/rex/logging/sinks/flatfile.rb
librex-0.0.63 lib/rex/logging/sinks/flatfile.rb
librex-0.0.54 lib/rex/logging/sinks/flatfile.rb
librex-0.0.53 lib/rex/logging/sinks/flatfile.rb
librex-0.0.52 lib/rex/logging/sinks/flatfile.rb
librex-0.0.51 lib/rex/logging/sinks/flatfile.rb
librex-0.0.50 lib/rex/logging/sinks/flatfile.rb
librex-0.0.49 lib/rex/logging/sinks/flatfile.rb
librex-0.0.48 lib/rex/logging/sinks/flatfile.rb
librex-0.0.47 lib/rex/logging/sinks/flatfile.rb
librex-0.0.46 lib/rex/logging/sinks/flatfile.rb
librex-0.0.44 lib/rex/logging/sinks/flatfile.rb
librex-0.0.43 lib/rex/logging/sinks/flatfile.rb
librex-0.0.42 lib/rex/logging/sinks/flatfile.rb
librex-0.0.41 lib/rex/logging/sinks/flatfile.rb
librex-0.0.40 lib/rex/logging/sinks/flatfile.rb
librex-0.0.39 lib/rex/logging/sinks/flatfile.rb
librex-0.0.38 lib/rex/logging/sinks/flatfile.rb
librex-0.0.37 lib/rex/logging/sinks/flatfile.rb
librex-0.0.36 lib/rex/logging/sinks/flatfile.rb