logrithm 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2641dcf0038e8cd1fc2df39d52136413be3c974c
4
- data.tar.gz: e41c59225bd7dc8c3145e0fb9ccc784fa9489363
3
+ metadata.gz: e7cc04ee6f656f889e885abb7b2fad8239812ab1
4
+ data.tar.gz: 2877580cfca21aad92a18e093893f7c1321ea14d
5
5
  SHA512:
6
- metadata.gz: c45a5f6f871cba9c060c80531fa2cd98f96f430d0239ba3c0abb7630bb91dc471beedbbb3ea40621680d760cf48100cf62c914b10895eefcc58e262c54192008
7
- data.tar.gz: e7894f3ae6bbaf81639be0ee99879b534a48543b3e274f9ec2a8c090b59321d9b45f64f7c714920d65037e2a1080554b12eebd3f61f98517710f71615b0d2dba
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
- Log::INSTANCE.send(:lead, severity, datetime) <<
8
- parse(message).map do |formatted|
9
- Log::INSTANCE.send(:color, severity).last.colorize(formatted)
10
- end.join(Logrithm::Log::JOINER) << $/
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
- def parse(message)
16
- return enum_for(:parse, message) unless block_given?
17
- [*message].each do |obj|
18
- klazz = obj.class.ancestors.inject(nil) do |memo, k|
19
- memo || Utils::Helpers.constantize(k, Logrithm::Spitters)
20
- end || Utils::Helpers.constantize(:string, Logrithm::Spitters)
21
- yield klazz.new(obj).formatted
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
- (@✍ ||= Logrithm::INSTANCE).rack what
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
- str = case @obj
10
- when String then @obj
11
- when Symbol, Regexp then @obj.to_s
12
- else @obj.inspect
13
- end
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
- result = namespace.const_get string.to_s.gsub(/(?:\A|_)(\w)/) { |m| m[-1].upcase }
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
@@ -1,3 +1,3 @@
1
1
  module Logrithm
2
- VERSION = '0.2.0'
2
+ VERSION = '0.2.1'
3
3
  end
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 'logrithm/middleware/rack'
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logrithm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aleksei Matiushkin