mongo_beautiful_logger 0.2.2 → 0.3.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/lib/mongo_beautiful_logger/mongo_actions.rb +14 -11
- data/lib/mongo_beautiful_logger.rb +15 -8
- metadata +8 -8
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a4c72f1a4afccbadb36212389ea2a148f31638c319d549f635c47dcb1b4e93f1
|
|
4
|
+
data.tar.gz: 7da0afe4563ae6edd2118693481469a41544aeb4bf696f314028b4a060ec811a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e843dc219a3d83bdec7fc06666259aa9a71f1610c1ce7d64a2c77193feadce9d385cb02f1ae2c5b11277f839cbff087309dcf121749b551465eb1c9813c17d1e
|
|
7
|
+
data.tar.gz: 31b29333e9a323d87ee6235c3a33db493f03dc4829748ddf1b183ba00aba3d4bf479eddf99dd3e9b980a319b14a721effde3043fdf9c8e93602a4952ea486db3
|
|
@@ -3,24 +3,27 @@ require "mongo_beautiful_logger/colors"
|
|
|
3
3
|
module MongoActions
|
|
4
4
|
include Colors
|
|
5
5
|
|
|
6
|
+
# https://bugs.ruby-lang.org/issues/20433
|
|
7
|
+
arrow = (RUBY_VERSION >= '3.4') ? ' =>' : '=>'
|
|
8
|
+
|
|
6
9
|
# substring matches and the corresponding colors for mongodb actions
|
|
7
|
-
FIND = { match: "\"find\"
|
|
8
|
-
UPDATE = { match: "\"update\"
|
|
9
|
-
INSERT = { match: "\"insert\"
|
|
10
|
-
DELETE = { match: "\"delete\"
|
|
11
|
-
AGGREGATE = { match: "\"aggregate\"
|
|
12
|
-
SUCCEEDED = { match: "succeeded",
|
|
13
|
-
FAILED = { match: "failed",
|
|
14
|
-
ERROR = { match: "error",
|
|
15
|
-
ENDSESSION = { match: "\"endsessions\"
|
|
16
|
-
INITIALIZING = { match: "initializing",
|
|
10
|
+
FIND = { match: "\"find\"#{arrow}", color: BLUE }
|
|
11
|
+
UPDATE = { match: "\"update\"#{arrow}", color: YELLOW }
|
|
12
|
+
INSERT = { match: "\"insert\"#{arrow}", color: GREEN }
|
|
13
|
+
DELETE = { match: "\"delete\"#{arrow}", color: RED }
|
|
14
|
+
AGGREGATE = { match: "\"aggregate\"#{arrow}", color: MAGENTA }
|
|
15
|
+
SUCCEEDED = { match: "succeeded", color: GREEN }
|
|
16
|
+
FAILED = { match: "failed", color: RED }
|
|
17
|
+
ERROR = { match: "error", color: RED }
|
|
18
|
+
ENDSESSION = { match: "\"endsessions\"#{arrow}", color: YELLOW }
|
|
19
|
+
INITIALIZING = { match: "initializing", color: GREEN }
|
|
17
20
|
ACTIONS = [ FIND, UPDATE, INSERT, DELETE, AGGREGATE,
|
|
18
21
|
SUCCEEDED, FAILED, ERROR, ENDSESSION, INITIALIZING ]
|
|
19
22
|
|
|
20
23
|
# substring matches for unnecessary log messages that will be filtered out
|
|
21
24
|
UNNECESSARY = ["opology", "server description"]
|
|
22
25
|
|
|
23
|
-
# regex for
|
|
26
|
+
# regex for the log prefix that will be filtered out
|
|
24
27
|
# matches: +| localhost:27017 | app_test.update | STARTED |+
|
|
25
28
|
# note: +| STARTED |+ and +| SUCCEEDED |+ will be filtered due to redundancy,
|
|
26
29
|
# but +| FAILED |+ and others will not
|
|
@@ -6,18 +6,25 @@ class MongoBeautifulLogger
|
|
|
6
6
|
include MongoActions
|
|
7
7
|
include Colors
|
|
8
8
|
|
|
9
|
-
def initialize(
|
|
10
|
-
|
|
9
|
+
def initialize(*targets)
|
|
10
|
+
nil_targets_error if targets.empty?
|
|
11
|
+
@targets = targets.map do |t|
|
|
12
|
+
logger = Logger.new(t)
|
|
13
|
+
format! logger
|
|
14
|
+
logger
|
|
15
|
+
end
|
|
11
16
|
end
|
|
12
17
|
|
|
13
18
|
private
|
|
14
19
|
|
|
15
|
-
|
|
20
|
+
def nil_targets_error
|
|
21
|
+
raise ArgumentError.new "wrong number of arguments (given 0, expected at least 1)"
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# default logger format, removes prompt of:
|
|
16
25
|
# +d, [2020-06-20 14:02:29#17329] INFO -- MONGODB:+
|
|
17
|
-
def
|
|
18
|
-
logger = Logger.new($stdout)
|
|
26
|
+
def format!(logger)
|
|
19
27
|
logger.formatter = proc { |severity, datetime, progname, msg| "#{msg}" }
|
|
20
|
-
return logger
|
|
21
28
|
end
|
|
22
29
|
|
|
23
30
|
# define custom logger methods
|
|
@@ -27,7 +34,7 @@ class MongoBeautifulLogger
|
|
|
27
34
|
def #{level}(msg = nil, &block)
|
|
28
35
|
return if unnecessary?(msg)
|
|
29
36
|
msg = format_log(msg)
|
|
30
|
-
@
|
|
37
|
+
@targets.each { |t| t.#{level}(msg, &block) }; nil
|
|
31
38
|
end
|
|
32
39
|
RUBY
|
|
33
40
|
end
|
|
@@ -57,7 +64,7 @@ class MongoBeautifulLogger
|
|
|
57
64
|
|
|
58
65
|
# send all other methods back to logger instance
|
|
59
66
|
def method_missing(method, *args, &block)
|
|
60
|
-
@
|
|
67
|
+
@targets.each { |t| t.send(method, *args, &block) }
|
|
61
68
|
end
|
|
62
69
|
|
|
63
70
|
# set color based one the defined constants.
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: mongo_beautiful_logger
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.3.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ibraheem Ahmed
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2025-11-08 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -16,31 +16,31 @@ dependencies:
|
|
|
16
16
|
requirements:
|
|
17
17
|
- - "~>"
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: '
|
|
19
|
+
version: '2.7'
|
|
20
20
|
type: :development
|
|
21
21
|
prerelease: false
|
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
23
|
requirements:
|
|
24
24
|
- - "~>"
|
|
25
25
|
- !ruby/object:Gem::Version
|
|
26
|
-
version: '
|
|
26
|
+
version: '2.7'
|
|
27
27
|
- !ruby/object:Gem::Dependency
|
|
28
28
|
name: rake
|
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
|
30
30
|
requirements:
|
|
31
31
|
- - "~>"
|
|
32
32
|
- !ruby/object:Gem::Version
|
|
33
|
-
version: '
|
|
33
|
+
version: '13.3'
|
|
34
34
|
type: :development
|
|
35
35
|
prerelease: false
|
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
|
37
37
|
requirements:
|
|
38
38
|
- - "~>"
|
|
39
39
|
- !ruby/object:Gem::Version
|
|
40
|
-
version: '
|
|
40
|
+
version: '13.3'
|
|
41
41
|
description:
|
|
42
42
|
email:
|
|
43
|
-
-
|
|
43
|
+
- ibraheem@ibraheem.ca
|
|
44
44
|
executables: []
|
|
45
45
|
extensions: []
|
|
46
46
|
extra_rdoc_files: []
|
|
@@ -67,7 +67,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
67
67
|
- !ruby/object:Gem::Version
|
|
68
68
|
version: '0'
|
|
69
69
|
requirements: []
|
|
70
|
-
rubygems_version: 3.
|
|
70
|
+
rubygems_version: 3.5.23
|
|
71
71
|
signing_key:
|
|
72
72
|
specification_version: 4
|
|
73
73
|
summary: A simple and beautiful logger for MongoDB/Mongoid in you Ruby/Rails app.
|