queryable_logs 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +47 -5
- data/lib/generators/templates/initializer.rb +1 -2
- data/lib/queryable_logs/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 24a41e93a9b5a82d65308c7a0328fe06e09e258da2bbdecf22318787f8b7bd12
|
4
|
+
data.tar.gz: fa7a6fcb05f84ef1e93c46f615fd24e61a378b6a94b45654b3d5a67cffe8a9c1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7be44957dc9085326c0316c9f3494376886e6a486e930ea2d74e79456e10f33d4eb788ee45876bb46c3bb94f1dee20c69e9940d374a8c7b8a1587dfed8892def
|
7
|
+
data.tar.gz: 80ca1801204f4c5bda12e7a36a38563959b14aae1eb3cccf866da873ff9b0ee764153c0e91025ae150380cd1d7011a541b944eb7bde506b91573d3df7b9ee649
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -21,12 +21,54 @@ Or install it yourself as:
|
|
21
21
|
Run
|
22
22
|
`rails g queryable_logs`.
|
23
23
|
|
24
|
-
This will generate a migration file
|
24
|
+
This will generate a migration file.
|
25
|
+
```ruby
|
26
|
+
class CreateTrailLogs < ActiveRecord::Migration
|
27
|
+
def change
|
28
|
+
create_table :trail_logs do |t|
|
29
|
+
t.integer :user_id
|
30
|
+
t.string :ip_address
|
31
|
+
t.string :controller
|
32
|
+
t.string :action
|
33
|
+
t.string :format
|
34
|
+
t.string :http_verb
|
35
|
+
t.text :params_hash
|
36
|
+
t.datetime :logged_at
|
37
|
+
t.string :response_code
|
38
|
+
t.string :request_url
|
39
|
+
t.string :sig
|
40
|
+
|
41
|
+
t.timestamps null: false
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
```
|
46
|
+
and an initializer file.
|
47
|
+
```ruby
|
48
|
+
class Trail
|
49
|
+
cattr_accessor :current_user_method, :logger, :saving_logs
|
50
|
+
LogFile = Rails.root.join('log', 'trail.log')
|
51
|
+
delegate :debug, :info, :warn, :error, :fatal, :to => :logger
|
52
|
+
end
|
53
|
+
|
54
|
+
Trail.logger = Logger.new(Trail::LogFile)
|
55
|
+
Trail.logger.level = 'info' # could be debug, info, warn, error or fatal
|
56
|
+
Trail.current_user_method = :current_user
|
57
|
+
```
|
58
|
+
queryable_logs also logs the current user id. Let the gem know which method you are using to get the current user. Default is set to `current_user`.
|
59
|
+
|
60
|
+
Finally, include the `QueryableLogs::WriteLog` in the base controller, typically the `ApplicationController`.
|
61
|
+
```ruby
|
62
|
+
class ApplicationController < ActionController::Base
|
63
|
+
include QueryableLogs::WriteLog
|
64
|
+
end
|
65
|
+
```
|
66
|
+
|
67
|
+
Enter the following task to your crontab `rake parse:logs_to_db`
|
68
|
+
|
69
|
+
eg: `0 * * * * cd /Users/akshaytakkar/sample_rails_app && /Users/akshaytakkar/.rvm/wrappers/ruby-3.1.0/rake db:parse_log_and_save_trails >> /Users/akshaytakkar/sample_rails_app/log/worker.log 2>&1`
|
25
70
|
|
26
|
-
|
27
|
-
`rake parse:logs_to_db`
|
28
|
-
eg:
|
29
|
-
`* * * * * cd /Users/akshaytakkar/sample_rails_app && /Users/akshaytakkar/.rvm/wrappers/ruby-3.1.0/rake db:parse_log_and_save_trails >> /Users/akshaytakkar/sample_rails_app/log/worker.log 2>&1`
|
71
|
+
This will run the `rake parse:logs_to_db` rake task every hour and log any errors or output from the task to `worker.log` file.
|
30
72
|
|
31
73
|
## Usage
|
32
74
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: queryable_logs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Akshay Takkar
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-10-
|
11
|
+
date: 2023-10-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|