Module: ActiveModelLogger::Loggable

Extended by:
ActiveSupport::Concern
Includes:
LoggableHelpers
Defined in:
lib/active_model_logger/loggable.rb

Overview

The Loggable concern provides comprehensive logging functionality to ActiveRecord models. It allows models to create, query, and manage log entries with various levels of detail.

Examples:

Basic usage

class User < ApplicationRecord
  include ActiveModelLogger::Loggable
end

user = User.create!(name: "John")
user.log("User created successfully")
user.log("User updated", log_level: "info", metadata: { action: "update" })

Configuration

class User < ApplicationRecord
  include ActiveModelLogger::Loggable

  configure_loggable(
    default_visible_to: "user",
    default_log_level: "debug"
  )
end

Batch logging

user.log_batch([
  { message: "Step 1 completed", status: "success" },
  { message: "Step 2 completed", status: "success" },
  { message: "Process finished", status: "completed" }
])

Method Summary

Methods included from LoggableHelpers

#build_batch_log_entries, #build_log_attributes, #cleanup_logs, #create_log_entry, #generate_log_chain, #validate_log_inputs