GunnyLog 1.0.3 → 1.0.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.rb +58 -26
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ce05dbfada2cc1e42ff869d414a8a4e671f4b95f
|
4
|
+
data.tar.gz: fa999833bef668ac86de3e7cfbf42455947b034a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cc374fce9a7214cf426a3e93357ccf73ee09129161bed98ce5b781d6640fe50002af7b1693ff954a21b5e29f697f4fc285785100a790911522a39c66457022af
|
7
|
+
data.tar.gz: a72e128408ce5498d3526485e4a4c9d461b4fe8c013648c80ada8895928a3ecd45b2a8905f33fd389d39b5e0363e558007470f86a2bb147147b6ab5612c381cf
|
data/lib/GunnyLog.rb
CHANGED
@@ -5,37 +5,51 @@ require 'date'
|
|
5
5
|
|
6
6
|
# GunnyLog logs messages to stdout or a file
|
7
7
|
class GunnyLog
|
8
|
-
|
9
|
-
include Singleton
|
10
8
|
|
11
|
-
#
|
12
|
-
|
9
|
+
# Singleton instance method
|
10
|
+
def self.instance
|
11
|
+
@@instance ||= new
|
12
|
+
end
|
13
|
+
|
14
|
+
# Set logging on and off
|
15
|
+
#
|
16
|
+
# @param switch [bool] switch for on or off
|
13
17
|
def set_switch(switch)
|
14
18
|
@onoffswitch = switch
|
15
19
|
end
|
16
20
|
|
17
|
-
#
|
18
|
-
#
|
21
|
+
# Set message was logged from location
|
22
|
+
#
|
23
|
+
# @param name [string] location name
|
19
24
|
def set_location(name)
|
20
25
|
@location = name
|
21
26
|
end
|
22
27
|
|
23
|
-
#
|
24
|
-
#
|
28
|
+
# Open the logfile
|
29
|
+
#
|
30
|
+
# @param filename [string] name of the .log file
|
25
31
|
def open(filename = 'gunnylog')
|
26
32
|
@outfile = File.open(filename + '.log', 'a+')
|
27
33
|
@_is_file_open = true
|
28
34
|
end
|
29
35
|
|
30
|
-
#
|
36
|
+
# Close the logfile
|
31
37
|
def close
|
32
38
|
@outfile.close
|
33
39
|
@_is_file_open = false
|
34
40
|
end
|
35
41
|
|
36
|
-
#
|
37
|
-
#
|
38
|
-
# @param [string]
|
42
|
+
# Write message to file
|
43
|
+
#
|
44
|
+
# @param msg [string] message string
|
45
|
+
def msg(msg)
|
46
|
+
message(nil,msg)
|
47
|
+
end
|
48
|
+
|
49
|
+
# Write message to file
|
50
|
+
#
|
51
|
+
# @param loc [string] message location, optional
|
52
|
+
# @param msg [string] message string
|
39
53
|
def message(loc = nil, msg)
|
40
54
|
if @_is_file_open
|
41
55
|
write_msg(@outfile, loc, msg)
|
@@ -44,19 +58,21 @@ class GunnyLog
|
|
44
58
|
end
|
45
59
|
end
|
46
60
|
|
47
|
-
#
|
48
|
-
#
|
49
|
-
# @param [string]
|
50
|
-
# @param [
|
61
|
+
# Write formatted message with single arg or array of args
|
62
|
+
#
|
63
|
+
# @param loc [string] message location, optional
|
64
|
+
# @param msg [string] message format string
|
65
|
+
# @param args [arg or array of args]
|
51
66
|
def formatted_message(loc = nil, msg, args)
|
52
67
|
formatted = sprintf(msg, *args)
|
53
68
|
message(loc, formatted)
|
54
69
|
end
|
55
70
|
|
56
|
-
#
|
57
|
-
#
|
58
|
-
# @param [string]
|
59
|
-
# @param [
|
71
|
+
# Write formatted message with variable number of args
|
72
|
+
#
|
73
|
+
# @param loc [string] message location
|
74
|
+
# @param msg [string] message format string
|
75
|
+
# @param args [variable number of args]
|
60
76
|
def formatted_message_vars(loc, msg, *args)
|
61
77
|
formatted = sprintf(msg, *args)
|
62
78
|
message(loc, formatted)
|
@@ -64,33 +80,49 @@ class GunnyLog
|
|
64
80
|
|
65
81
|
private
|
66
82
|
|
83
|
+
include Singleton
|
84
|
+
|
67
85
|
# logging off and on flag
|
68
86
|
class << self;
|
69
87
|
attr_accessor :onoffswitch
|
70
88
|
end
|
71
|
-
@onoffswitch = true
|
72
89
|
|
73
90
|
# location message was logged from
|
74
91
|
class << self;
|
75
92
|
attr_accessor :location
|
76
93
|
end
|
77
|
-
@location = 'MainMethod'
|
78
94
|
|
79
95
|
# is file open flag
|
80
96
|
class << self;
|
81
97
|
attr_accessor :_is_file_open
|
82
98
|
end
|
83
|
-
@_is_file_open = false
|
84
99
|
|
100
|
+
# log file
|
101
|
+
class << self;
|
102
|
+
attr_accessor :outfile
|
103
|
+
end
|
104
|
+
|
105
|
+
# initailize
|
106
|
+
def initialize
|
107
|
+
@onoffswitch = true
|
108
|
+
@location = 'MainMethod'
|
109
|
+
@_is_file_open = false
|
110
|
+
@outfile = STDOUT
|
111
|
+
end
|
112
|
+
|
113
|
+
# write the msg
|
85
114
|
def write_msg(output, loc, msg)
|
86
115
|
if loc == nil
|
87
116
|
loc = @location
|
117
|
+
else
|
118
|
+
@location = loc
|
88
119
|
end
|
89
120
|
if @onoffswitch
|
90
|
-
output.puts "#{date_str}|#{loc}|#{msg}"
|
121
|
+
output.puts "#{date_str}|#{$0}|#{loc}|#{msg}"
|
91
122
|
end
|
92
123
|
end
|
93
124
|
|
125
|
+
# get the date time stamp
|
94
126
|
def date_str
|
95
127
|
d = DateTime.now
|
96
128
|
d.strftime('%m/%d/%Y|%I:%M:%S%p')
|
@@ -98,7 +130,7 @@ class GunnyLog
|
|
98
130
|
|
99
131
|
end
|
100
132
|
|
101
|
-
# GunnyLogFile from earlier versions
|
102
|
-
class GunnyLogFile < GunnyLog
|
103
133
|
|
134
|
+
# @deprecated Use {#GunnyLog} instead
|
135
|
+
class GunnyLogFile < GunnyLog
|
104
136
|
end
|