GunnyLog 1.0.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 +7 -0
- data/lib/GunnyExceptions.rb +2 -0
- data/lib/GunnyLog.rb +108 -0
- metadata +45 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: fe60c69bf1b1c76b5716ef6718dac69bc2e236ac
|
4
|
+
data.tar.gz: ee5d1e09a2cccf2277dfd5c15ebe11a719ca6fd5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: dc0dbf682e29d3b0b9557faa6859c42699a15c57ac09496b77cbdb8e96bed8e650a466fc1585c07fda37372fbf6f7ba8e940be01e26fec02507cb782865a7c86
|
7
|
+
data.tar.gz: 545ee8393c0a4795edca63049c355cf878fbec8f6c46c331dad249fd7683d2d6f18c16c0f2396e5d61f1b4e1d35189a41c9aa1101767def1dc1827d70e153977
|
data/lib/GunnyLog.rb
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
# GunnyLog logs messages to stdout
|
2
|
+
# GunnyLogFile logs messages to a file
|
3
|
+
require 'GunnyExceptions'
|
4
|
+
require 'singleton'
|
5
|
+
require 'date'
|
6
|
+
|
7
|
+
|
8
|
+
# GunnyLog logs messages to stdout
|
9
|
+
class GunnyLog
|
10
|
+
|
11
|
+
include Singleton
|
12
|
+
|
13
|
+
class << self;
|
14
|
+
attr_accessor :onoffswitch
|
15
|
+
end
|
16
|
+
@onoffswitch = true
|
17
|
+
|
18
|
+
class << self;
|
19
|
+
attr_accessor :location
|
20
|
+
end
|
21
|
+
@location = 'MainMethod'
|
22
|
+
|
23
|
+
|
24
|
+
# @param [bool] switch - logging on and off
|
25
|
+
def set_switch(switch)
|
26
|
+
@onoffswitch = switch
|
27
|
+
end
|
28
|
+
|
29
|
+
# @param [string] name - set message location
|
30
|
+
def set_location(name)
|
31
|
+
@location = name
|
32
|
+
end
|
33
|
+
|
34
|
+
# write message
|
35
|
+
# @param [string] loc - message location, optional
|
36
|
+
# @param [string] msg - message string
|
37
|
+
def message(loc = nil, msg)
|
38
|
+
write_msg(STDOUT, loc, msg)
|
39
|
+
end
|
40
|
+
|
41
|
+
# write formatted message - single arg or array of args
|
42
|
+
# @param [string] loc - message location, optional
|
43
|
+
# @param [string] msg - message format string
|
44
|
+
# @param [arg or array of args]
|
45
|
+
def formatted_message(loc = nil, msg, args)
|
46
|
+
formatted = sprintf(msg, *args)
|
47
|
+
message(loc, formatted)
|
48
|
+
end
|
49
|
+
|
50
|
+
# write formatted message - variable number of args
|
51
|
+
# @param [string] loc - message location
|
52
|
+
# @param [string] msg - message format string
|
53
|
+
# @param [variable number of args]
|
54
|
+
def formatted_message_vars(loc, msg, *args)
|
55
|
+
formatted = sprintf(msg, *args)
|
56
|
+
message(loc, formatted)
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
def write_msg(output, loc, msg)
|
62
|
+
if loc == nil
|
63
|
+
loc = @location
|
64
|
+
end
|
65
|
+
if @onoffswitch
|
66
|
+
output.puts "#{date_str}|#{loc}|#{msg}"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def date_str
|
71
|
+
d = DateTime.now
|
72
|
+
d.strftime('%m/%d/%Y|%I:%M:%S%p')
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
|
78
|
+
# GunnyLogFile logs messages to a file
|
79
|
+
class GunnyLogFile < GunnyLog
|
80
|
+
|
81
|
+
class << self;
|
82
|
+
attr_accessor :_is_file_open
|
83
|
+
end
|
84
|
+
@_is_file_open = false
|
85
|
+
|
86
|
+
# open the logfile
|
87
|
+
# @param [string] filename
|
88
|
+
def open(filename = 'gunnylog')
|
89
|
+
@outfile = File.open(filename + '.log', 'a+')
|
90
|
+
@_is_file_open = true
|
91
|
+
end
|
92
|
+
|
93
|
+
# close the logfile
|
94
|
+
def close
|
95
|
+
@outfile.close
|
96
|
+
@_is_file_open = false
|
97
|
+
end
|
98
|
+
|
99
|
+
# write message to file
|
100
|
+
# @param [string] loc - message location, optional
|
101
|
+
# @param [string] msg - message string
|
102
|
+
def message(loc = nil, msg)
|
103
|
+
if @_is_file_open
|
104
|
+
write_msg(@outfile, loc, msg)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
end
|
metadata
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: GunnyLog
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- GunnyHwy
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-08-01 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Ruby class for logging to screen or file
|
14
|
+
email: gunnyhwy21@yahoo.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/GunnyLog.rb
|
20
|
+
- lib/GunnyExceptions.rb
|
21
|
+
homepage: http://rubygems.org/gems/GunnyLog
|
22
|
+
licenses:
|
23
|
+
- GPL v3
|
24
|
+
metadata: {}
|
25
|
+
post_install_message:
|
26
|
+
rdoc_options: []
|
27
|
+
require_paths:
|
28
|
+
- lib
|
29
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - '>='
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
requirements: []
|
40
|
+
rubyforge_project:
|
41
|
+
rubygems_version: 2.0.14
|
42
|
+
signing_key:
|
43
|
+
specification_version: 4
|
44
|
+
summary: Ruby log file class
|
45
|
+
test_files: []
|