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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/nub/log.rb +47 -24
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 20dfa82087dac3fc6f2aca133219ffff8f13614017c6a0ce78c07b28ab63ccb1
4
- data.tar.gz: 4874238d59fab76c44734625345372ab8d18e465fb1c9d4c04399e57f2a3b936
3
+ metadata.gz: e811c301a7788614805f286b752b1f4d69f126ed694c27c1bfad8420396d8b33
4
+ data.tar.gz: 702005c8d194fccfe6cf410ccdd31fe86e87ee5f161dc4e5fc4775c9079df55c
5
5
  SHA512:
6
- metadata.gz: 02fc00dd683da7166068c94209cd154db09747c9adde25e5f397de7aefda175864cd3b35bbe3003cd3c75d4b3c3159fe6d1ff518feb577258cfbee3586c3f2f9
7
- data.tar.gz: 4dfcd93cacdd01224bad1872523f9e9d8473e07eac6d645fd70c56d00e8c98fd5b5b22301ff57c529de8b14c66e2e1974685f693c3edf6ef4a807f380b82a35f
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
- # Format the given string for use in log
72
- def format(str)
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 format, 1 = synchronize, 2 = format)
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
- loc = ":#{File.basename(stack[i].path, '.rb')}:#{label}:#{lineno}"
104
- return "#{Time.now.utc.iso8601(3)}#{loc}:: #{str}"
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
- # Determine if stamp should be used
113
- stamp = true
111
+ # Format message
114
112
  opts = args.find{|x| x.is_a?(Hash)}
115
- if opts and opts.key?(:stamp)
116
- stamp = opts[:stamp]
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
- # Format message
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
- # Determine if stamp should be used
137
- stamp = true
138
+ # Format message
138
139
  opts = args.find{|x| x.is_a?(Hash)}
139
- if opts and opts.key?(:stamp)
140
- stamp = opts[:stamp]
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
- return puts(*args) if LogLevel.warn <= @@_level
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
- return puts(*args) if LogLevel.info <= @@_level
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
- return puts(*args) if LogLevel.debug <= @@_level
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nub
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.36
4
+ version: 0.0.37
5
5
  platform: ruby
6
6
  authors:
7
7
  - Patrick Crummett