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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 05cd8b9fc53224e8eff70695f4b8ce927fb083c6
4
- data.tar.gz: 05ea1e1f03477f539e67326946c416a1a9dc02c2
3
+ metadata.gz: c78d8e30e4408513a454acbafb2aa647138bb28a
4
+ data.tar.gz: a720d8c42078a1493bcd091684d34eaead0a5d8c
5
5
  SHA512:
6
- metadata.gz: ca765cd96a2ccafecda1674c3d49dcebd433f399717c1a644340a34d457f6a745c4c39e829977f97b8c1ea0d955603a01e3009a40912db3069e8932c54cc73e1
7
- data.tar.gz: bf2c36de80a4c6bed32a9a8b77006ea09680567bfdd9e42c53120b76f466299b3e6bedd96fb632d044ee301986f22bca7db8c42174a8a2994239b4d888b8855b
6
+ metadata.gz: 331e442c7aca0b443b0afedb0f2603b9e329fe6a05c43fdfb4b5d1329a88f32e59ac1fd191b2851ec40cf6dfeb254c6a71a0b9c67980277340efb06d5424a43b
7
+ data.tar.gz: a2a092535cfa53db7d4796b8181f750fdb15bf5ad85cbf46883f54108a12045883ba1f95b55c6a9ee254cf6836456ac0f33a13ccaedd7bcb19d1d3c5f1b57d53
@@ -1,6 +1,8 @@
1
1
  require_relative '../lib/simple_cloud_logging'
2
2
 
3
- logger = BlackStack::LocalLogger.new('./example01.log')
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')
@@ -1,6 +1,8 @@
1
1
  require_relative '../lib/simple_cloud_logging'
2
2
 
3
- logger = BlackStack::LocalLogger.new('./example02.log')
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]
@@ -1,6 +1,8 @@
1
1
  require_relative '../lib/simple_cloud_logging'
2
2
 
3
- logger = BlackStack::LocalLogger.new('./example03.log')
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]]
@@ -1,27 +1,40 @@
1
1
  require_relative '../lib/simple_cloud_logging'
2
2
 
3
- logger = BlackStack::RemoteLogger.new(
4
- './example04.log',
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
- logger.logs("Check if n>5... ")
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
- raise "This is an abstract method."
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
- raise "This is an abstract method."
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
- ltime = Time.now.strftime("%Y%m%d%H%M%S").to_s
6
- ltext = ltime + ":" + s + "\r\n"
5
+ ltext = super(s)
7
6
  File.open(self.filename, 'a') { |file| file.write(ltext) }
8
- print ltext
7
+ ltext
9
8
  end
10
9
 
11
10
  #
12
11
  def logs(s)
13
- self.nest_level += 1
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
- if self.number_of_lines_in_current_level > 0
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
- nTries = 0
15
- bSuccess = false
16
- parsed = nil
17
- sError = ""
18
- while (nTries < 5 && bSuccess == false)
19
- begin
20
- nTries = nTries + 1
21
- uri = URI("#{self.api_url}:#{self.api_port}/log.json")
22
- res = CallPOST(uri,
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
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_cloud_logging
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.3
4
+ version: 1.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Leandro Daniel Sardi