GunnyLog 1.1.3 → 1.1.4
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/GunnyLog/severity.rb +35 -0
- data/lib/GunnyLog.rb +79 -53
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8998ce904556ed0da6e918201fdb0f12a0b06191
|
4
|
+
data.tar.gz: 2cf030be5f636749fe167417071fab8ae7cf0423
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a96f6392f2c2a5c99385ced29ac552acca7feb923759703141a4de007fff70a8430eb8ff6c07d77236e5fcf629c01a2b967c0df95882b7bf09a87f99eecf0c53
|
7
|
+
data.tar.gz: 4efcbdc2fc1e5ed22cfc0a66ed95c03581c2c3d6267b297f922eeba1400617196e769c7aaab27ce825866164e8891fb6928ac5a23a9db5e1489d5d1a784fde09
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# GunnyLog logs messages to stdout, stderr, or a file. It defaults
|
2
|
+
# to stdout. GunnyLog is a singleton and uses the instance method.
|
3
|
+
# For example you can use GunnyLog.instance.msg('Error message')
|
4
|
+
# or you can use log = GunnyLog.instance
|
5
|
+
class GunnyLog
|
6
|
+
|
7
|
+
public
|
8
|
+
|
9
|
+
DEBUG = 0
|
10
|
+
INFO = 1
|
11
|
+
WARNING = 2
|
12
|
+
ERROR = 3
|
13
|
+
FATAL = 4
|
14
|
+
UNKNOWN = 5
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def level_string(level)
|
19
|
+
case level
|
20
|
+
when 0
|
21
|
+
return 'DEBUG'
|
22
|
+
when 1
|
23
|
+
return 'INFO'
|
24
|
+
when 2
|
25
|
+
return 'WARNING'
|
26
|
+
when 3
|
27
|
+
return 'ERROR'
|
28
|
+
when 4
|
29
|
+
return 'FATAL'
|
30
|
+
else
|
31
|
+
return 'UNKNOWN'
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
data/lib/GunnyLog.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
# GunnyLog class
|
2
2
|
require 'GunnyLog/exceptions'
|
3
|
+
require 'GunnyLog/severity'
|
3
4
|
require 'singleton'
|
4
5
|
require 'date'
|
5
6
|
|
6
|
-
|
7
7
|
# GunnyLog logs messages to stdout, stderr, or a file. It defaults
|
8
8
|
# to stdout. GunnyLog is a singleton and uses the instance method.
|
9
9
|
# For example you can use GunnyLog.instance.msg('Error message')
|
@@ -14,7 +14,7 @@ class GunnyLog
|
|
14
14
|
|
15
15
|
private
|
16
16
|
|
17
|
-
|
17
|
+
# local debug messages
|
18
18
|
DEBUG_FLAG = false
|
19
19
|
|
20
20
|
# public class attributes
|
@@ -24,7 +24,13 @@ class GunnyLog
|
|
24
24
|
attr_reader :logging_enabled
|
25
25
|
|
26
26
|
# @return [string] message location
|
27
|
-
attr_reader :
|
27
|
+
attr_reader :logging_location
|
28
|
+
|
29
|
+
# @return [int] logging level
|
30
|
+
attr_reader :logging_level
|
31
|
+
|
32
|
+
# @return [string] message location
|
33
|
+
#attr_reader :message_location
|
28
34
|
|
29
35
|
# private class attributes
|
30
36
|
private
|
@@ -44,24 +50,23 @@ class GunnyLog
|
|
44
50
|
@logging_enabled = flag
|
45
51
|
end
|
46
52
|
|
47
|
-
# Set logging
|
48
|
-
# @
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
end
|
53
|
+
# Set logging level
|
54
|
+
# @param level [int] logging level
|
55
|
+
def set_logging_level(level)
|
56
|
+
@logging_level = level
|
57
|
+
end
|
53
58
|
|
54
|
-
# Set message was logged from
|
55
|
-
# @param loc [string]
|
56
|
-
def
|
57
|
-
@
|
59
|
+
# Set message was logged from logging location
|
60
|
+
# @param loc [string] logging location name
|
61
|
+
def set_logging_location(loc)
|
62
|
+
@logging_location = loc
|
58
63
|
end
|
59
64
|
|
60
|
-
# Set message was logged from
|
61
|
-
# @
|
62
|
-
# @
|
63
|
-
def
|
64
|
-
|
65
|
+
# Set message was logged from message location
|
66
|
+
# @param loc [string] message location name
|
67
|
+
# @deprecated Use {#set_logging_location} instead
|
68
|
+
def set_message_location(loc)
|
69
|
+
@logging_location = loc
|
65
70
|
end
|
66
71
|
|
67
72
|
# Set output to STDOUT, default
|
@@ -103,15 +108,6 @@ class GunnyLog
|
|
103
108
|
end
|
104
109
|
end
|
105
110
|
|
106
|
-
# Open the logfile with path, name, and extension
|
107
|
-
# @param pathname [string] path of the logfile
|
108
|
-
# @param filename [string] name of the logfile
|
109
|
-
# @param extension [string] extension of the logfile
|
110
|
-
# @deprecated Use {#open_file} instead
|
111
|
-
def open_with_info(pathname = nil, filename = 'gunnylog', extension = 'log')
|
112
|
-
self.open_file(pathname, filename, extension)
|
113
|
-
end
|
114
|
-
|
115
111
|
# Close the logfile
|
116
112
|
def close
|
117
113
|
begin
|
@@ -130,14 +126,14 @@ class GunnyLog
|
|
130
126
|
end
|
131
127
|
|
132
128
|
# Write message to logfile
|
133
|
-
# @param loc [string] message
|
129
|
+
# @param loc [string] message logging location, optional
|
134
130
|
# @param msg [string] message string
|
135
131
|
def message(loc = nil, msg)
|
136
132
|
write_msg(@logging_file, loc, msg)
|
137
133
|
end
|
138
134
|
|
139
135
|
# Write formatted message with single arg or array of args
|
140
|
-
# @param loc [string] message
|
136
|
+
# @param loc [string] message logging location, optional
|
141
137
|
# @param msg [string] message format string
|
142
138
|
# @param args [arg or array of args]
|
143
139
|
def message_formatted(loc = nil, msg, args)
|
@@ -146,7 +142,7 @@ class GunnyLog
|
|
146
142
|
end
|
147
143
|
|
148
144
|
# Write formatted message with variable number of args
|
149
|
-
# @param loc [string] message
|
145
|
+
# @param loc [string] message logging location
|
150
146
|
# @param msg [string] message format string
|
151
147
|
# @param args [variable number of args]
|
152
148
|
def message_formatted_vars(loc, msg, *args)
|
@@ -157,7 +153,7 @@ class GunnyLog
|
|
157
153
|
# Write exception to logfile
|
158
154
|
# @param exc [exception] exception to log
|
159
155
|
def msg_exception(exc)
|
160
|
-
write_msg(@logging_file, @
|
156
|
+
write_msg(@logging_file, @logging_location, exc.message)
|
161
157
|
end
|
162
158
|
|
163
159
|
# Write exception to logfile
|
@@ -166,24 +162,46 @@ class GunnyLog
|
|
166
162
|
write_msg(@logging_file, loc, exc.message)
|
167
163
|
end
|
168
164
|
|
169
|
-
# Write
|
170
|
-
# @param loc [string] message
|
165
|
+
# Write DEBUG message to logfile
|
166
|
+
# @param loc [string] message logging location, optional
|
171
167
|
# @param msg [string] message format string
|
172
|
-
|
173
|
-
|
174
|
-
def formatted_message(loc = nil, msg, args)
|
175
|
-
formatted = sprintf(msg, *args)
|
176
|
-
message(loc, formatted)
|
168
|
+
def log_debug(loc = nil, msg)
|
169
|
+
log(DEBUG, loc, msg)
|
177
170
|
end
|
178
171
|
|
179
|
-
# Write
|
180
|
-
# @param loc [string] message
|
172
|
+
# Write INFO message to logfile
|
173
|
+
# @param loc [string] message logging location, optional
|
181
174
|
# @param msg [string] message format string
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
175
|
+
def log_info(loc = nil, msg)
|
176
|
+
log(INFO, loc, msg)
|
177
|
+
end
|
178
|
+
|
179
|
+
# Write WARNING message to logfile
|
180
|
+
# @param loc [string] message logging location, optional
|
181
|
+
# @param msg [string] message format string
|
182
|
+
def log_warning(loc = nil, msg)
|
183
|
+
log(WARNING, loc, msg)
|
184
|
+
end
|
185
|
+
|
186
|
+
# Write ERROR message to logfile
|
187
|
+
# @param loc [string] message logging location, optional
|
188
|
+
# @param msg [string] message format string
|
189
|
+
def log_error(loc = nil, msg)
|
190
|
+
log(ERROR, loc, msg)
|
191
|
+
end
|
192
|
+
|
193
|
+
# Write FATAL message to logfile
|
194
|
+
# @param loc [string] message logging location, optional
|
195
|
+
# @param msg [string] message format string
|
196
|
+
def log_fatal(loc = nil, msg)
|
197
|
+
log(FATAL, loc, msg)
|
198
|
+
end
|
199
|
+
|
200
|
+
# Write UNKOWN message to logfile
|
201
|
+
# @param loc [string] message logging location, optional
|
202
|
+
# @param msg [string] message format string
|
203
|
+
def log_unknown(loc = nil, msg)
|
204
|
+
log(UNKNOWN, loc, msg)
|
187
205
|
end
|
188
206
|
|
189
207
|
# private instance methods
|
@@ -193,9 +211,10 @@ class GunnyLog
|
|
193
211
|
def initialize
|
194
212
|
#local_debug('initialize')
|
195
213
|
@logging_enabled = true
|
214
|
+
@logging_level = DEBUG
|
196
215
|
#@logging_severity = GunnyLogSeverity::DEBUG
|
197
216
|
#local_debug('initialize', sprintf('Log level = %d',@logging_severity) )
|
198
|
-
@
|
217
|
+
@logging_location = 'MainMethod'
|
199
218
|
@file_open = false
|
200
219
|
@logging_file = STDOUT
|
201
220
|
end
|
@@ -203,15 +222,27 @@ class GunnyLog
|
|
203
222
|
# write the msg
|
204
223
|
def write_msg(output, loc, msg)
|
205
224
|
if loc == nil
|
206
|
-
loc = @
|
225
|
+
loc = @logging_location
|
207
226
|
else
|
208
|
-
@
|
227
|
+
@logging_location = loc
|
209
228
|
end
|
210
229
|
if @logging_enabled
|
211
230
|
output.puts "#{date_str}|#{$0}|#{loc}|#{msg}"
|
212
231
|
end
|
213
232
|
end
|
214
233
|
|
234
|
+
def log(sev, loc, msg)
|
235
|
+
if loc == nil
|
236
|
+
loc = @logging_location
|
237
|
+
else
|
238
|
+
@logging_location = loc
|
239
|
+
end
|
240
|
+
if @logging_enabled and sev >= @logging_level
|
241
|
+
@logging_file.puts "#{date_str}|#{$0}|#{level_string(sev)}|#{loc}|#{msg}"
|
242
|
+
end
|
243
|
+
end
|
244
|
+
|
245
|
+
|
215
246
|
# get the date time stamp
|
216
247
|
def date_str
|
217
248
|
d = DateTime.now
|
@@ -235,9 +266,4 @@ class GunnyLog
|
|
235
266
|
end
|
236
267
|
end
|
237
268
|
|
238
|
-
end
|
239
|
-
|
240
|
-
|
241
|
-
# @deprecated Use {GunnyLog} instead
|
242
|
-
class GunnyLogFile < GunnyLog
|
243
269
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: GunnyLog
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- GunnyHwy
|
@@ -18,6 +18,7 @@ extra_rdoc_files: []
|
|
18
18
|
files:
|
19
19
|
- lib/GunnyLog.rb
|
20
20
|
- lib/GunnyLog/exceptions.rb
|
21
|
+
- lib/GunnyLog/severity.rb
|
21
22
|
- README.md
|
22
23
|
homepage: http://rubygems.org/gems/GunnyLog
|
23
24
|
licenses:
|