GunnyLog 1.0.2 → 1.0.3

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/GunnyLog.rb +40 -46
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9d78492939a8c7c6f91db7d2c08812464637bafa
4
- data.tar.gz: 2ab0049b6a262bb5a261da6f7f8529671dac7f1b
3
+ metadata.gz: 8d8ed19e0851ad8bef2a9bd8c12d3a97b1cd2a5f
4
+ data.tar.gz: 55a0da85b35c10fd823f439394ce18f403396fcf
5
5
  SHA512:
6
- metadata.gz: 7e8bd6bbe3560c687b65a5c3e2fd09d5c2c130a52f29db43ed2e70d7c5546b1f7c2853422fd16e53ef31ae5172ddaa74968ebd7297a16b864d54cb2b441e8904
7
- data.tar.gz: 4fb2adbfac7a78993fd58a4a5cf3dc9519d733c8606191a5dc7e43f8382466891d430214bb17b5c8584e22dbf649078d0923cbad95dab44740c1fd194bfd2fb9
6
+ metadata.gz: bab38a928d3e7139bc8b513b271889d2144b2f71de40bfce02c28eb5c290c7236989dcd98b40c20c6e176b9750d88f92224837538f7f25a504000180df5b35be
7
+ data.tar.gz: a5e7e859cea8cf82ad97eaac58a602adb7ae70455142ab739994b6ad4f6c8f181e620a49602955c6479ce1840c2dbc97c8c2a0bc0a6bda5f32b7517e28223c40
data/lib/GunnyLog.rb CHANGED
@@ -1,25 +1,13 @@
1
- # GunnyLog and GunnyLogFile classes
1
+ # GunnyLog class
2
2
  require 'singleton'
3
3
  require 'date'
4
4
 
5
5
 
6
- # GunnyLog logs messages to stdout
6
+ # GunnyLog logs messages to stdout or a file
7
7
  class GunnyLog
8
8
 
9
9
  include Singleton
10
10
 
11
- # logging off and on flag
12
- class << self;
13
- attr_accessor :onoffswitch
14
- end
15
- @onoffswitch = true
16
-
17
- # location message was logged from
18
- class << self;
19
- attr_accessor :location
20
- end
21
- @location = 'MainMethod'
22
-
23
11
  # set logging on and off
24
12
  # @param [bool] switch
25
13
  def set_switch(switch)
@@ -32,11 +20,28 @@ class GunnyLog
32
20
  @location = name
33
21
  end
34
22
 
35
- # write message
23
+ # open the logfile
24
+ # @param [string] filename
25
+ def open(filename = 'gunnylog')
26
+ @outfile = File.open(filename + '.log', 'a+')
27
+ @_is_file_open = true
28
+ end
29
+
30
+ # close the logfile
31
+ def close
32
+ @outfile.close
33
+ @_is_file_open = false
34
+ end
35
+
36
+ # write message to file
36
37
  # @param [string] loc - message location, optional
37
38
  # @param [string] msg - message string
38
39
  def message(loc = nil, msg)
40
+ if @_is_file_open
41
+ write_msg(@outfile, loc, msg)
42
+ else
39
43
  write_msg(STDOUT, loc, msg)
44
+ end
40
45
  end
41
46
 
42
47
  # write formatted message - single arg or array of args
@@ -59,6 +64,24 @@ class GunnyLog
59
64
 
60
65
  private
61
66
 
67
+ # logging off and on flag
68
+ class << self;
69
+ attr_accessor :onoffswitch
70
+ end
71
+ @onoffswitch = true
72
+
73
+ # location message was logged from
74
+ class << self;
75
+ attr_accessor :location
76
+ end
77
+ @location = 'MainMethod'
78
+
79
+ # is file open flag
80
+ class << self;
81
+ attr_accessor :_is_file_open
82
+ end
83
+ @_is_file_open = false
84
+
62
85
  def write_msg(output, loc, msg)
63
86
  if loc == nil
64
87
  loc = @location
@@ -73,38 +96,9 @@ class GunnyLog
73
96
  d.strftime('%m/%d/%Y|%I:%M:%S%p')
74
97
  end
75
98
 
76
- end
99
+ end
77
100
 
78
-
79
- # GunnyLogFile logs messages to a file
101
+ # GunnyLogFile from earlier versions
80
102
  class GunnyLogFile < GunnyLog
81
103
 
82
- # is file open flag
83
- class << self;
84
- attr_accessor :_is_file_open
85
- end
86
- @_is_file_open = false
87
-
88
- # open the logfile
89
- # @param [string] filename
90
- def open(filename = 'gunnylog')
91
- @outfile = File.open(filename + '.log', 'a+')
92
- @_is_file_open = true
93
- end
94
-
95
- # close the logfile
96
- def close
97
- @outfile.close
98
- @_is_file_open = false
99
- end
100
-
101
- # write message to file
102
- # @param [string] loc - message location, optional
103
- # @param [string] msg - message string
104
- def message(loc = nil, msg)
105
- if @_is_file_open
106
- write_msg(@outfile, loc, msg)
107
- end
108
- end
109
-
110
104
  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.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - GunnyHwy