Skip to content

Commit

Permalink
Merge pull request #17228 from djberg96/azure_logger
Browse files Browse the repository at this point in the history
Add custom Azure logger
  • Loading branch information
Fryguy authored Apr 3, 2018
2 parents f4b2f93 + dcdc4d6 commit 2652592
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/vmdb/loggers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def self.create_loggers
$api_log = create_multicast_logger(path_dir.join("api.log"))
$miq_ae_logger = create_multicast_logger(path_dir.join("automation.log"))
$aws_log = create_multicast_logger(path_dir.join("aws.log"))
$azure_log = create_multicast_logger(path_dir.join("azure.log"))
$azure_log = create_multicast_logger(path_dir.join("azure.log"), AzureLogger)
$cn_monitoring_log = create_multicast_logger(path_dir.join("container_monitoring.log"))
$datawarehouse_log = create_multicast_logger(path_dir.join("datawarehouse.log"))
$fog_log = create_multicast_logger(path_dir.join("fog.log"), FogLogger)
Expand Down
26 changes: 26 additions & 0 deletions lib/vmdb/loggers/azure_logger.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module Vmdb::Loggers
class AzureLogger < VMDBLogger
def initialize(*loggers)
super

# pulled from Ruby's `Logger::Formatter`, which is what it defaults to when it is `nil`
@datetime_format = "%Y-%m-%dT%H:%M:%S.%6N "
@formatter = Vmdb::Loggers::AzureLogger::Formatter.new
end

def <<(msg)
msg = msg.strip
log(level, msg)
msg.size
end

class Formatter < VMDBLogger::Formatter
def call(severity, datetime, progname, msg)
msg = msg.sub(/Bearer(.*?)\"/, 'Bearer [FILTERED] "')
msg = msg.sub(/SharedKey(.*?)\"/, 'SharedKey [FILTERED] "')
msg = msg.sub(/client_secret=(.*?)&/, "client_secret=[FILTERED]&")
super(severity, datetime, progname, msg)
end
end
end
end
26 changes: 26 additions & 0 deletions spec/lib/vmdb/loggers/azure_logger_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
describe Vmdb::Loggers::AzureLogger do
before do
@log_stream = StringIO.new
@log = described_class.new(@log_stream)
end

context "azure" do
it "filters out bearer tokens" do
@log.log(@log.level, 'Bearer abcd1234 "stuff"')
@log_stream.rewind
expect(@log_stream.read).to match(Regexp.quote('Bearer [FILTERED] "stuff"'))
end

it "filters out sharedkey tokens" do
@log.log(@log.level, 'SharedKey xxx123 "stuff"')
@log_stream.rewind
expect(@log_stream.read).to match(Regexp.quote('SharedKey [FILTERED] "stuff"'))
end

it "filters out client secret tokens" do
@log.log(@log.level, 'client_secret=abc123&management=yadayada')
@log_stream.rewind
expect(@log_stream.read).to match(Regexp.quote('client_secret=[FILTERED]&management=yadayada'))
end
end
end

0 comments on commit 2652592

Please sign in to comment.