rmtools 2.4.0 → 2.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4af007b3b54a30faa10b74f7954970878d36ab73
4
- data.tar.gz: 202e16f990d3115ef0d9a934b0fec88f52c85644
3
+ metadata.gz: 3543de2cf0e25504f8c5be1c6e91aad75b102672
4
+ data.tar.gz: 75d5c56892deed75940a1d990e4bd681a39351a6
5
5
  SHA512:
6
- metadata.gz: 5c2869bcd4ca80a81bec45e10c23eb778bc48e03b89f9889d5efe901e09e28fb843204f9c293cb4b55032636175bf5fe8e9e8786632295c7c6e9c6a45fdd2c0c
7
- data.tar.gz: bec7b536593e4c95fbb689e5a9eed3aaa6f211eef5a895d2f9a76e11db4aa9d71237a37eebb568ea1d2292f5aff602a77b7b4b9bf0571add58553519559fac5d
6
+ metadata.gz: a2239289a4dde502cca7e83dfaff86803c56ac352b702f51012a6faa97443b87cd1600d03809131c5a3c49222a27a537b766d331a8dd1bb50fa9b62812c550ab
7
+ data.tar.gz: 0c1a64bdafb956dce0ae7af597fbe6f7f4188260ab1c471dfe6950dd91c2441dc72940063b78afa6c4654328d7f2b040f88ecca86bdafb59bedb20f65a88dc02
data/README.md CHANGED
@@ -29,6 +29,16 @@ It's still randomly documented since it's just my working tool.
29
29
 
30
30
  ### CHANGES
31
31
 
32
+ ##### Version 2.4.1
33
+
34
+ * Fixed trace_format for exceptions using Thread::Backtrace
35
+ * Added String#decapitalize and (for cyrillic strings) #funcap
36
+ * RMLogger
37
+ * made indifferent of global variables: $panic, $verbose, $quiet
38
+ * control log level by
39
+ * env variables (globally): LOGLEVEL, DEBUG || VERBOSE, WARN || QUIET, SILENT
40
+ * instance methods: log_level=, debug=, log=, info=, warn=, error=
41
+
32
42
  ##### Version 2.4.0
33
43
 
34
44
  * Ruby 2.1+ behaviour:
@@ -9,10 +9,10 @@ module RMTools
9
9
  # with caller processing and highlighting
10
10
  class RMLogger
11
11
  __init__
12
- attr_accessor :mute_info, :mute_warn, :mute_log, :mute_debug
12
+ attr_accessor :mute_info, :mute_error, :mute_warn, :mute_log, :mute_debug
13
13
  attr_reader :default_format
14
14
 
15
- Modes = [:debug, :log, :info, :warn]
15
+ Modes = [:debug, :log, :info, :warn, :error]
16
16
  NOPRINT = 8
17
17
  NOLOG = 4
18
18
  PREV_CALLER = 2
@@ -21,6 +21,7 @@ module RMTools
21
21
  def initialize format={}
22
22
  @c = Painter
23
23
  @highlight = {
24
+ :error => @c.red_bold("ERROR"),
24
25
  :warn => @c.red_bold("WARN"),
25
26
  :log => @c.cyan("INFO"),
26
27
  :info => @c.cyan_bold("INFO"),
@@ -28,6 +29,16 @@ module RMTools
28
29
  }
29
30
  @file_formats = Hash.new(@default_format = {})
30
31
  set_format :global, format
32
+
33
+ if ENV['LOGLEVEL']
34
+ self.log_level = ENV['LOGLEVEL']
35
+ elsif ENV['DEBUG'] || ENV['VERBOSE']
36
+ self.log_level = 'DEBUG'
37
+ elsif ENV['WARN'] || ENV['QUIET']
38
+ self.log_level = 'WARN'
39
+ elsif ENV['SILENT']
40
+ self.log_level = 'ERROR'
41
+ end
31
42
  end
32
43
 
33
44
  def _set_format file, format
@@ -97,6 +108,8 @@ module RMTools
97
108
  %{<Logger #{cfg.fmt.sub('%time', "%time(#{cfg.tf*'.'})").sub('%caller', "%caller(#{cfg.cf0})")}#{' -> '+cfg.out if cfg.out} #{modes.b ? modes.inspect : 'muted'}>}
98
109
  end
99
110
 
111
+ # TODO: добавить фильтров,
112
+ # например, для обработки текста, который будет логирован
100
113
  def _print mode, text, opts, caler, bind, cfg
101
114
  log_ = opts&NOLOG==0
102
115
  print_ = opts&NOPRINT==0
@@ -139,12 +152,22 @@ module RMTools
139
152
  end
140
153
 
141
154
  # controls:
142
- # - $panic: print debug messages
143
- # - $verbose: print log messages
144
- # - $quiet: print only warn messages regardless of other globals
145
- # - @mute_warn, @mute_info, @mute_log: do not print
146
- # this messages regardless of any globals
147
- # - @out_all: write to file any messages
155
+ # - @mute_warn, @mute_info, @mute_log, @mute_debug:
156
+ # do not print this messages regardless of any globals
157
+ # - @out_all: write to file info and debug messages
158
+ # - @out: write to file
159
+ # - @print: write to stdout
160
+
161
+ def error *args
162
+ cfg = get_config!
163
+ if (cfg.out or cfg.print) && !@mute_error
164
+ text, bind, opts = args.get_opts [!block_given? && args[0].kinda(Hash) ? args[0] : "\b\b ", nil], :mute => 0
165
+ opts[:mute] |= NOLOG if !cfg.out
166
+ opts[:mute] |= NOPRINT if !cfg.print
167
+ return if block_given? && (text = yield).nil?
168
+ _print(:error, text, opts[:mute], cfg._caller && (@current_caller || caller)[opts[:caller].to_i], bind, cfg)
169
+ end
170
+ end
148
171
 
149
172
  def warn *args
150
173
  cfg = get_config!
@@ -159,10 +182,10 @@ module RMTools
159
182
 
160
183
  def log *args
161
184
  cfg = get_config!
162
- if (cfg.out or cfg.print && !$quiet && $verbose) && !@mute_log
185
+ if (cfg.out or cfg.print) && !@mute_log
163
186
  text, bind, opts = args.get_opts [!block_given? && args[0].kinda(Hash) ? args[0] : "\b\b ", nil], :mute => 0
164
187
  opts[:mute] |= NOLOG if !cfg.out
165
- opts[:mute] |= NOPRINT if !(cfg.print && !$quiet && $verbose)
188
+ opts[:mute] |= NOPRINT if !cfg.print
166
189
  return if block_given? && (text = yield).nil?
167
190
  _print(:log, text, opts[:mute], cfg._caller && (@current_caller || caller)[opts[:caller].to_i], bind, cfg)
168
191
  end
@@ -170,10 +193,10 @@ module RMTools
170
193
 
171
194
  def info *args
172
195
  cfg = get_config!
173
- if (cfg.print && !$quiet or cfg.out && cfg.out_all) && !@mute_info
196
+ if (cfg.print or cfg.out && cfg.out_all) && !@mute_info
174
197
  text, bind, opts = args.get_opts [!block_given? && args[0].kinda(Hash) ? args[0] : "\b\b ", nil], :mute => 0
175
198
  opts[:mute] |= NOLOG if !(cfg.out && cfg.out_all)
176
- opts[:mute] |= NOPRINT if !(cfg.print && !$quiet)
199
+ opts[:mute] |= NOPRINT if !cfg.print
177
200
  return if block_given? && (text = yield).nil?
178
201
  _print(:info, text, opts[:mute], cfg._caller && (@current_caller || caller)[opts[:caller].to_i], bind, cfg)
179
202
  end
@@ -181,10 +204,10 @@ module RMTools
181
204
 
182
205
  def debug *args
183
206
  cfg = get_config!
184
- if (cfg.print && $panic && !$quiet or cfg.out && cfg.out_all) && !@mute_debug
207
+ if (cfg.print or cfg.out && cfg.out_all) && !@mute_debug
185
208
  text, bind, opts = args.get_opts [!block_given? && args[0].kinda(Hash) ? args[0] : "\b\b ", nil], :mute => 0
186
209
  opts[:mute] |= NOLOG if !(cfg.out && cfg.out_all)
187
- opts[:mute] |= NOPRINT if !(cfg.print && $panic && !$quiet)
210
+ opts[:mute] |= NOPRINT if !cfg.print
188
211
  return if block_given? && (text = yield).nil?
189
212
  _print(:debug, text, opts[:mute], cfg._caller && (@current_caller || caller)[opts[:caller].to_i], bind, cfg)
190
213
  end
@@ -192,12 +215,24 @@ module RMTools
192
215
 
193
216
  alias :<= :debug
194
217
  alias :<< :info
195
- alias :< :warn
196
218
  alias :puts :info
219
+ alias :< :warn
220
+ alias :fatal :error
197
221
 
198
222
  def print text
199
223
  info text, caller: 1, mute: INLINE
200
224
  end
225
+
226
+ def log_level=(level)
227
+ unless level.is_a? Integer
228
+ level = ::Logger.const_get(level.to_s.upcase)
229
+ end
230
+ self.debug = level < 1
231
+ self.info = level < 2
232
+ self.log = level < 2
233
+ self.warn = level < 3
234
+ self.error = level < 4
235
+ end
201
236
 
202
237
  Modes.each {|m| define_method("#{m}=") {|mute| send :"mute_#{m}=", !mute}}
203
238
 
@@ -104,12 +104,30 @@ class Exception
104
104
  # end
105
105
  # it will be possible to fetch lines entered in IRB
106
106
  # else format_trace would only read ordinally require'd files
107
- def set_backtrace src
108
- if format = self.class.trace_format
109
- src = RMTools.__send__ format, src
107
+ if RUBY_VERSION > '2.1'
108
+
109
+ def set_backtrace src
110
+ if format = self.class.trace_format
111
+ if src.is_a? Thread::Backtrace
112
+ return src
113
+ else
114
+ src = RMTools.__send__ format, src
115
+ end
116
+ end
117
+ set_bt src
110
118
  end
111
- set_bt src
119
+
120
+ else
121
+
122
+ def set_backtrace src
123
+ if format = self.class.trace_format
124
+ src = RMTools.__send__ format, src
125
+ end
126
+ set_bt src
127
+ end
128
+
112
129
  end
130
+
113
131
  end
114
132
 
115
133
  # This is the most usable setting, I think. Set it in the irbrc, config/initializers or wherever
@@ -84,6 +84,10 @@ class String
84
84
  def cuncap
85
85
  self[0].cdowncase + self[1..-1]
86
86
  end
87
+
88
+ def funcap
89
+ self[0].fdowncase + self[1..-1]
90
+ end
87
91
 
88
92
  alias csize size
89
93
  alias cljust ljust
@@ -70,6 +70,11 @@ class String
70
70
  end
71
71
  alias :next_version :bump_version
72
72
 
73
+ def uncap
74
+ self[0].downcase + self[1..-1]
75
+ end
76
+ alias :decapitalize :uncap
77
+
73
78
  def to_re(esc=false)
74
79
  Regexp.new(esc ? Regexp.escape(self) : self)
75
80
  end
@@ -1,3 +1,3 @@
1
1
  module RMTools
2
- VERSION = '2.4.0'
2
+ VERSION = '2.4.1'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rmtools
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.0
4
+ version: 2.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergey Baev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-21 00:00:00.000000000 Z
11
+ date: 2014-09-09 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: RMTools is a collection of helpers for debug, text/array/file processing
14
14
  and simply easing a coding process