logue 1.0.14 → 1.0.15

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: d93c0be8b98a96fa0f527a7fbf9ee887bc568152
4
- data.tar.gz: e4e95e29c3e01b1a979c34abd12941508851435d
3
+ metadata.gz: a7c205466841c21db43c8dbf6082280cfcaed239
4
+ data.tar.gz: a685296b9efad06ea3cbb8bbb25b9ed29dfaca65
5
5
  SHA512:
6
- metadata.gz: 610941e8a4c13e4a770fbc67ffa470091edf44ece9143bcce8bc0dc95c13e35571a16d87673194580755e57974933194a18665b52cd844c42dbfe150854b9ea1
7
- data.tar.gz: 337d2cab1cedc557e65ddc9d2c7d7110dccbf0ba32382d2ae365c945dd67f5f446558ea7b71a8fbfa46d900cef844c2bc5a25e0e5cf47f5e14980c5c8451f545
6
+ metadata.gz: 125a0d83eb0bdf5a155e8be2147a93c57896a096455c0e3df70395e80a0e37bcdb10494015546a8a3fa97c9396dd701712b016172d966fe6c0a33dbc4fea299b
7
+ data.tar.gz: a2d6cd9e512b3782fe13d9e220ec6f643acebfa9edd416d75bbbf451196b7bb6b90cc01e4b469870a124bf5990706ef9154fecfae285178e5a6543dac89d2d47
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- logue (1.0.13)
4
+ logue (1.0.15)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -43,17 +43,22 @@ module Logue
43
43
  end
44
44
 
45
45
  def add_color_method color, code
46
- meth = Array.new.tap do |a|
47
- a << 'def ' + color.to_s + '(msg = "", lvl = Logue::Level::DEBUG, classname: nil, &blk)'
48
- a << ' log("\e[' + code.to_s + 'm#{msg}\e[0m", level: lvl, classname: classname, &blk)'
49
- a << 'end'
50
- end
51
- instance_eval meth.join "\n"
46
+ instance_eval ColorLog.color_method_source(color, code)
52
47
  end
53
48
 
54
49
  def valid_colors
55
50
  # Rainbow::X11ColorNames::NAMES
56
51
  Rainbow::Color::Named::NAMES
57
52
  end
53
+
54
+ class << self
55
+ def color_method_source color, code
56
+ Array.new.tap do |a|
57
+ a << 'def ' + color.to_s + '(msg = "", lvl = Logue::Level::DEBUG, classname: nil, &blk)'
58
+ a << ' log("\e[' + code.to_s + 'm#{msg}\e[0m", level: lvl, classname: classname, &blk)'
59
+ a << 'end'
60
+ end.join "\n"
61
+ end
62
+ end
58
63
  end
59
64
  end
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/ruby -w
2
+ # -*- ruby -*-
3
+
4
+ module Logue
5
+ class Element
6
+ attr_reader :object
7
+
8
+ def initialize object
9
+ @object = object
10
+ end
11
+
12
+ def write output = $stdout
13
+ output.print @object.to_s
14
+ end
15
+ end
16
+ end
data/lib/logue/line.rb CHANGED
@@ -2,6 +2,8 @@
2
2
  # -*- ruby -*-
3
3
 
4
4
  require 'logue/location_format'
5
+ require 'logue/element'
6
+ require 'stringio'
5
7
 
6
8
  module Logue
7
9
  class Line
@@ -25,9 +27,13 @@ module Logue
25
27
  if @block
26
28
  @block.call.to_s
27
29
  elsif @obj
28
- "#{@msg}: #{@obj}"
30
+ elmt = Element.new @obj
31
+ io = StringIO.new
32
+ elmt.write io
33
+ io.close
34
+ @msg.to_s + ": " + io.string
29
35
  else
30
- "#{@msg}"
36
+ @msg.to_s
31
37
  end
32
38
  end
33
39
 
@@ -23,8 +23,8 @@ module Logue
23
23
 
24
24
  def format path, line, cls, methname
25
25
  name = cls ? cls.to_s + "#" + methname : methname
26
- path = PathUtil.trim_right path.to_s, @file
27
- name = PathUtil.trim_left name, @method
26
+ path = PathUtil.trim_right path.to_s, @file.abs
27
+ name = PathUtil.trim_left name, @method.abs
28
28
  sprintf format_string, path, line, name
29
29
  end
30
30
 
data/lib/logue/log.rb CHANGED
@@ -5,7 +5,7 @@
5
5
  #
6
6
  # Logging Module
7
7
  #
8
- # Author:: Jeff Pace
8
+ # Author:: Jeff Pace <jeugenepace@gmail.com>
9
9
  # Documentation:: Author
10
10
  #
11
11
 
@@ -27,21 +27,19 @@ require 'logue/logger'
27
27
  #
28
28
  # The most general usage is simply to call:
29
29
  #
30
- # Log.log "some message"
30
+ # Logue::Log::info "some message"
31
31
  #
32
32
  # That will simply log the given message.
33
33
  #
34
34
  # class YourClass
35
- # include Logue::Loggable
36
- #
37
- # def some_method(...)
38
- # log "my message"
35
+ # def some_method
36
+ # Logue::Log::debug "my message"
39
37
  #
40
38
  # That will log from the given class and method, showing the line number from
41
39
  # which the logger was called.
42
40
  #
43
- # def another_method(...)
44
- # stack "my message"
41
+ # def another_method
42
+ # Logue::Log::stack "my message"
45
43
  #
46
44
  # That will produce a stack trace from the given location.
47
45
  #
@@ -11,6 +11,7 @@
11
11
 
12
12
  require 'logue/logger'
13
13
  require 'logue/log'
14
+ require 'logue/colorlog'
14
15
 
15
16
  #
16
17
  # == Loggable
@@ -19,20 +20,20 @@ require 'logue/log'
19
20
  #
20
21
  # == Examples
21
22
  #
22
- # See the unit tests in log_test.rb
23
+ # See the unit tests in loggable_test.rb
23
24
  #
24
25
  # == Usage
25
26
  #
26
27
  # class YourClass
27
28
  # include Logue::Loggable
28
29
  #
29
- # def some_method(...)
30
+ # def some_method
30
31
  # log "my message"
31
32
  #
32
33
  # That will log from the given class and method, showing the line number from
33
34
  # which the logger was called.
34
35
  #
35
- # def another_method(...)
36
+ # def another_method
36
37
  # stack "my message"
37
38
  #
38
39
  # That will produce a stack trace from the given location.
@@ -40,60 +41,41 @@ require 'logue/log'
40
41
 
41
42
  module Logue
42
43
  module Loggable
43
- def logger
44
- @@logger ||= Logger.new
45
- end
46
-
47
- def logger= logger
48
- @@logger = logger
49
- end
50
-
51
- def respond_to_missing? *args
52
- true
53
- end
54
-
55
- def methods all = true
56
- methods_with_level + methods_without_level + super
57
- end
44
+ class << self
45
+ def add_delegator with_level, methnames
46
+ methnames.each do |methname|
47
+ lines = Array.new.tap do |a|
48
+ if with_level
49
+ a << "def #{methname} msg = '', obj = nil, level = Level::DEBUG, &blk"
50
+ a << " logger.send :#{methname}, msg, obj, level: level, classname: self.class.to_s, &blk"
51
+ else
52
+ a << "def #{methname} msg = '', obj = nil, &blk"
53
+ a << " logger.send :#{methname}, msg, obj, classname: self.class.to_s, &blk"
54
+ end
55
+ a << "end"
56
+ end
57
+
58
+ class_eval lines.join("\n")
59
+ end
60
+ end
58
61
 
59
- def methods_with_level
60
- [ :log, :stack ]
62
+ def add_color_methods colors
63
+ colors.each do |color, code|
64
+ class_eval ColorLog.color_method_source(color, code)
65
+ end
66
+ end
61
67
  end
62
68
 
63
- def methods_without_level
64
- [ :debug, :info, :error, :fatal, :write ] + logger.valid_colors.keys
69
+ def logger
70
+ @logger ||= Log.logger
65
71
  end
66
72
 
67
- def warn msg = "", obj = nil, &blk
68
- logger.warn msg, obj, classname: self.class.to_s, &blk
69
- end
73
+ add_delegator true, [ :log, :stack ]
74
+ add_delegator false, [ :debug, :info, :warn, :error, :fatal, :write ]
75
+ add_color_methods Rainbow::Color::Named::NAMES
70
76
 
71
- def method_missing methname, *args, &blk
72
- # only handling foregrounds, not backgrounds
73
- if methods_with_level.include? methname
74
- add_delegator methname, true
75
- send methname, *args, &blk
76
- elsif methods_without_level.include? methname
77
- add_delegator methname, false
78
- send methname, *args, &blk
79
- else
80
- super
81
- end
82
- end
83
-
84
- def add_delegator methname, with_level
85
- lines = Array.new.tap do |a|
86
- if with_level
87
- a << "def #{methname} msg = '', obj = nil, level = Level::DEBUG, &blk"
88
- a << " logger.send :#{methname}, msg, obj, level: level, classname: self.class.to_s, &blk"
89
- else
90
- a << "def #{methname} msg = '', obj = nil, &blk"
91
- a << " logger.send :#{methname}, msg, obj, classname: self.class.to_s, &blk"
92
- end
93
- a << "end"
94
- end
95
-
96
- instance_eval lines.join("\n")
77
+ def logger= logger
78
+ @logger = logger
97
79
  end
98
80
  end
99
81
  end
data/lib/logue/logger.rb CHANGED
@@ -9,12 +9,10 @@
9
9
  # Documentation:: Author
10
10
  #
11
11
 
12
- require 'logue/level'
13
12
  require 'logue/colorlog'
14
13
  require 'logue/writer'
15
14
  require 'logue/filter'
16
15
  require 'logue/legacy_logger'
17
- require 'logue/location'
18
16
  require 'logue/stack'
19
17
  require 'logue/line'
20
18
 
@@ -5,13 +5,11 @@ module Logue
5
5
  class PathUtil
6
6
  class << self
7
7
  def trim_left str, maxlen
8
- str[0 ... maxlen.to_i.abs]
8
+ str[0, maxlen] || ""
9
9
  end
10
10
 
11
11
  def trim_right str, maxlen
12
- mxln = maxlen.abs
13
-
14
- if str.length > mxln
12
+ if str.length > maxlen
15
13
  trim_path_right str, maxlen
16
14
  else
17
15
  str
@@ -19,17 +17,16 @@ module Logue
19
17
  end
20
18
 
21
19
  def trim_path_right path, maxlen
22
- mxln = maxlen.abs
23
-
20
+ return "" if maxlen < 0
24
21
  comps = path.split "/"
25
22
  str = comps.pop
26
23
  comps.reverse.each do |comp|
27
24
  newstr = comp + "/" + str
28
- if newstr.length + 4 <= mxln
25
+ if newstr.length + 4 <= maxlen
29
26
  str = newstr
30
27
  else
31
- newstr = "..." + "/" + str
32
- if newstr.length <= mxln
28
+ newstr = ".../" + str
29
+ if newstr.length <= maxlen
33
30
  str = newstr
34
31
  end
35
32
  break
data/lib/logue/version.rb CHANGED
@@ -2,5 +2,5 @@
2
2
  # -*- ruby -*-
3
3
 
4
4
  module Logue
5
- VERSION = '1.0.14'
5
+ VERSION = '1.0.15'
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logue
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.14
4
+ version: 1.0.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Pace
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-08-20 00:00:00.000000000 Z
11
+ date: 2018-08-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -98,6 +98,7 @@ files:
98
98
  - bin/setup
99
99
  - lib/logue.rb
100
100
  - lib/logue/colorlog.rb
101
+ - lib/logue/element.rb
101
102
  - lib/logue/filter.rb
102
103
  - lib/logue/frame.rb
103
104
  - lib/logue/legacy_logger.rb
@@ -134,7 +135,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
134
135
  version: '0'
135
136
  requirements: []
136
137
  rubyforge_project:
137
- rubygems_version: 2.5.2.1
138
+ rubygems_version: 2.6.3
138
139
  signing_key:
139
140
  specification_version: 4
140
141
  summary: A minimalist logging module.