module Morpheus::Logging
Provides global Logging
behavior By default, Morpheus::Logging.logger
is set to STDOUT with level INFO
Constants
- AUTHORIZATION_HEADER
- DEFAULT_LOG_LEVEL
- SECRET_TOKEN_HEADERS
Public Class Methods
Source
# File lib/morpheus/logging.rb, line 72 def self.debug? # self.log_level && self.log_level <= Logger::DEBUG self.logger.debug? end
is log level debug?
Source
# File lib/morpheus/logging.rb, line 53 def self.log_level @@log_level end
set the global log level
Source
# File lib/morpheus/logging.rb, line 35 def self.logger if !@@logger set_logger(STDOUT, @@log_level) end @@logger end
get the global logger instance
Source
# File lib/morpheus/logging.rb, line 78 def self.print_stacktrace? self.debug? end
whether or not to print stack traces
Source
# File lib/morpheus/logging.rb, line 83 def self.scrub_message(msg) if msg.is_a?(String) msg = msg.clone # looks for RestClient format (hash.inspect) and request/curl output name: value msg.gsub!(/Authorization\"\s?\=\>\s?\"Bearer [^"]+/i, 'Authorization"=>"Bearer ************') msg.gsub!(/Authorization\:\s?Bearer [^"']+/i, 'Authorization: Bearer ************') # msg.gsub!(/#{AUTHORIZATION_HEADER}\"\s?\=\>\s?\"Bearer [^"]+/, "#{AUTHORIZATION_HEADER}"=>"Bearer ************") # msg.gsub!(/#{AUTHORIZATION_HEADER}\:\s?Bearer [^"']+/, "#{AUTHORIZATION_HEADER}: Bearer ************") SECRET_TOKEN_HEADERS.each do |header| msg.gsub!(/#{header}\"\s?\=\>\s?\"[^"]+/, "#{header}\"=>\"************") msg.gsub!(/#{header}\:\s?[^"']+/, "#{header}: ************") end msg.gsub!(/password\"\: "[^"]+/, 'password": "************') # json properties ending with password msg.gsub!(/Password\"\: "[^"]+/, 'Password": "************') # json properties ending with Password msg.gsub!(/password\"\s?\=\>\s?\"[^"]+/, 'password"=>"************') msg.gsub!(/Password\"\s?\=\>\s?\"[^"]+/, 'Password"=>"************') msg.gsub!(/password\=\"[^"]+/, 'password="************') msg.gsub!(/Password\=\"[^"]+/, 'Password="************') msg.gsub!(/password\=[^"'&]+/, 'password=************') # buggy, wont work with ampersand or quotes in passwords! heh msg.gsub!(/Password\=[^"'&]+/, 'Password=************') msg.gsub!(/passwordConfirmation\=[^" ]+/i, 'passwordConfirmation="************') msg.gsub!(/passwordConfirmation\=[^" ]+/i, 'passwordConfirmation=************') end msg end
mask well known secrets and password patterns
Source
# File lib/morpheus/logging.rb, line 58 def self.set_log_level(level) @@log_level = level.to_i if @@logger @@logger.level = @@log_level end @@log_level end
set the global log level
Source
# File lib/morpheus/logging.rb, line 43 def self.set_logger(logdev, log_level = @@log_level) @@logger = logdev.is_a?(Logger) ? logdev : Logger.new(logdev) @@logger.level = log_level || DEFAULT_LOG_LEVEL @@logger.formatter = proc do |severity, datetime, progname, msg| "#{msg}\n" end @@logger end
set the global logger to another logger or filename