db_log_tag 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/db_log_tag/dynamic.rb +9 -7
- data/lib/db_log_tag.rb +7 -8
- metadata +8 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '09522886cdba1969ddf183893c9260bde1f09b4237086d458e121127865ae217'
|
4
|
+
data.tar.gz: b75b3c0fb9a2a6a5702fe5f39df208542f22f20040f3bc0bf3ba22f9a87f3e24
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5e6521dd4f4a71f8a7cd433fa28b4ce39a39920471e2b84a7fdb5fb8d665264139f90fce46851df104618825fc5960ded8d5a1c5612082d31d5914d9f9d17967
|
7
|
+
data.tar.gz: 4150536f87888ec00481cc73536e36a183041acffd711ab0e36cd828d10951f9f9a18ebff756fd81464748c7c5cc19354c80453c928178f2344ed31f2ebea388
|
data/lib/db_log_tag/dynamic.rb
CHANGED
@@ -11,22 +11,24 @@ module ActiveRecord
|
|
11
11
|
|
12
12
|
attr_accessor :log_tags
|
13
13
|
|
14
|
-
def log_tag(tag_name=
|
14
|
+
def log_tag(tag_name="", **options)
|
15
15
|
return self unless DbLogTag.enable?
|
16
16
|
|
17
17
|
if block_given?
|
18
|
-
tag_name
|
18
|
+
tag_name += yield(
|
19
19
|
klass.connection_pool.db_config.name,
|
20
20
|
ActiveRecord::Base.current_shard,
|
21
21
|
ActiveRecord::Base.current_role
|
22
22
|
)
|
23
23
|
end
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
25
|
+
if tag_name.present?
|
26
|
+
tag_color = options.dig(:color)
|
27
|
+
tag_font = options.dig(:font) || :bold
|
28
|
+
tag_name = DbLogTag::Colors.set_color(tag_name, tag_color, tag_font) unless tag_color.nil?
|
29
|
+
self.annotate_values += [":tag:#{tag_name}:tag:"]
|
30
|
+
end
|
31
|
+
|
30
32
|
self
|
31
33
|
end
|
32
34
|
|
data/lib/db_log_tag.rb
CHANGED
@@ -27,10 +27,11 @@ module DbLogTag
|
|
27
27
|
included do
|
28
28
|
alias_method :origin_sql, :sql
|
29
29
|
def sql(event)
|
30
|
-
if DbLogTag.enable?
|
30
|
+
if DbLogTag.enable? && !should_ignore_log?(event)
|
31
31
|
begin
|
32
|
-
db_log_tags(event)
|
33
|
-
|
32
|
+
if tags = parse_annotations_as_dynamic_tags(event) || db_log_tags(event)
|
33
|
+
event.payload[:name] = "#{tags} #{event.payload[:name]}"
|
34
|
+
end
|
34
35
|
rescue
|
35
36
|
end
|
36
37
|
end
|
@@ -42,14 +43,13 @@ module DbLogTag
|
|
42
43
|
|
43
44
|
def parse_annotations_as_dynamic_tags(event)
|
44
45
|
tags = event.payload[:sql].scan(ActiveRecord::Relation::Tags_Regex).map(&:first).join(" ")
|
45
|
-
|
46
|
-
unless should_ignore_log?(event) || tags.nil?
|
47
|
-
event.payload[:name] = "#{tags} #{event.payload[:name]}"
|
48
|
-
end
|
46
|
+
return unless tags.present?
|
49
47
|
|
50
48
|
event.payload[:sql] = event.payload[:sql].gsub(ActiveRecord::Relation::Tags_Regex, "")
|
51
49
|
# still keep normal annotations
|
52
50
|
event.payload[:sql] = event.payload[:sql].gsub(ActiveRecord::Relation::Empty_Annotation, "")
|
51
|
+
|
52
|
+
tags
|
53
53
|
end
|
54
54
|
|
55
55
|
def db_log_tags(event)
|
@@ -57,7 +57,6 @@ module DbLogTag
|
|
57
57
|
|
58
58
|
clazz, _ = event.payload[:name].split(" ")
|
59
59
|
_db_info = DbLogTag::MultipleDb.db_info(clazz)
|
60
|
-
event.payload[:name] = "#{_db_info} #{event.payload[:name]}"
|
61
60
|
end
|
62
61
|
|
63
62
|
def should_ignore_log?(event)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: db_log_tag
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lam Phan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-03-
|
11
|
+
date: 2024-03-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -66,8 +66,8 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
-
description: Allow to prepend prefix tags
|
70
|
-
role of the database
|
69
|
+
description: Allow to prepend prefix tags to the beginning of the query logs to track
|
70
|
+
name, shard and role of the database
|
71
71
|
email: theforestvn88@gmail.com
|
72
72
|
executables: []
|
73
73
|
extensions: []
|
@@ -85,7 +85,10 @@ files:
|
|
85
85
|
homepage: https://github.com/theforestvn88/rails_db_log_tag
|
86
86
|
licenses:
|
87
87
|
- MIT
|
88
|
-
metadata:
|
88
|
+
metadata:
|
89
|
+
homepage_uri: https://github.com/theforestvn88/rails_db_log_tag
|
90
|
+
source_code_uri: https://github.com/theforestvn88/rails_db_log_tag.git
|
91
|
+
changelog_uri: https://github.com/theforestvn88/rails_db_log_tag.git
|
89
92
|
post_install_message:
|
90
93
|
rdoc_options: []
|
91
94
|
require_paths:
|