GunnyLog 1.0.9 → 1.1.0
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/README.md +38 -0
- data/lib/GunnyLog.rb +70 -24
- data/lib/GunnyLog/version.rb +1 -1
- 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: 73d2ba22a9990c09f32fd64d272808bad6fef44a
|
4
|
+
data.tar.gz: 1473871267f074e583165595d87deff8952474e3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 759b45c1e539fb8e08448c36c01b8d30085f1a0a85802d85b6dd4fbc6499f6cd6d806510af35fb2545e8ed6a86fd0cfdfae91a5e8bd4e37f7ed360f37be1870d
|
7
|
+
data.tar.gz: 42a0318e63af4e9f96402bb4d5ea743bee0f302ed616a3f906d189df5b3f40ad7bc8bf2aaf0718655464f3163cf6a99bffc72b1d8f46accdd2fb046b59c0cdee
|
data/README.md
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# GunnyLog
|
2
|
+
|
3
|
+
Ruby logfile class
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'GunnyLog'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install GunnyLog
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
See test/testapp01.rb for examples
|
24
|
+
|
25
|
+
## Documentation
|
26
|
+
|
27
|
+
http://rubydoc.info/gems/GunnyLog/frames/index
|
28
|
+
|
29
|
+
## Contributing
|
30
|
+
|
31
|
+
1. Fork it ( https://github.com/gunnyhwy/GunnyLog/fork )
|
32
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
33
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
34
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
35
|
+
5. Create a new Pull Request
|
36
|
+
|
37
|
+
Thanks!
|
38
|
+
Gunny
|
data/lib/GunnyLog.rb
CHANGED
@@ -4,6 +4,7 @@ require 'GunnyLog/exceptions'
|
|
4
4
|
require 'singleton'
|
5
5
|
require 'date'
|
6
6
|
|
7
|
+
|
7
8
|
# GunnyLog logs messages to stdout, stderr, or a file. It defaults
|
8
9
|
# to stdout. GunnyLog is a singleton and uses the instance method.
|
9
10
|
# For example you can use GunnyLog.instance.msg('Error message')
|
@@ -17,11 +18,11 @@ class GunnyLog
|
|
17
18
|
class << self;
|
18
19
|
# Logging flag on and off (default=on)
|
19
20
|
private
|
20
|
-
attr_accessor :
|
21
|
+
attr_accessor :logging_enabled
|
21
22
|
end
|
22
23
|
|
23
24
|
# @return [bool] is logging enabled
|
24
|
-
attr_reader :
|
25
|
+
attr_reader :logging_enabled
|
25
26
|
|
26
27
|
class << self;
|
27
28
|
# The location that the message was from
|
@@ -37,7 +38,7 @@ class GunnyLog
|
|
37
38
|
class << self;
|
38
39
|
# Is file open flag
|
39
40
|
private
|
40
|
-
attr_accessor :
|
41
|
+
attr_accessor :file_open
|
41
42
|
end
|
42
43
|
|
43
44
|
class << self;
|
@@ -51,14 +52,14 @@ class GunnyLog
|
|
51
52
|
# Set logging on and off
|
52
53
|
# @param flag [bool] switch for on or off
|
53
54
|
def set_logging_enabled(flag)
|
54
|
-
@
|
55
|
+
@logging_enabled = flag
|
55
56
|
end
|
56
57
|
|
57
58
|
# Set logging on and off
|
58
59
|
# @deprecated Use {#set_logging_enabled} instead
|
59
60
|
# @param flag [bool] switch for on or off
|
60
61
|
def set_switch(flag)
|
61
|
-
@
|
62
|
+
@logging_enabled = flag
|
62
63
|
end
|
63
64
|
|
64
65
|
# Set message was logged from message_location
|
@@ -76,7 +77,7 @@ class GunnyLog
|
|
76
77
|
|
77
78
|
# Set output to STDOUT, default
|
78
79
|
def set_output_stdout
|
79
|
-
if @
|
80
|
+
if @file_open
|
80
81
|
self.close
|
81
82
|
end
|
82
83
|
@logging_file = STDOUT
|
@@ -84,7 +85,7 @@ class GunnyLog
|
|
84
85
|
|
85
86
|
# Set output to STDERR
|
86
87
|
def set_output_stderr
|
87
|
-
if @
|
88
|
+
if @file_open
|
88
89
|
self.close
|
89
90
|
end
|
90
91
|
@logging_file = STDERR
|
@@ -95,9 +96,9 @@ class GunnyLog
|
|
95
96
|
def open(filename = 'gunnylog.log')
|
96
97
|
begin
|
97
98
|
@logging_file = File.open(filename, 'a+')
|
98
|
-
@
|
99
|
-
rescue SystemCallError
|
100
|
-
|
99
|
+
@file_open = true
|
100
|
+
rescue SystemCallError => exc
|
101
|
+
handle_exception(exc)
|
101
102
|
end
|
102
103
|
end
|
103
104
|
|
@@ -105,9 +106,7 @@ class GunnyLog
|
|
105
106
|
# @param pathname [string] path of the logfile
|
106
107
|
# @param filename [string] name of the logfile
|
107
108
|
# @param extension [string] extension of the logfile
|
108
|
-
def
|
109
|
-
filename = 'gunnylog',
|
110
|
-
extension = 'log')
|
109
|
+
def open_file(pathname = nil, filename = 'gunnylog', extension = 'log')
|
111
110
|
if pathname == nil
|
112
111
|
self.open(filename + '.' + extension)
|
113
112
|
else
|
@@ -115,24 +114,33 @@ class GunnyLog
|
|
115
114
|
end
|
116
115
|
end
|
117
116
|
|
117
|
+
# Open the logfile with path, name, and extension
|
118
|
+
# @param pathname [string] path of the logfile
|
119
|
+
# @param filename [string] name of the logfile
|
120
|
+
# @param extension [string] extension of the logfile
|
121
|
+
# @deprecated Use {#open_file} instead
|
122
|
+
def open_with_info(pathname = nil, filename = 'gunnylog', extension = 'log')
|
123
|
+
self.open_file(pathname, filename, extension)
|
124
|
+
end
|
125
|
+
|
118
126
|
# Close the logfile
|
119
127
|
def close
|
120
128
|
begin
|
121
129
|
@logging_file.close
|
122
|
-
@
|
130
|
+
@file_open = false
|
123
131
|
@logging_file = STDOUT
|
124
|
-
rescue SystemCallError
|
125
|
-
|
132
|
+
rescue SystemCallError => exc
|
133
|
+
handle_exception(exc)
|
126
134
|
end
|
127
135
|
end
|
128
136
|
|
129
|
-
# Write message to
|
137
|
+
# Write message to logfile
|
130
138
|
# @param msg [string] message string
|
131
139
|
def msg(msg)
|
132
140
|
message(nil, msg)
|
133
141
|
end
|
134
142
|
|
135
|
-
# Write message to
|
143
|
+
# Write message to logfile
|
136
144
|
# @param loc [string] message message_location, optional
|
137
145
|
# @param msg [string] message string
|
138
146
|
def message(loc = nil, msg)
|
@@ -143,7 +151,7 @@ class GunnyLog
|
|
143
151
|
# @param loc [string] message message_location, optional
|
144
152
|
# @param msg [string] message format string
|
145
153
|
# @param args [arg or array of args]
|
146
|
-
def
|
154
|
+
def message_formatted(loc = nil, msg, args)
|
147
155
|
formatted = sprintf(msg, *args)
|
148
156
|
message(loc, formatted)
|
149
157
|
end
|
@@ -152,19 +160,51 @@ class GunnyLog
|
|
152
160
|
# @param loc [string] message message_location
|
153
161
|
# @param msg [string] message format string
|
154
162
|
# @param args [variable number of args]
|
155
|
-
def
|
163
|
+
def message_formatted_vars(loc, msg, *args)
|
156
164
|
formatted = sprintf(msg, *args)
|
157
165
|
message(loc, formatted)
|
158
166
|
end
|
159
167
|
|
168
|
+
# Write exception to logfile
|
169
|
+
# @param exc [exception] exception to log
|
170
|
+
def msg_exception(exc)
|
171
|
+
write_msg(@logging_file, @message_location, exc.message)
|
172
|
+
end
|
173
|
+
|
174
|
+
# Write exception to logfile
|
175
|
+
# @param exc [exception] exception to log
|
176
|
+
def message_exception(loc = nil, exc)
|
177
|
+
write_msg(@logging_file, loc, exc.message)
|
178
|
+
end
|
179
|
+
|
180
|
+
# Write formatted message with single arg or array of args
|
181
|
+
# @param loc [string] message message_location, optional
|
182
|
+
# @param msg [string] message format string
|
183
|
+
# @param args [arg or array of args]
|
184
|
+
# @deprecated Use {#message_formatted} instead
|
185
|
+
def formatted_message(loc = nil, msg, args)
|
186
|
+
formatted = sprintf(msg, *args)
|
187
|
+
message(loc, formatted)
|
188
|
+
end
|
189
|
+
|
190
|
+
# Write formatted message with variable number of args
|
191
|
+
# @param loc [string] message message_location
|
192
|
+
# @param msg [string] message format string
|
193
|
+
# @param args [variable number of args]
|
194
|
+
# @deprecated Use {#message_formatted_vars} instead
|
195
|
+
def formatted_message_vars(loc, msg, *args)
|
196
|
+
formatted = sprintf(msg, *args)
|
197
|
+
message(loc, formatted)
|
198
|
+
end
|
199
|
+
|
160
200
|
# private instance methods
|
161
201
|
private
|
162
202
|
|
163
203
|
# initailize
|
164
204
|
def initialize
|
165
|
-
@
|
205
|
+
@logging_enabled = true
|
166
206
|
@message_location = 'MainMethod'
|
167
|
-
@
|
207
|
+
@file_open = false
|
168
208
|
@logging_file = STDOUT
|
169
209
|
end
|
170
210
|
|
@@ -175,7 +215,7 @@ class GunnyLog
|
|
175
215
|
else
|
176
216
|
@message_location = loc
|
177
217
|
end
|
178
|
-
if @
|
218
|
+
if @logging_enabled
|
179
219
|
output.puts "#{date_str}|#{$0}|#{loc}|#{msg}"
|
180
220
|
end
|
181
221
|
end
|
@@ -186,9 +226,15 @@ class GunnyLog
|
|
186
226
|
d.strftime('%m/%d/%Y|%I:%M:%S%p')
|
187
227
|
end
|
188
228
|
|
229
|
+
# log exception and raise
|
230
|
+
def handle_exception(exc)
|
231
|
+
self.message_exception('***GunnyLog***', exc)
|
232
|
+
raise GunnyLogException.new(exc.message)
|
233
|
+
end
|
234
|
+
|
189
235
|
end
|
190
236
|
|
191
237
|
|
192
|
-
# @deprecated Use {
|
238
|
+
# @deprecated Use {GunnyLog} instead
|
193
239
|
class GunnyLogFile < GunnyLog
|
194
240
|
end
|
data/lib/GunnyLog/version.rb
CHANGED
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.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- GunnyHwy
|
@@ -19,6 +19,7 @@ files:
|
|
19
19
|
- lib/GunnyLog.rb
|
20
20
|
- lib/GunnyLog/version.rb
|
21
21
|
- lib/GunnyLog/exceptions.rb
|
22
|
+
- README.md
|
22
23
|
homepage: http://rubygems.org/gems/GunnyLog
|
23
24
|
licenses:
|
24
25
|
- GPL v3
|