nub 0.0.36 → 0.0.37
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 +4 -4
- data/lib/nub/log.rb +47 -24
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e811c301a7788614805f286b752b1f4d69f126ed694c27c1bfad8420396d8b33
|
4
|
+
data.tar.gz: 702005c8d194fccfe6cf410ccdd31fe86e87ee5f161dc4e5fc4775c9079df55c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4ece535ae79f6bbd0ae0e3c539b508f0df3b80e496db9be23459dfecec5f3f888c8c2689b729667f3971fdc9b575347ecf1c294a13cdf619aecb2abd92b082f9
|
7
|
+
data.tar.gz: 7a71e5cdcfa4f8fcc1c82757fe514a537a138737ce5c01b59a6fd2906b71b10b5182770c2134a062dd2cdcdf57c78ac6655f6447cd4b5cc88954ed3531fc08a3
|
data/lib/nub/log.rb
CHANGED
@@ -68,13 +68,12 @@ module Log
|
|
68
68
|
end
|
69
69
|
end
|
70
70
|
|
71
|
-
#
|
72
|
-
def
|
71
|
+
# Get timestamp and location of call
|
72
|
+
def call_details
|
73
73
|
@@_monitor.synchronize{
|
74
74
|
|
75
|
-
# Skip first 3 on stack (i.e. 0 = block in
|
75
|
+
# Skip first 3 on stack (i.e. 0 = block in call_details, 1 = synchronize, 2 = call_detail)
|
76
76
|
stack = caller_locations(3, 10)
|
77
|
-
#stack.each{|x| $stdout.puts(x.label)}
|
78
77
|
|
79
78
|
# Skip past any calls in 'log.rb' or 'monitor.rb'
|
80
79
|
i = -1
|
@@ -100,8 +99,8 @@ module Log
|
|
100
99
|
label = stack[i].label if label.empty?
|
101
100
|
|
102
101
|
# Construct stamp
|
103
|
-
|
104
|
-
return
|
102
|
+
location = ":#{File.basename(stack[i].path, '.rb')}:#{label}:#{lineno}"
|
103
|
+
return Time.now.utc.iso8601(3), location
|
105
104
|
}
|
106
105
|
end
|
107
106
|
|
@@ -109,16 +108,19 @@ module Log
|
|
109
108
|
@@_monitor.synchronize{
|
110
109
|
str = !args.first.is_a?(Hash) ? args.first.to_s : ''
|
111
110
|
|
112
|
-
#
|
113
|
-
stamp = true
|
111
|
+
# Format message
|
114
112
|
opts = args.find{|x| x.is_a?(Hash)}
|
115
|
-
|
116
|
-
|
113
|
+
loc = (opts && opts.key?(:loc)) ? opts[:loc] : false
|
114
|
+
type = (opts && opts.key?(:type)) ? opts[:type] : ""
|
115
|
+
stamp = (opts && opts.key?(:stamp)) ? opts[:stamp] : true
|
116
|
+
if stamp or loc
|
117
|
+
timestamp, location = call_details
|
118
|
+
location = loc ? location : ""
|
119
|
+
type = ":#{type}" if !type.empty?
|
120
|
+
str = "#{timestamp}#{location}#{type}:: #{str}"
|
117
121
|
end
|
118
122
|
|
119
|
-
#
|
120
|
-
str = format(str) if stamp
|
121
|
-
|
123
|
+
# Handle output
|
122
124
|
if !str.empty?
|
123
125
|
@file << Sys.strip_colorize(str) if @path
|
124
126
|
@@_queue << str if @@_queue
|
@@ -133,16 +135,18 @@ module Log
|
|
133
135
|
@@_monitor.synchronize{
|
134
136
|
str = !args.first.is_a?(Hash) ? args.first.to_s : ''
|
135
137
|
|
136
|
-
#
|
137
|
-
stamp = true
|
138
|
+
# Format message
|
138
139
|
opts = args.find{|x| x.is_a?(Hash)}
|
139
|
-
|
140
|
-
|
140
|
+
loc = (opts && opts.key?(:loc)) ? opts[:loc] : false
|
141
|
+
type = (opts && opts.key?(:type)) ? opts[:type] : ""
|
142
|
+
stamp = (opts && opts.key?(:stamp)) ? opts[:stamp] : true
|
143
|
+
if stamp or loc
|
144
|
+
timestamp, location = call_details
|
145
|
+
location = loc ? location : ""
|
146
|
+
type = ":#{type}" if !type.empty?
|
147
|
+
str = "#{timestamp}#{location}#{type}:: #{str}"
|
141
148
|
end
|
142
149
|
|
143
|
-
# Format message
|
144
|
-
str = format(str) if stamp
|
145
|
-
|
146
150
|
# Handle output
|
147
151
|
@file.puts(Sys.strip_colorize(str)) if @path
|
148
152
|
@@_queue << "#{str}\n" if @@_queue
|
@@ -153,28 +157,47 @@ module Log
|
|
153
157
|
end
|
154
158
|
|
155
159
|
def error(*args)
|
160
|
+
opts = args.find{|x| x.is_a?(Hash)}
|
161
|
+
opts[:loc] = true and opts[:type] = 'E' if opts
|
162
|
+
args << {:loc => true, :type => 'E'} if !opts
|
163
|
+
|
156
164
|
return puts(*args)
|
157
165
|
end
|
158
166
|
|
159
167
|
def warn(*args)
|
160
|
-
|
168
|
+
if LogLevel.warn <= @@_level
|
169
|
+
opts = args.find{|x| x.is_a?(Hash)}
|
170
|
+
opts[:type] = 'W' if opts
|
171
|
+
args << {:type => 'W'} if !opts
|
172
|
+
return puts(*args)
|
173
|
+
end
|
161
174
|
return true
|
162
175
|
end
|
163
176
|
|
164
177
|
def info(*args)
|
165
|
-
|
178
|
+
if LogLevel.info <= @@_level
|
179
|
+
opts = args.find{|x| x.is_a?(Hash)}
|
180
|
+
opts[:type] = 'I' if opts
|
181
|
+
args << {:type => 'I'} if !opts
|
182
|
+
return puts(*args)
|
183
|
+
end
|
166
184
|
return true
|
167
185
|
end
|
168
186
|
|
169
187
|
def debug(*args)
|
170
|
-
|
188
|
+
if LogLevel.debug <= @@_level
|
189
|
+
opts = args.find{|x| x.is_a?(Hash)}
|
190
|
+
opts[:type] = 'D' if opts
|
191
|
+
args << {:type => 'D'} if !opts
|
192
|
+
return puts(*args)
|
193
|
+
end
|
171
194
|
return true
|
172
195
|
end
|
173
196
|
|
174
197
|
# Log the given message in red and exit
|
175
198
|
# @param msg [String] message to log
|
176
199
|
def die(msg)
|
177
|
-
puts(msg.colorize(:red)) and exit
|
200
|
+
puts(msg.colorize(:red), loc:true, type:'DIE') and exit
|
178
201
|
end
|
179
202
|
|
180
203
|
# Remove an item from the queue, block until one exists
|