Class: Dotenv::LogSubscriber

Inherits:
ActiveSupport::LogSubscriber
  • Object
show all
Defined in:
lib/dotenv/log_subscriber.rb

Overview

Logs instrumented events

Usage:

require "active_support/notifications"
require "dotenv/log_subscriber"
Dotenv.instrumenter = ActiveSupport::Notifications

Instance Method Summary collapse

Instance Method Details

#load(event) ⇒ Object



18
19
20
21
22
# File 'lib/dotenv/log_subscriber.rb', line 18

def load(event)
  env = event.payload[:env]

  info "Loaded #{color_filename(env.filename)}"
end

#loggerObject



14
15
16
# File 'lib/dotenv/log_subscriber.rb', line 14

def logger
  Dotenv::Rails.logger
end

#restore(event) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
# 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

#save(event) ⇒ Object



30
31
32
# File 'lib/dotenv/log_subscriber.rb', line 30

def save(event)
  info "Saved a snapshot of #{color_env_constant}"
end

#update(event) ⇒ Object



24
25
26
27
28
# 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