module OhMyLog

Effect is container of all the changes that a model suffers

Result contains the request and all the effects that a specific request caused all over the models

Constants

VERSION

Public Class Methods

activate() click to toggle source
# File lib/oh_my_log.rb, line 33
def self.activate
  begin
    ::OhMyLog::ObserverFactory.activate_observers
  rescue
    return "could not start the gem, did you run oh_my_log:install ?"
  end
end
destroy_initializer() click to toggle source
# File lib/oh_my_log.rb, line 46
def self.destroy_initializer
  path = Rails.root + "config/initializers/oh_my_log_initializer.rb"
  File.delete(path) if File.exist?(path)
  p "Successfully destroyed the initializer!"
end
generate_initializer() click to toggle source
# File lib/oh_my_log.rb, line 41
def self.generate_initializer
  FileUtils.cp_r(File.expand_path(__dir__ + '/../blue_print/oh_my_log_initializer.rb'), Rails.root + "config/initializers")
  p "Successfully created initializer!"
end
start() click to toggle source

call this after you configured the Log Module

# File lib/oh_my_log.rb, line 18
def self.start
  return unless File.directory?(Rails.root + "app/models/observers/oh_my_log")
  activate
  #the main loop to get callbacks from controllers
  ActiveSupport::Notifications.subscribe "process_action.action_controller" do |*args|
    data = args[-1]
    if Log::loggable?(data[:params], data[:status], data[:method])
      request = Log::Request.new(sender: Thread.current[:user], date: Time.now.utc, params: data[:params], method: data[:method], status: data[:status], path: data[:path])
      result = Log::Result.new(request)
      result.record!
    end
    Log::flush
  end
end
test_message(msg) click to toggle source
# File lib/oh_my_log.rb, line 52
def self.test_message(msg)
  OhMyLog::Log.configuration.log_instance.info(msg)
end