No release in over 3 years
Low commit activity in last 3 years
Save Ruby's Logger messages to a database column
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.16
~> 10.0
~> 3.0

Runtime

 Project Readme

ActiveRecord::LoggerAttributes

Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file lib/active_record/logger_attributes. To experiment with that code, run bin/console for an interactive prompt.

TODO: Delete this and the text above, and describe your gem

Installation

Add this line to your application's Gemfile:

gem 'activerecord-logger_attributes'

And then execute:

$ bundle

Or install it yourself as:

$ gem install activerecord-logger_attributes

Usage

First, create a column to hold your log messages:

class AddActivityLogToPosts < ActiveRecord::Migration[5.1]
  def change
    add_column :posts, :activity_log, :text, array: true, default: []
  end
end

Add the logger_attr to your model:

class BlogPost < ActiveRecord::Base
  logger_attr :activity_log
end

Write to the logger as you normally would:

@post = BlogPost.new
@post.activity_log_logger.info "Setting up new blog post"
@post.save

All of the options supported by activemodel-logger_attributes are supported here with a few additions:

logger_attr :activity_log, update_on_write: true

If the update_on_write option is enabled (true by default) the log column will be updated immediately when new messages are pushed to the logger (internally this happens via update_column so beware caveats, however this is generally what you want) if the model is already persisted, otherwise database updates will happen conventionally via save.

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the ActiveRecord::LoggerAttributes project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.