-
Notifications
You must be signed in to change notification settings - Fork 13.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add configurable logging to the console and support stdout sinks
- Loading branch information
1 parent
cb926e7
commit 9e20bb5
Showing
15 changed files
with
229 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# -*- coding: binary -*- | ||
|
||
require 'rex/logging/sinks/stream' | ||
require 'rex/logging/sinks/flatfile' | ||
require 'rex/logging/sinks/timestamp_colorless_flatfile' | ||
require 'rex/logging/sinks/stderr' | ||
require 'rex/logging/sinks/stdout' | ||
require 'rex/logging/sinks/stdout_without_timestamps' | ||
|
||
module Rex | ||
module Logging | ||
|
||
### | ||
# | ||
# LogSinkFactory can instantiate a LogSink based on the given name. | ||
# | ||
### | ||
module LogSinkFactory | ||
# Creates a new log sink of the given name. If no name is provided, a default | ||
# Flatfile log sink is chosen | ||
# | ||
# @param [String] name The name of the required log sink within Rex::Logging::Sinks | ||
# @param [Array] attrs The attributes to use with the given log sink | ||
# @return [Rex::Logging::LogSink] The newly created log sink | ||
def self.new(name = nil, *attrs) | ||
name ||= Rex::Logging::Sinks::Flatfile.name.demodulize | ||
raise NameError unless available_sinks.include?(name.to_sym) | ||
|
||
log_sink = Rex::Logging::Sinks.const_get(name) | ||
log_sink.new(*attrs) | ||
rescue NameError | ||
raise Rex::ArgumentError, "Could not find logger #{name}, expected one of #{available_sinks.join(', ')}" | ||
end | ||
|
||
# Returns a list of the available sinks that can be created by this factory | ||
# | ||
# @return [Array<Sym>] The available sinks that can be created by this factory | ||
def self.available_sinks | ||
Rex::Logging::Sinks.constants - [Rex::Logging::Sinks::Stream.name.demodulize.to_sym] | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# -*- coding: binary -*- | ||
module Rex | ||
module Logging | ||
module Sinks | ||
|
||
### | ||
# | ||
# This class implements the LogSink interface and backs it against stdout | ||
### | ||
class Stdout < Rex::Logging::Sinks::Stream | ||
|
||
# | ||
# Creates a log sink instance that will be configured to log to stdout | ||
# | ||
def initialize(*_attrs) | ||
super($stdout) | ||
end | ||
|
||
end | ||
|
||
end end end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# -*- coding: binary -*- | ||
module Rex | ||
module Logging | ||
module Sinks | ||
|
||
### | ||
# | ||
# This class implements the LogSink interface and backs it against stdout | ||
### | ||
class StdoutWithoutTimestamps < Rex::Logging::Sinks::Stream | ||
|
||
# | ||
# Creates a log sink instance that will be configured to log to stdout | ||
# | ||
def initialize(*_attrs) | ||
super($stdout) | ||
end | ||
|
||
# | ||
# Writes log data to a stream | ||
# | ||
# | ||
# Writes log data to a stream | ||
# | ||
def log(sev, src, level, msg) # :nodoc: | ||
if sev == LOG_RAW | ||
stream.write(msg) | ||
else | ||
stream.write("[#{log_code_for(sev)}(#{level})] #{src}: #{msg}\n") | ||
end | ||
|
||
stream.flush | ||
end | ||
|
||
end | ||
|
||
end end end |
Oops, something went wrong.