GunnyLog 1.0.5 → 1.0.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c19d520898a9cc4b37e37c9c6c3a8c57d3922fff
4
- data.tar.gz: d05934002edcccf016fb72ab2ee2212b49cfbb60
3
+ metadata.gz: bd5c1a4adf9af717629295c61470f1cb8a909072
4
+ data.tar.gz: 658e172fed90c916974fea334520aef8589302ff
5
5
  SHA512:
6
- metadata.gz: 96c08e7dccb7201844d823004701d7508d6379eb3d15e72b1c46dab17f59b9715cea40b1788afd24fddfbb03c0c144be218517c3891ec6b86fab70dc41e4e1ba
7
- data.tar.gz: 5ca8db77684d938a216cddcc6f378233835b540af60c5a0e8c2ea37386e578e05d1d5d368c322e8d1127c9560c07850ec5a694649439c79ac0d8504bd8c9b1ab
6
+ metadata.gz: a95adeaf8531c11de8be07c07b122aaa0e927177fc861b2eaefc93da35c961eff4b29bcec5176119e713f44745ab40682483f6b6613c7d439687a1b14fd3205b
7
+ data.tar.gz: e3c6e6d67ad6ce3a912042f38e090b64667abb73c92aec5e67ac3387b80863a8bb7954532677c20395cd546d9df347e6687a01f59943ba52063b78d58024da5f
@@ -0,0 +1,3 @@
1
+ class GunnyLogException < Exception
2
+
3
+ end
@@ -0,0 +1,4 @@
1
+ class GunnyLog
2
+ VERSION = "1.0.6"
3
+ DESC_VERSION = 'GunnyLog Version: ' + GunnyLog::VERSION
4
+ end
data/lib/GunnyLog.rb CHANGED
@@ -1,9 +1,11 @@
1
1
  # GunnyLog class
2
+ require 'GunnyLog/version'
3
+ require 'GunnyLog/exceptions'
2
4
  require 'singleton'
3
5
  require 'date'
4
6
 
5
7
 
6
- # GunnyLog logs messages to stdout or a file
8
+ # GunnyLog logs messages to stdout(default), stderr, or a file
7
9
  class GunnyLog
8
10
 
9
11
  # Singleton instance method
@@ -12,54 +14,110 @@ class GunnyLog
12
14
  #end
13
15
 
14
16
  # Set logging on and off
15
- #
16
- # @param switch [bool] switch for on or off
17
- def set_switch(switch)
18
- @onoffswitch = switch
17
+ # @param flag [bool] switch for on or off
18
+ def set_logging_enabled(flag)
19
+ @onoffswitch = flag
20
+ end
21
+
22
+ # Set logging on and off
23
+ # @deprecated Use {#set_logging_enabled} instead
24
+ # @param flag [bool] switch for on or off
25
+ def set_switch(flag)
26
+ @onoffswitch = flag
19
27
  end
20
28
 
21
29
  # Set message was logged from location
22
- #
23
- # @param name [string] location name
24
- def set_location(name)
25
- @location = name
30
+ # @param loc [string] location name
31
+ def set_message_location(loc)
32
+ @location = loc
33
+ end
34
+
35
+ # Set message was logged from location
36
+ # @deprecated Use {#set_message_location} instead
37
+ # @param loc [string] location name
38
+ def set_location(loc)
39
+ @location = loc
40
+ end
41
+
42
+ # Set output to STDOUT, default
43
+ def set_output_stdout
44
+ if @_is_file_open
45
+ self.close
46
+ end
47
+ @outfile = STDOUT
48
+ end
49
+
50
+ # Set output to STDERR
51
+ def set_output_stderr
52
+ if @_is_file_open
53
+ self.close
54
+ end
55
+ @outfile = STDERR
26
56
  end
27
57
 
28
58
  # Open the logfile
29
- #
30
- # @param filename [string] name of the .log file
31
- def open(filename = 'gunnylog')
32
- @outfile = File.open(filename + '.log', 'a+')
33
- @_is_file_open = true
59
+ # @param filename [string] name of the logfile
60
+ def open(filename = 'gunnylog.log')
61
+ begin
62
+ @outfile = File.open(filename, 'a+')
63
+ @_is_file_open = true
64
+ rescue SystemCallError
65
+ raise GunnyLogException.new('Error opening file: ' + filename)
66
+ end
67
+ end
68
+
69
+ # Open the logfile with path, name, and extention
70
+ # @param pathname [string] path of the logfile
71
+ # @param filename [string] name of the logfile
72
+ # @param extention [string] extension of the logfile
73
+ def open_with_info(pathname = nil,
74
+ filename = 'gunnylog',
75
+ extension = 'log')
76
+
77
+ #if pathname == nil
78
+ # puts 'pathname = nil'
79
+ #else
80
+ # puts 'pathname = ' + pathname
81
+ #end
82
+ #puts 'filename = ' + filename
83
+ #puts 'extension = ' + extension
84
+
85
+ if pathname == nil
86
+ self.open(filename + '.' + extension)
87
+ else
88
+ self.open(pathname + '/' + filename + '.' + extension)
89
+ end
34
90
  end
35
91
 
36
92
  # Close the logfile
37
93
  def close
38
- @outfile.close
39
- @_is_file_open = false
94
+ begin
95
+ @outfile.close
96
+ @_is_file_open = false
97
+ @outfile = STDOUT
98
+ rescue SystemCallError
99
+ raise GunnyLogException.new('Error closing file')
100
+ end
40
101
  end
41
102
 
42
103
  # Write message to file
43
- #
44
104
  # @param msg [string] message string
45
105
  def msg(msg)
46
- message(nil,msg)
106
+ message(nil, msg)
47
107
  end
48
108
 
49
109
  # Write message to file
50
- #
51
110
  # @param loc [string] message location, optional
52
111
  # @param msg [string] message string
53
112
  def message(loc = nil, msg)
54
- if @_is_file_open
113
+ #if @_is_file_open
55
114
  write_msg(@outfile, loc, msg)
56
- else
57
- write_msg(STDOUT, loc, msg)
58
- end
115
+ #else
116
+ # write_msg(STDOUT, loc, msg)
117
+ #end
59
118
  end
60
119
 
61
120
  # Write formatted message with single arg or array of args
62
- #
63
121
  # @param loc [string] message location, optional
64
122
  # @param msg [string] message format string
65
123
  # @param args [arg or array of args]
@@ -69,7 +127,6 @@ class GunnyLog
69
127
  end
70
128
 
71
129
  # Write formatted message with variable number of args
72
- #
73
130
  # @param loc [string] message location
74
131
  # @param msg [string] message format string
75
132
  # @param args [variable number of args]
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: GunnyLog
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
4
+ version: 1.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - GunnyHwy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-09 00:00:00.000000000 Z
11
+ date: 2014-09-10 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Ruby class for logging to screen or file
14
14
  email: gunnyhwy21@yahoo.com
@@ -17,6 +17,8 @@ extensions: []
17
17
  extra_rdoc_files: []
18
18
  files:
19
19
  - lib/GunnyLog.rb
20
+ - lib/GunnyLog/version.rb
21
+ - lib/GunnyLog/exceptions.rb
20
22
  homepage: http://rubygems.org/gems/GunnyLog
21
23
  licenses:
22
24
  - GPL v3