README.md in model_log-1.0.2 vs README.md in model_log-2.0.0
- old
+ new
@@ -1,15 +1,20 @@
# ModelLog
-User operation data saves log files and records user information.
+It's designed to be used to record all changes of the models to a log file for Rails. You can also use it to record who made the changes.
+## Supported Versions
+
+- Ruby 2.0.0+
+- Rails 3.0.0+
+
## Installation
Add this line to your application's Gemfile:
```ruby
-gem 'model_log', :git => 'git@bitbucket.org:scige/model_log.git'
+gem 'model_log', '~> 2.0.0'
```
And then execute:
$ bundle install
@@ -22,51 +27,88 @@
class User < ActiveRecord::Base
model_log
end
```
-## Log Path
+## Log File Path
The log is saved in the `log/` section of your rails app.
-The development environment file is called `model_log_development.log`.
+The log in development environment is in `model_log_development.log`.
-The product environment file is called `model_log_product.log`.
+The log in production environment is in `model_log_production.log`.
-## Current User Tracking
+## Configure
-If you're using ModelLog in a Rails application, all audited changes made within a request will automatically be attributed to the current user. By default, ModelLog uses the `current_passport` method in your controller.
+By default, ModelLog uses the `current_user` method in your controller. The default identity field is `id`.
-The username field default to `username`.
+To use a method other than `current_user` and an identity field other than `id`, put the following in an initializer:
-To use a method other than `current_passport` and a field other than `username`, put the following in an initializer:
-
```ruby
# config/initializers/model_log.rb
-
-ModelLog.current_user_method = :current_user
-ModelLog.user_name_field = :name
+ModelLog.configure do |config|
+ config.current_user_method = :current_manager # default: :current_user
+ config.identity_field = :username # default: :id
+ config.separator = ' ' # default: "\t"
+ config.logger_datetime_format = '%Y-%m-%d %H:%M:%S'
+end
```
-## Other Settings
+## Custom Log Formatter
-If you have multiple platforms, and the tag data changes belong to that platform, put the following in an initializer:
+There are default log formatter. You can also custom them here. For example:
```ruby
# config/initializers/model_log.rb
+class Myformatter
+ include ModelLog::Helpers::Context
+ # Some methods are provided here. You can use them directly.
+ # current_user The information about the current user, which could be nil.
+ # requester The infomation about the current network request, which could be nil.
+ # resource Current resource.
+ # changes The changes to the current resource.
+ # changed? Whether the current resource has been changed.
+ # action update|create|destroy
+ # is_update? If the action is update.
+ # is_create? If the action is create.
+ # is_destroy? If the action is destroy.
-ModelLog.platform = :CPM
-```
+ def call
+ return unless changed?
+ content = []
+ content += requester_content if requester
+ content += user_content if current_user
+ content += resource_content
+ content.join(' ')
+ end
-## Run Error
-If you run a rails app hint `The git source git@bitbucket.org:scige/model_log.git is not yet checked out. Please run “bundle install” before trying to start your application`, Try to run
+ private
- $ bundle install --deployment
+ def user_content
+ [
+ current_user.id,
+ current_user.username
+ ]
+ end
+ def requester_content
+ [
+ requester.request_method,
+ requester.url,
+ ]
+ end
+ def resource_content
+ [
+ changes
+ ]
+ end
+end
-## Gem Update
+ModelLog.configure do |config|
+ config.formatter = MyFormatter
+end
+```
-If you want to update the gem, run:
+## Copyright
- $ bundle update model_log
-
+Copyright (c) 2018- jk-sun. See LICENSE.tet for further details.