logrithm 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/logrithm/formatters/pretty.rb +1 -1
- data/lib/logrithm/log.rb +16 -12
- data/lib/logrithm/utils/helpers.rb +2 -2
- data/lib/logrithm/version.rb +1 -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: 86cba65ebff7f5967d1adbfb48940c461ba76511
|
4
|
+
data.tar.gz: 7a10a6397937fa1500de32f65123776e27003ed5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b5a0d7e43974711935fe2e8f5faefc7c5e9dd663fe3ff683f9c4b810cb0528c8478880841c8bf7126fcaa58a10008e0386b27ec36a46f475d0943c3040eb5054
|
7
|
+
data.tar.gz: 445167639261857670d8e2f72cbc55ae801d4e3abe5116410d0f935f0ef4805465780edbfd40d23bfc268544275490c5e5e0eae41d6b43f576832ddaca6ce1b3
|
@@ -23,7 +23,7 @@ module Logrithm
|
|
23
23
|
klazz = obj.class.ancestors.inject(nil) do |memo, k|
|
24
24
|
memo || Utils::Helpers.constantize(k, Logrithm::Spitters)
|
25
25
|
end || Utils::Helpers.constantize(:string, Logrithm::Spitters)
|
26
|
-
yield klazz.new(obj).formatted
|
26
|
+
yield klazz.new(obj).formatted unless empty?(obj)
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
data/lib/logrithm/log.rb
CHANGED
@@ -7,18 +7,7 @@ module Logrithm
|
|
7
7
|
include Kungfuig
|
8
8
|
|
9
9
|
JOINER = "#{$/} #{option(:log, :joiners, :objects) || '⮩ '}".freeze
|
10
|
-
|
11
|
-
def self.log(message)
|
12
|
-
if $♯
|
13
|
-
puts "Self: [#{$♯}], Message: [#{message}]."
|
14
|
-
else
|
15
|
-
# idx = caller.index { |s| s.include? __FILE__ } to work inside pry
|
16
|
-
Utils::Syringe.inject(*Utils::Helpers.dirty_lookup_class_method(*caller.first[/\A(.+):(\d+)(?=:in)/].split(/:(?=\d+\z)/)))
|
17
|
-
puts "Message: [#{message}]."
|
18
|
-
end
|
19
|
-
rescue
|
20
|
-
puts "Message: [#{message}]."
|
21
|
-
end
|
10
|
+
USE_GLOBAL_SELF = option(:log, :global_self) || false
|
22
11
|
|
23
12
|
def initialize(log = nil, **params)
|
24
13
|
[
|
@@ -54,6 +43,21 @@ module Logrithm
|
|
54
43
|
|
55
44
|
%i(debug info warn error fatal).each do |m|
|
56
45
|
define_method(m) do |*args, **extended|
|
46
|
+
# rubocop:disable Lint/HandleExceptions
|
47
|
+
# rubocop:disable Style/RescueModifier
|
48
|
+
if USE_GLOBAL_SELF && $♯.nil?
|
49
|
+
caller_line = caller.detect do |line|
|
50
|
+
Logrithm.rails? ? line.start_with?(Rails.root.to_s) : !line.start_with?(__dir__)
|
51
|
+
end
|
52
|
+
cf = caller_line[/\A(.+):(\d+)(?=:in)/].split(/:(?=\d+\z)/)
|
53
|
+
if cf.is_a?(Array) && cf.first.is_a?(String)
|
54
|
+
Utils::Syringe.inject(*Utils::Helpers.dirty_lookup_class_method(*cf))
|
55
|
+
end
|
56
|
+
end rescue nil # SUPPRESS
|
57
|
+
# rubocop:enable Style/RescueModifier
|
58
|
+
# rubocop:enable Lint/HandleExceptions
|
59
|
+
args << $♯ if $♯ # global constant storing the object
|
60
|
+
|
57
61
|
logger.public_send m, (args.length == 1 && extended.empty? ? args.first : [*args, **extended])
|
58
62
|
end
|
59
63
|
end
|
@@ -12,8 +12,8 @@ module Logrithm
|
|
12
12
|
def dirty_lookup_class_method(file, lineno)
|
13
13
|
content = File.readlines(file)[0..lineno.to_i].reverse
|
14
14
|
result = content.each_with_object(method: nil, ns: []) do |line, memo|
|
15
|
-
(memo[:method] ||= line[/\A\s*def\s
|
16
|
-
(memo[:ns] << line[/\A\s*(?:class|module)\s
|
15
|
+
(memo[:method] ||= line[/\A\s*def\s+(?<method>\w+)/, :method]) &&
|
16
|
+
(memo[:ns] << line[/\A\s*(?:class|module)\s+(?<ns>\w+)/, :ns])
|
17
17
|
end
|
18
18
|
|
19
19
|
[const_get(result[:ns].compact.reverse.join('::')), result[:method]]
|
data/lib/logrithm/version.rb
CHANGED