rmtools 2.4.0 → 2.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +10 -0
- data/lib/rmtools/dev/logging.rb +50 -15
- data/lib/rmtools/dev/trace_format.rb +22 -4
- data/lib/rmtools/lang/cyrillic.rb +4 -0
- data/lib/rmtools/text/string_simple.rb +5 -0
- data/lib/rmtools/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3543de2cf0e25504f8c5be1c6e91aad75b102672
|
4
|
+
data.tar.gz: 75d5c56892deed75940a1d990e4bd681a39351a6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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:
|
data/lib/rmtools/dev/logging.rb
CHANGED
@@ -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
|
-
# -
|
143
|
-
#
|
144
|
-
# -
|
145
|
-
# - @
|
146
|
-
#
|
147
|
-
|
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
|
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 !
|
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
|
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 !
|
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
|
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 !
|
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
|
-
|
108
|
-
|
109
|
-
|
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
|
-
|
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
|
data/lib/rmtools/version.rb
CHANGED
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.
|
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-
|
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
|