mongo_beautiful_logger 0.1.0 → 0.3.0
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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4c58868b69432a45f1f40e031eeb8d60e88c33dae37aa48715475608f01afc53
|
4
|
+
data.tar.gz: e063316c20d3461c5957afcae9b52eaea496445138cf4c7fc78de5e912387abe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7a7e2cdd141db663be2969779eab22f9eee4081bc4d3b0abcb22d4f92484ba00b01d7ebbf3f50e89d9ec1c52b33591e4c4e9ddd440ae03ab407190627839b59d
|
7
|
+
data.tar.gz: de6694d1250d2459fa7762efdd85e751fa189760cbdad77a3d534767fde12a1dbd4a391d20d0030cd0c45539e4c9a059862c82776789fe3d401232972d8843a6
|
@@ -6,45 +6,65 @@ 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
|
26
|
+
def format!(logger)
|
18
27
|
logger.formatter = proc { |severity, datetime, progname, msg| "#{msg}" }
|
19
|
-
logger
|
20
28
|
end
|
21
29
|
|
22
30
|
# define custom logger methods
|
23
|
-
#
|
31
|
+
# formats log message and then sends message back to the logger instance
|
24
32
|
%w(debug info warn error fatal unknown).each do |level|
|
25
33
|
class_eval <<-RUBY
|
26
34
|
def #{level}(msg = nil, &block)
|
27
|
-
|
28
|
-
msg =
|
29
|
-
@
|
35
|
+
return if unnecessary?(msg)
|
36
|
+
msg = format_log(msg)
|
37
|
+
@targets.each { |t| t.#{level}(msg, &block) }; nil
|
30
38
|
end
|
31
39
|
RUBY
|
32
40
|
end
|
33
41
|
|
42
|
+
# checks if a message if a message is included in the +UNNECESSARY+ array constant
|
43
|
+
def unnecessary?(msg)
|
44
|
+
UNNECESSARY.any? { |s| msg.downcase.include? s }
|
45
|
+
end
|
46
|
+
|
47
|
+
# takes a log message and returns the message formatted
|
48
|
+
def format_log(msg)
|
49
|
+
msg = colorize_log(msg)
|
50
|
+
msg = remove_prefix(msg)
|
51
|
+
"#{msg}\n"
|
52
|
+
end
|
53
|
+
|
34
54
|
# colorize messages that are specified in ACTIONS constant
|
35
55
|
def colorize_log(msg)
|
36
56
|
ACTIONS.each { |a| msg = color(msg, a[:color]) if msg.downcase.include?(a[:match]) }
|
37
|
-
msg
|
57
|
+
return msg
|
38
58
|
end
|
39
59
|
|
40
|
-
#
|
41
|
-
def
|
42
|
-
|
60
|
+
# remove prefix defined in +PREFIX_REGEX+ from message
|
61
|
+
def remove_prefix(msg)
|
62
|
+
msg.sub(PREFIX_REGEX, "|")
|
43
63
|
end
|
44
64
|
|
45
65
|
# send all other methods back to logger instance
|
46
66
|
def method_missing(method, *args, &block)
|
47
|
-
@
|
67
|
+
@targets.each { |t| t.send(method, *args, &block) }
|
48
68
|
end
|
49
69
|
|
50
70
|
# set color based one the defined constants.
|
@@ -13,15 +13,16 @@ module MongoActions
|
|
13
13
|
FAILED = { match: "failed", color: RED }
|
14
14
|
ERROR = { match: "error", color: RED }
|
15
15
|
ENDSESSION = { match: "\"endsessions\"=>", color: YELLOW }
|
16
|
+
INITIALIZING = { match: "initializing", color: GREEN }
|
16
17
|
ACTIONS = [ FIND, UPDATE, INSERT, DELETE, AGGREGATE,
|
17
|
-
SUCCEEDED, FAILED, ERROR, ENDSESSION ]
|
18
|
+
SUCCEEDED, FAILED, ERROR, ENDSESSION, INITIALIZING ]
|
18
19
|
|
19
20
|
# substring matches for unnecessary log messages that will be filtered out
|
20
21
|
UNNECESSARY = ["opology", "server description"]
|
21
22
|
|
22
23
|
# regex for for the log prefix that will be filtered out
|
23
24
|
# matches: +| localhost:27017 | app_test.update | STARTED |+
|
24
|
-
# note: +| STARTED |+ and +| SUCCEEDED |+ will be filtered due to redundancy
|
25
|
+
# note: +| STARTED |+ and +| SUCCEEDED |+ will be filtered due to redundancy,
|
25
26
|
# but +| FAILED |+ and others will not
|
26
27
|
PREFIX_REGEX = /\|.*?\|.*?\|( (SUCCEEDED|STARTED) \|)?/
|
27
28
|
end
|
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.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ibraheem Ahmed
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-07-
|
11
|
+
date: 2020-07-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -48,7 +48,7 @@ files:
|
|
48
48
|
- lib/mongo_beautiful_logger.rb
|
49
49
|
- lib/mongo_beautiful_logger/colors.rb
|
50
50
|
- lib/mongo_beautiful_logger/mongo_actions.rb
|
51
|
-
homepage: https://github.com/
|
51
|
+
homepage: https://github.com/ibraheemdev/mongo_beautiful_logger
|
52
52
|
licenses:
|
53
53
|
- MIT
|
54
54
|
metadata: {}
|