class Dotenv::LogSubscriber
Logs instrumented events
Usage:
require "active_support/notifications" require "dotenv/log_subscriber" Dotenv.instrumenter = ActiveSupport::Notifications
Public Instance Methods
Source
# File lib/dotenv/log_subscriber.rb, line 18 def load(event) env = event.payload[:env] info "Loaded #{color_filename(env.filename)}" end
Source
# File lib/dotenv/log_subscriber.rb, line 34 def restore(event) diff = event.payload[:diff] removed = diff.removed.keys.map { |key| color(key, :RED) } restored = (diff.changed.keys + diff.added.keys).map { |key| color_var(key) } if removed.any? || restored.any? info "Restored snapshot of #{color_env_constant}" debug "Unset #{removed.to_sentence}" if removed.any? debug "Restored #{restored.to_sentence}" if restored.any? end end
Source
# File lib/dotenv/log_subscriber.rb, line 30 def save(event) info "Saved a snapshot of #{color_env_constant}" end
Source
# File lib/dotenv/log_subscriber.rb, line 24 def update(event) diff = event.payload[:diff] changed = diff.env.keys.map { |key| color_var(key) } debug "Set #{changed.to_sentence}" if diff.any? end
Private Instance Methods
Source
# File lib/dotenv/log_subscriber.rb, line 57 def color_env_constant color("ENV", :GREEN) end
Source
# File lib/dotenv/log_subscriber.rb, line 49 def color_filename(filename) color(Pathname.new(filename).relative_path_from(Dotenv::Rails.root.to_s).to_s, :YELLOW) end
Source
# File lib/dotenv/log_subscriber.rb, line 53 def color_var(name) color(name, :CYAN) end