logrithm 0.2.0 → 0.2.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/logrithm/formatters/pretty.rb +26 -13
- data/lib/logrithm/log.rb +1 -1
- data/lib/logrithm/middleware/rack.rb +1 -3
- data/lib/logrithm/spitters/string.rb +5 -6
- data/lib/logrithm/utils/helpers.rb +2 -3
- data/lib/logrithm/version.rb +1 -1
- data/lib/logrithm.rb +2 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e7cc04ee6f656f889e885abb7b2fad8239812ab1
|
4
|
+
data.tar.gz: 2877580cfca21aad92a18e093893f7c1321ea14d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d7277a5c320908ebcb6a93ec0bc9d3aecb5997772cf60acecec31506b310042a8e8282ede7bbf614058de03ad83752fa0514106342e0efcb9fd3801c645de8d4
|
7
|
+
data.tar.gz: ee5794ce6f162305632923a6b78804e2302bee0c80c76ee552fca830cf6f081817ba17d4f08b92326ae522cd59fe66d80e745b97cef343dccf0ab8a47cd793b6
|
@@ -3,25 +3,38 @@ module Logrithm
|
|
3
3
|
module Pretty
|
4
4
|
def formatter
|
5
5
|
proc do |severity, datetime, _, message|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
6
|
+
if empty?(message)
|
7
|
+
''
|
8
|
+
else
|
9
|
+
'' <<
|
10
|
+
Log::INSTANCE.send(:lead, severity, datetime) <<
|
11
|
+
parse(message).map do |formatted|
|
12
|
+
Log::INSTANCE.send(:color, severity).last.colorize(formatted)
|
13
|
+
end.join(Logrithm::Log::JOINER) << $/
|
14
|
+
end
|
11
15
|
end
|
12
16
|
end
|
13
17
|
module_function :formatter
|
14
18
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
19
|
+
class << self
|
20
|
+
def parse(message)
|
21
|
+
return enum_for(:parse, message) unless block_given?
|
22
|
+
[*message].each do |obj|
|
23
|
+
klazz = obj.class.ancestors.inject(nil) do |memo, k|
|
24
|
+
memo || Utils::Helpers.constantize(k, Logrithm::Spitters)
|
25
|
+
end || Utils::Helpers.constantize(:string, Logrithm::Spitters)
|
26
|
+
yield klazz.new(obj).formatted
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def empty?(message)
|
31
|
+
return true if message.nil?
|
32
|
+
message = message.strip if message.respond_to?(:strip)
|
33
|
+
return true if message.respond_to?(:empty?) && message.empty?
|
34
|
+
return true if message.respond_to?(:blank?) && message.blank?
|
35
|
+
false
|
22
36
|
end
|
23
37
|
end
|
24
|
-
module_function :parse
|
25
38
|
end
|
26
39
|
end
|
27
40
|
end
|
data/lib/logrithm/log.rb
CHANGED
@@ -23,7 +23,7 @@ module Logrithm
|
|
23
23
|
def initialize(log = nil, **params)
|
24
24
|
[
|
25
25
|
File.join(__dir__, '..', '..', 'config', 'logrithm.yml'),
|
26
|
-
(File.join(Rails.root, 'config', 'logrithm.yml') if Logrithm.rails?)
|
26
|
+
(File.join((Rails.root || '.'), 'config', 'logrithm.yml') if Logrithm.rails?)
|
27
27
|
].compact.each do |cfg|
|
28
28
|
kungfuig(cfg) if File.exist?(cfg)
|
29
29
|
end
|
@@ -34,13 +34,11 @@ module Logrithm
|
|
34
34
|
end
|
35
35
|
|
36
36
|
# rubocop:disable Style/MethodName
|
37
|
-
# rubocop:disable Style/VariableName
|
38
37
|
# rubocop:disable Style/OpMethod
|
39
38
|
def ✍(what)
|
40
|
-
|
39
|
+
Logrithm.debug what unless what.blank?
|
41
40
|
end
|
42
41
|
# rubocop:enable Style/OpMethod
|
43
|
-
# rubocop:enable Style/VariableName
|
44
42
|
# rubocop:enable Style/MethodName
|
45
43
|
end
|
46
44
|
end
|
@@ -6,12 +6,11 @@ module Logrithm
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def formatted
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
# Logrithm::Utils::Output.clrz(str, Logrithm.color(:error).last)
|
9
|
+
case @obj
|
10
|
+
when ::String then @obj
|
11
|
+
when ::Symbol, ::Regexp then @obj.to_s
|
12
|
+
else @obj.inspect
|
13
|
+
end
|
15
14
|
end
|
16
15
|
end
|
17
16
|
end
|
@@ -2,10 +2,9 @@ module Logrithm
|
|
2
2
|
module Utils
|
3
3
|
module Helpers
|
4
4
|
class << self
|
5
|
-
def constantize(string, namespace = Kernel)
|
5
|
+
def constantize(string, namespace = Kernel, inherit = false)
|
6
6
|
namespace = Kernel.const_get(namespace) unless namespace.is_a?(Module)
|
7
|
-
|
8
|
-
result if namespace == Kernel || result.to_s =~ /\A#{namespace}/
|
7
|
+
namespace.const_get string.to_s.gsub(/(?:\A|_)(\w)/) { |m| m[-1].upcase }, inherit
|
9
8
|
rescue NameError
|
10
9
|
nil
|
11
10
|
end
|
data/lib/logrithm/version.rb
CHANGED
data/lib/logrithm.rb
CHANGED
@@ -40,7 +40,8 @@ require 'logrithm/log'
|
|
40
40
|
require 'logrithm/utils/output'
|
41
41
|
require 'logrithm/spitters'
|
42
42
|
|
43
|
-
require
|
43
|
+
# This require is to be put into Rails initializer
|
44
|
+
# require 'logrithm/middleware/rack'
|
44
45
|
|
45
46
|
module Logrithm
|
46
47
|
class << self
|