simple_cloud_logging 1.1.3 → 1.1.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/examples/example01.rb +6 -1
- data/examples/example02.rb +3 -1
- data/examples/example03.rb +3 -1
- data/examples/example04.rb +20 -7
- data/lib/baselogger.rb +58 -2
- data/lib/locallogger.rb +12 -47
- data/lib/remotelogger.rb +35 -28
- data/lib/simple_cloud_logging.rb +48 -1
- 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: c78d8e30e4408513a454acbafb2aa647138bb28a
|
4
|
+
data.tar.gz: a720d8c42078a1493bcd091684d34eaead0a5d8c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 331e442c7aca0b443b0afedb0f2603b9e329fe6a05c43fdfb4b5d1329a88f32e59ac1fd191b2851ec40cf6dfeb254c6a71a0b9c67980277340efb06d5424a43b
|
7
|
+
data.tar.gz: a2a092535cfa53db7d4796b8181f750fdb15bf5ad85cbf46883f54108a12045883ba1f95b55c6a9ee254cf6836456ac0f33a13ccaedd7bcb19d1d3c5f1b57d53
|
data/examples/example01.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
require_relative '../lib/simple_cloud_logging'
|
2
2
|
|
3
|
-
|
3
|
+
# Testing a simple local log.
|
4
|
+
|
5
|
+
logger = BlackStack::LocalLoggerFactory.create('./example01.log')
|
4
6
|
|
5
7
|
logger.logs("Declare variable... ")
|
6
8
|
@n = 5
|
@@ -12,3 +14,6 @@ if @n>5
|
|
12
14
|
else
|
13
15
|
logger.no
|
14
16
|
end
|
17
|
+
|
18
|
+
#BlackStack::LocalLoggerFactory.save('./example01.log', logger)
|
19
|
+
#BlackStack::LocalLoggerFactory.release('./example01.log')
|
data/examples/example02.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
require_relative '../lib/simple_cloud_logging'
|
2
2
|
|
3
|
-
|
3
|
+
# Testing a local log, with 1-level nesting.
|
4
|
+
|
5
|
+
logger = BlackStack::LocalLoggerFactory.create('./example02.log')
|
4
6
|
|
5
7
|
logger.logs("Declare array of numbers... ")
|
6
8
|
@a = [1,2,3,4,5,6,7,8,9,10]
|
data/examples/example03.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
require_relative '../lib/simple_cloud_logging'
|
2
2
|
|
3
|
-
|
3
|
+
# Testing a local log, with 2-levels of nesting.
|
4
|
+
|
5
|
+
logger = BlackStack::LocalLoggerFactory.create('./example03.log')
|
4
6
|
|
5
7
|
logger.logs("Declare array of array of numbers... ")
|
6
8
|
@a = [[1,2,3],[4,5,6],[7,8,9,10]]
|
data/examples/example04.rb
CHANGED
@@ -1,27 +1,40 @@
|
|
1
1
|
require_relative '../lib/simple_cloud_logging'
|
2
2
|
|
3
|
-
logger
|
4
|
-
|
5
|
-
'https://127.0.0.1',
|
6
|
-
443,
|
7
|
-
'E20CBAE0-A4D4-4161-8812-6D9FE67A2E47'
|
8
|
-
)
|
3
|
+
# Testing the LocalLoggerFactory, getting the logger object before each log action.
|
4
|
+
# The log should keep congruent, like it happens in example03.rb
|
9
5
|
|
6
|
+
logger = BlackStack::LocalLoggerFactory.create('./example04.log')
|
10
7
|
logger.logs("Declare array of array of numbers... ")
|
11
8
|
@a = [[1,2,3],[4,5,6],[7,8,9,10]]
|
9
|
+
BlackStack::LocalLoggerFactory.save('./example04.log', logger)
|
10
|
+
logger = BlackStack::LocalLoggerFactory.create('./example04.log')
|
12
11
|
logger.done
|
13
12
|
|
13
|
+
BlackStack::LocalLoggerFactory.save('./example04.log', logger)
|
14
|
+
logger = BlackStack::LocalLoggerFactory.create('./example04.log')
|
14
15
|
logger.logs("Process array of array elements... ")
|
15
16
|
@a.each { |b|
|
17
|
+
BlackStack::LocalLoggerFactory.save('./example04.log', logger)
|
18
|
+
logger = BlackStack::LocalLoggerFactory.create('./example04.log')
|
16
19
|
logger.logs("Process array of numbers... ")
|
17
20
|
b.each { |n|
|
18
|
-
|
21
|
+
BlackStack::LocalLoggerFactory.save('./example04.log', logger)
|
22
|
+
logger = BlackStack::LocalLoggerFactory.create('./example04.log')
|
23
|
+
logger.logs("Check if #{n.to_s}>5... ")
|
19
24
|
if n>5
|
25
|
+
BlackStack::LocalLoggerFactory.save('./example04.log', logger)
|
26
|
+
logger = BlackStack::LocalLoggerFactory.create('./example04.log')
|
20
27
|
logger.yes
|
21
28
|
else
|
29
|
+
BlackStack::LocalLoggerFactory.save('./example04.log', logger)
|
30
|
+
logger = BlackStack::LocalLoggerFactory.create('./example04.log')
|
22
31
|
logger.no
|
23
32
|
end
|
24
33
|
}
|
34
|
+
BlackStack::LocalLoggerFactory.save('./example04.log', logger)
|
35
|
+
logger = BlackStack::LocalLoggerFactory.create('./example04.log')
|
25
36
|
logger.done
|
26
37
|
}
|
38
|
+
BlackStack::LocalLoggerFactory.save('./example04.log', logger)
|
39
|
+
logger = BlackStack::LocalLoggerFactory.create('./example04.log')
|
27
40
|
logger.done
|
data/lib/baselogger.rb
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
module BlackStack
|
2
2
|
class BaseLogger
|
3
|
+
METHOD_LOG = 'log'
|
4
|
+
METHOD_LOGS = 'logs'
|
5
|
+
METHOD_LOGF = 'logf'
|
6
|
+
METHODS = [METHOD_LOG, METHOD_LOGS, METHOD_LOGF]
|
7
|
+
|
3
8
|
attr_accessor :filename, :nest_level, :number_of_lines_in_current_level, :current_nest_level
|
4
9
|
|
5
10
|
def initialize(the_filename)
|
@@ -14,14 +19,65 @@ module BlackStack
|
|
14
19
|
end
|
15
20
|
|
16
21
|
def log(s)
|
17
|
-
|
22
|
+
ltime = Time.now.strftime("%Y%m%d%H%M%S").to_s
|
23
|
+
ltext = ltime + ":" + s + "\r\n"
|
24
|
+
print ltext
|
25
|
+
ltext
|
18
26
|
end
|
19
27
|
|
20
28
|
def logs(s)
|
21
|
-
|
29
|
+
ltext = ""
|
30
|
+
self.nest_level += 1
|
31
|
+
self.number_of_lines_in_current_level = 0
|
32
|
+
|
33
|
+
if self.current_nest_level != self.nest_level
|
34
|
+
ltext += "\n"
|
35
|
+
end
|
36
|
+
|
37
|
+
i=1
|
38
|
+
while (i<self.nest_level)
|
39
|
+
ltext += " > "
|
40
|
+
i+=1
|
41
|
+
end
|
42
|
+
|
43
|
+
if self.nest_level==1
|
44
|
+
ltime = Time.now.strftime("%Y%m%d%H%M%S").to_s
|
45
|
+
ltext += ltime + ":" + s
|
46
|
+
else
|
47
|
+
ltext += s
|
48
|
+
end
|
49
|
+
|
50
|
+
#File.open(self.filename, 'a') { |file| file.write(ltext) }
|
51
|
+
print ltext
|
52
|
+
|
53
|
+
#
|
54
|
+
self.current_nest_level = self.nest_level
|
55
|
+
|
56
|
+
#
|
57
|
+
ltext
|
22
58
|
end
|
23
59
|
|
24
60
|
def logf(s)
|
61
|
+
ltext = ""
|
62
|
+
if self.number_of_lines_in_current_level > 0
|
63
|
+
i=1
|
64
|
+
while (i<self.nest_level)
|
65
|
+
ltext += " > "
|
66
|
+
i+=1
|
67
|
+
end
|
68
|
+
end # if self.number_of_lines_in_current_level == 0
|
69
|
+
|
70
|
+
self.nest_level -= 1
|
71
|
+
self.number_of_lines_in_current_level += 1
|
72
|
+
|
73
|
+
ltext += s + "\n"
|
74
|
+
|
75
|
+
print ltext
|
76
|
+
|
77
|
+
ltext
|
78
|
+
end
|
79
|
+
|
80
|
+
def release()
|
25
81
|
raise "This is an abstract method."
|
26
82
|
end
|
27
83
|
|
data/lib/locallogger.rb
CHANGED
@@ -2,64 +2,29 @@ module BlackStack
|
|
2
2
|
require_relative './baselogger'
|
3
3
|
class LocalLogger < BlackStack::BaseLogger
|
4
4
|
def log(s)
|
5
|
-
|
6
|
-
ltext = ltime + ":" + s + "\r\n"
|
5
|
+
ltext = super(s)
|
7
6
|
File.open(self.filename, 'a') { |file| file.write(ltext) }
|
8
|
-
|
7
|
+
ltext
|
9
8
|
end
|
10
9
|
|
11
10
|
#
|
12
11
|
def logs(s)
|
13
|
-
|
14
|
-
self.number_of_lines_in_current_level = 0
|
15
|
-
|
16
|
-
if self.current_nest_level != self.nest_level
|
17
|
-
ltext = "\r\n"
|
18
|
-
print ltext
|
19
|
-
File.open(self.filename, 'a') { |file| file.write(ltext) }
|
20
|
-
end
|
21
|
-
|
22
|
-
i=1
|
23
|
-
while (i<self.nest_level)
|
24
|
-
ltext = " > "
|
25
|
-
print ltext
|
26
|
-
File.open(self.filename, 'a') { |file| file.write(ltext) }
|
27
|
-
i+=1
|
28
|
-
end
|
29
|
-
|
30
|
-
ltext = s
|
31
|
-
if self.nest_level==1
|
32
|
-
ltime = Time.now.strftime("%Y%m%d%H%M%S").to_s
|
33
|
-
ltext = ltime + ":" + s
|
34
|
-
end
|
35
|
-
|
36
|
-
#File.open(self.filename, 'a') { |file| file.write(ltext) }
|
37
|
-
print ltext
|
12
|
+
ltext = super(s)
|
38
13
|
File.open(self.filename, 'a') { |file| file.write(ltext) }
|
39
|
-
|
40
|
-
#
|
41
|
-
self.current_nest_level = self.nest_level
|
14
|
+
ltext
|
42
15
|
end # def logs
|
43
16
|
|
44
17
|
#
|
45
18
|
def logf(s)
|
46
|
-
|
47
|
-
i=1
|
48
|
-
while (i<self.nest_level)
|
49
|
-
ltext = " > "
|
50
|
-
print ltext
|
51
|
-
File.open(self.filename, 'a') { |file| file.write(ltext) }
|
52
|
-
i+=1
|
53
|
-
end
|
54
|
-
end # if self.number_of_lines_in_current_level == 0
|
55
|
-
|
56
|
-
self.nest_level -= 1
|
57
|
-
self.number_of_lines_in_current_level += 1
|
58
|
-
|
59
|
-
ltext = s + "\r\n"
|
60
|
-
print ltext
|
19
|
+
ltext = super(s)
|
61
20
|
File.open(self.filename, 'a') { |file| file.write(ltext) }
|
21
|
+
ltext
|
62
22
|
end # def logf
|
63
|
-
|
23
|
+
|
24
|
+
#
|
25
|
+
def release()
|
26
|
+
BlackStack::LocalLoggerFactory.release(self.filename)
|
27
|
+
end
|
28
|
+
|
64
29
|
end # class LocalLogger
|
65
30
|
end # module BlackStack
|
data/lib/remotelogger.rb
CHANGED
@@ -11,40 +11,47 @@ module BlackStack
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def log(s)
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
{'uid' => normalizeGuid(uid),}
|
24
|
-
)
|
25
|
-
parsed = JSON.parse(res.body)
|
26
|
-
if (parsed['status']=='success')
|
27
|
-
bSuccess = true
|
28
|
-
else
|
29
|
-
sError = parsed['status']
|
30
|
-
end
|
31
|
-
rescue Errno::ECONNREFUSED => e
|
32
|
-
sError = "Errno::ECONNREFUSED:" + e.to_s
|
33
|
-
rescue => e2
|
34
|
-
sError = "Exception" + e2.to_s
|
35
|
-
end
|
36
|
-
end # while
|
37
|
-
|
38
|
-
if (bSuccess==false)
|
39
|
-
raise "#{sError}"
|
40
|
-
end
|
14
|
+
ltext = super(s)
|
15
|
+
url = "#{self.api_url}:#{self.api_port}/api1.4/scl/log.json"
|
16
|
+
res = BlackStack::Netting::api_call(url, {
|
17
|
+
'api_key' => self.api_key,
|
18
|
+
'filename' => self.filename,
|
19
|
+
'text' => s,
|
20
|
+
'method' => BlackStack::BaseLogger::METHOD_LOG,
|
21
|
+
})
|
22
|
+
ltext
|
41
23
|
end
|
42
24
|
|
43
25
|
def logs(s)
|
26
|
+
ltext = super(s)
|
27
|
+
url = "#{self.api_url}:#{self.api_port}/api1.4/scl/log.json"
|
28
|
+
res = BlackStack::Netting::api_call(url, {
|
29
|
+
'api_key' => self.api_key,
|
30
|
+
'filename' => self.filename,
|
31
|
+
'text' => s,
|
32
|
+
'method' => BlackStack::BaseLogger::METHOD_LOGS,
|
33
|
+
})
|
34
|
+
ltext
|
44
35
|
end
|
45
36
|
|
46
37
|
def logf(s)
|
38
|
+
ltext = super(s)
|
39
|
+
url = "#{self.api_url}:#{self.api_port}/api1.4/scl/log.json"
|
40
|
+
res = BlackStack::Netting::api_call(url, {
|
41
|
+
'api_key' => self.api_key,
|
42
|
+
'filename' => self.filename,
|
43
|
+
'text' => s,
|
44
|
+
'method' => BlackStack::BaseLogger::METHOD_LOGF,
|
45
|
+
})
|
46
|
+
ltext
|
47
|
+
end
|
48
|
+
|
49
|
+
def release()
|
50
|
+
url = "#{self.api_url}:#{self.api_port}/api1.4/scl/release.json"
|
51
|
+
res = BlackStack::Netting::api_call(url, {
|
52
|
+
'api_key' => self.api_key,
|
53
|
+
'filename' => self.filename,
|
54
|
+
})
|
47
55
|
end
|
48
|
-
|
49
56
|
end
|
50
57
|
end # module BlackStack
|
data/lib/simple_cloud_logging.rb
CHANGED
@@ -1,3 +1,50 @@
|
|
1
1
|
require 'blackstack_commons'
|
2
2
|
require_relative './locallogger'
|
3
|
-
require_relative './remotelogger'
|
3
|
+
require_relative './remotelogger'
|
4
|
+
|
5
|
+
module BlackStack
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
class LocalLoggerFactory
|
10
|
+
def self.lock()
|
11
|
+
@@fd.flock(File::LOCK_EX)
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.release()
|
15
|
+
@@fd.flock(File::LOCK_UN)
|
16
|
+
end
|
17
|
+
|
18
|
+
#
|
19
|
+
def self.create(filename)
|
20
|
+
data_filename = "#{filename}.data"
|
21
|
+
ret = BlackStack::LocalLogger.new(filename)
|
22
|
+
if File.exist?(data_filename)
|
23
|
+
f = File.open(data_filename,"r")
|
24
|
+
data = f.read.split(/,/)
|
25
|
+
ret.nest_level = data[0].to_i
|
26
|
+
ret.number_of_lines_in_current_level = data[1].to_i
|
27
|
+
ret.current_nest_level = data[2].to_i
|
28
|
+
f.close
|
29
|
+
end
|
30
|
+
ret
|
31
|
+
end
|
32
|
+
|
33
|
+
#
|
34
|
+
def self.save(filename, locallogger)
|
35
|
+
data_filename = "#{filename}.data"
|
36
|
+
ret = BlackStack::LocalLogger.new(filename)
|
37
|
+
f = File.open(data_filename,"w")
|
38
|
+
f.write "#{locallogger.nest_level.to_s},#{locallogger.number_of_lines_in_current_level.to_s},#{locallogger.current_nest_level.to_s}"
|
39
|
+
f.close
|
40
|
+
end
|
41
|
+
|
42
|
+
#
|
43
|
+
def self.release(filename)
|
44
|
+
data_filename = "#{filename}.data"
|
45
|
+
File.delete(data_filename) if File.exist?(data_filename)
|
46
|
+
end
|
47
|
+
|
48
|
+
end # class LocalLoggerFactory
|
49
|
+
|
50
|
+
end # module BlackStack
|