All Projects → rails-engine → audit-log

rails-engine / audit-log

Licence: MIT license
📑 Create audit logs into the database for user behaviors, including a web UI to query logs.

Programming Languages

ruby
36898 projects - #4 most used programming language
HTML
75241 projects
CSS
56736 projects
SCSS
7915 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to audit-log

Paper trail
Track changes to your rails models
Stars: ✭ 6,185 (+4481.48%)
Mutual labels:  log, audit
discord-audit-log-bot
A Discord bot that extends Discord's native Audit Log.
Stars: ✭ 109 (-19.26%)
Mutual labels:  log, audit
Wordpress Simple History
🔍🕵️‍♀️ WordPress audit log that track user changes in WordPress admin using a nice activity feed.
Stars: ✭ 232 (+71.85%)
Mutual labels:  log, audit
Laravel Activitylog
Log activity inside your Laravel app
Stars: ✭ 4,123 (+2954.07%)
Mutual labels:  log, audit
aushape
A library and a tool for converting audit logs to XML and JSON
Stars: ✭ 37 (-72.59%)
Mutual labels:  log, audit
aud
Use `npx aud` instead of `npm audit`, whether you have a lockfile or not!
Stars: ✭ 24 (-82.22%)
Mutual labels:  audit
addon-log-viewer
Log Viewer - Home Assistant Community Add-ons
Stars: ✭ 37 (-72.59%)
Mutual labels:  log
wgpu-mc
Rust-based replacement for the default Minecraft renderer
Stars: ✭ 254 (+88.15%)
Mutual labels:  engine
app-application-logger
A small standalone Windows application to log the applications one is using
Stars: ✭ 13 (-90.37%)
Mutual labels:  log
Mage-Studio
Mage Studio is a Game Editor, built on top of Mage Engine, embedded in Electron. Mage Studio will allow to easily develop 3D apps using WebGL.
Stars: ✭ 16 (-88.15%)
Mutual labels:  engine
New-Star
Web. browser game engine :)
Stars: ✭ 64 (-52.59%)
Mutual labels:  engine
apollo-log
A logging extension for the Apollo GraphQL Server
Stars: ✭ 64 (-52.59%)
Mutual labels:  log
axios-curlirize
axios plugin converting requests to cURL commands, saving and logging them.
Stars: ✭ 152 (+12.59%)
Mutual labels:  log
GoogleCloudLogging
Swift (Darwin) library for logging application events in Google Cloud.
Stars: ✭ 24 (-82.22%)
Mutual labels:  log
l
Cross-platform html/io [L]ogger with simple API.
Stars: ✭ 26 (-80.74%)
Mutual labels:  log
traffic analyser
Retrieve useful information from apache/nginx access logs to help troubleshoot traffic related problems
Stars: ✭ 44 (-67.41%)
Mutual labels:  log
Fractal Engine
WIP 3D game engine with editor and other stuff
Stars: ✭ 152 (+12.59%)
Mutual labels:  engine
org-audit-action
GitHub Action that provides an Organization Membership Audit
Stars: ✭ 34 (-74.81%)
Mutual labels:  audit
kubelogs
Interactively dump logs from multiple Kubernetes containers.
Stars: ✭ 15 (-88.89%)
Mutual labels:  log
Awesome Unreal Engine 4
UE4/UE5 Ressources Collection (Plugins, Effects, Doc, Tools, etc...)
Stars: ✭ 153 (+13.33%)
Mutual labels:  engine

AuditLog

build

Trail audit logs (Operation logs) into the database for user behaviors, including a Web UI to query logs.

We used audit-log in our production environment more than 1 year, until now (2020.5.21), it's inserted about 20 million log in our system.

中文介绍与使用说明

Demo UI

Audit log list:

Detail page:

Installation

Add this line to your application's Gemfile:

gem "audit-log"

And then execute:

$ bundle

Generate files:

$ rails g audit_log:install

Usage

Use in controllers:

class TicktsController < ApplicationController
  def index
    audit! :list_ticket, nil
  end

  def create
    if @ticket.save
      audit! :create_ticket, @ticket, payload: ticket_params
    else
      render :new
    end
  end

  def update
    if @ticket.save
      audit! :update_ticket, @ticket, payload: ticket_params
    else
      render :edit
    end
  end

  def approve
    if @ticket.approve
      audit! :approve_ticket, @ticket, payload: ticket_params
    end
  end

  def destroy
    # store original attributes for destroy for keep values
    audit! :delete_ticket, nil, @ticket.attributes
  end

  private

    def ticket_params
      params.required(:ticket).permit!(:title, :description, :status)
    end
end

In models or other places:

AuditLog.audit!(:update_password, @user, payload: { ip: request.remote_ip })
AuditLog.audit!(:sign_in, @user, payload: { ip: request.remote_ip })
AuditLog.audit!(:create_address, nil, payload: params)

Change config/routes.rb to add Route:

Rails.application.routes.draw do
  authenticate :user, -> (u) { u.admin? } do
    mount AuditLog::Engine => "/audit-log"
  end
end

I18n for audit names, you need create a config/locales/audit-log.zh-CN.yml:

zh-CN:
  audit_log:
    action:
      sign_in: 登录
      update_password: 修改密码
      create_address: 添加住址
      list_ticket: 查看工单列表
      create_ticket: 创建工单
      update_ticket: 更新工单
      delete_ticket: 删除工单
      approve_ticket: 审批工单

For track Warden (Devise) sign in behavirs:

config/initializes/devise.rb

Warden::Manager.after_authentication do |user, auth, opts|
  request = ActionDispatch::Request.new(auth.env)
  AuditLog.audit!(:sign_in, user, payload: opts, user: user, request: request)
end

Warden::Manager.before_failure do |env, opts|
  request = ActionDispatch::Request.new(env)
  email = request.params.dig(:user, :email)
  user = User.find_by_email(email)
  opts[:email] = email
  AuditLog.audit!(:sign_in_failure, nil, payload: opts, request: request, user: user)
end

Configuration

You can write a config/initializers/audit_log.rb to configure the behavior of audit log.

AuditLog.configure do
  # class name of you User model, default: 'User'
  self.user_class = "User"
  # current_user method name in your Controller, default: 'current_user'
  self.current_user_method = "current_user"
  # Speical a table_name for AuditLog model, default: "audit_logs"
  self.table_name = "audit_logs"
end

License

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].