log 0.0.10 → 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.
- data/lib/log.rb +144 -105
- data/lib/log/version.rb +2 -4
- metadata +28 -10
- data/lib/log/log_consumer.rb +0 -102
- data/test/log/log_test.rb +0 -165
data/lib/log.rb
CHANGED
|
@@ -1,130 +1,169 @@
|
|
|
1
1
|
# Author: Yaron Dror (yaron.dror.bb@gmail.com)
|
|
2
2
|
# Description: The file contains the code which implements the 'Log' module
|
|
3
|
-
# Run: Add to 'require' list.
|
|
4
|
-
|
|
5
|
-
#
|
|
6
|
-
|
|
3
|
+
# Run: Add to 'require' list. Execute Log.init
|
|
4
|
+
|
|
5
|
+
#require 'email'
|
|
6
|
+
require 'log4r'
|
|
7
|
+
require 'log4r/outputter/emailoutputter'
|
|
7
8
|
|
|
8
9
|
require 'params'
|
|
9
|
-
require 'thread'
|
|
10
|
-
require 'log/log_consumer.rb'
|
|
11
|
-
|
|
12
|
-
module BBFS
|
|
13
|
-
# Module: Log.
|
|
14
|
-
# Abstruct: The Log is used to log info\warning\error\debug messages
|
|
15
|
-
# Note: The logger will be automatically initialized if log_param_auto_start is true
|
|
16
|
-
# If log_param_auto_start is false then 'Log.init' method will be called
|
|
17
|
-
# on the first attempt to log.
|
|
18
|
-
module Log
|
|
19
|
-
#Auxiliary method to retrieve the executable name
|
|
20
|
-
def Log.executable_name
|
|
21
|
-
/([a-zA-Z0-9\-_\.]+):\d+/ =~ caller[caller.size-1]
|
|
22
|
-
return $1
|
|
23
|
-
end
|
|
24
10
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
11
|
+
# Module: Log.
|
|
12
|
+
# Abstruct: The Log is used to log info\warning\error\debug messages
|
|
13
|
+
# This module is actually a wrapper to log4r gem and serves
|
|
14
|
+
# as a central code to use the log utility.
|
|
15
|
+
module Log
|
|
16
|
+
|
|
17
|
+
#Auxiliary method to retrieve the executable name
|
|
18
|
+
def Log.executable_name
|
|
19
|
+
/([a-zA-Z0-9\-_\.]+):\d+/ =~ caller[caller.size-1]
|
|
20
|
+
return $1
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# Global params
|
|
24
|
+
Params.integer('log_debug_level', 0 , \
|
|
25
|
+
'Verbosity of logging. 0 will log only INFO messages. Other value, will log all DEBUG messages as well.')
|
|
26
|
+
Params.boolean('log_flush_each_message', true, \
|
|
27
|
+
'If true then File and Console outputters will be flushed for each message.')
|
|
28
|
+
Params.boolean('log_write_to_file', true , \
|
|
29
|
+
'If true then the logger will write the messages to a file.')
|
|
30
|
+
Params.path('log_file_name', "~/.bbfs/log/#{Log.executable_name}.log4r" , \
|
|
31
|
+
'Default log file name: ~/.bbfs/log/<executable_name>.log')
|
|
32
|
+
Params.boolean('log_write_to_console', false , \
|
|
33
|
+
'If true then the logger will write the messages to the console.')
|
|
34
|
+
Params.boolean('log_write_to_email', false , \
|
|
35
|
+
'If true then the logger will write the error and fatal messages to email.')
|
|
36
|
+
Params.string('from_email', 'bbfsdev@gmail.com', 'From gmail address for update.')
|
|
37
|
+
Params.string('from_email_password', '', 'From gmail password.')
|
|
38
|
+
Params.string('to_email', 'bbfsdev@gmail.com', 'Destination email for updates.')
|
|
39
|
+
|
|
40
|
+
#Should be called from executable right after params handling.
|
|
41
|
+
# Init Log level and set output to file,stdout and email according to configuration params.
|
|
42
|
+
def Log.init
|
|
43
|
+
@log4r = Log4r::Logger.new 'BBFS log'
|
|
44
|
+
@log4r.trace = true
|
|
45
|
+
|
|
46
|
+
#levels setup
|
|
47
|
+
log4r_level = Log4r::DEBUG
|
|
48
|
+
log4r_level = Log4r::INFO if 0 == Params['log_debug_level']
|
|
49
|
+
|
|
50
|
+
#formatters
|
|
51
|
+
formatter = Log4r::PatternFormatter.new(:pattern => "[%l] [%d] [%m]")
|
|
52
|
+
|
|
53
|
+
#stdout setup
|
|
54
|
+
if Params['log_write_to_console']
|
|
55
|
+
stdout_outputter = Log4r::Outputter.stdout
|
|
56
|
+
stdout_outputter.formatter = formatter
|
|
57
|
+
stdout_outputter.level = log4r_level
|
|
58
|
+
@log4r.outputters << stdout_outputter
|
|
48
59
|
end
|
|
49
60
|
|
|
50
|
-
#
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
end
|
|
58
|
-
# BufferConsumerProducer - If enabled, will use the file consumer to flush a buffer to a file
|
|
59
|
-
if Params['log_write_to_file'] then
|
|
60
|
-
file_consumer = FileConsumer.new Params['log_file_name']
|
|
61
|
-
buffer_consumer_producer = BufferConsumerProducer.new \
|
|
62
|
-
Params['log_param_number_of_mega_bytes_stored_before_flush'], \
|
|
63
|
-
Params['log_param_max_elapsed_time_in_seconds_from_last_flush']
|
|
64
|
-
buffer_consumer_producer.add_consumer file_consumer
|
|
65
|
-
@consumers.push buffer_consumer_producer
|
|
61
|
+
#file setup
|
|
62
|
+
if Params['log_write_to_file']
|
|
63
|
+
if File.exist?(Params['log_file_name'])
|
|
64
|
+
File.delete Params['log_file_name']
|
|
65
|
+
else
|
|
66
|
+
dir_name = File.dirname(Params['log_file_name'])
|
|
67
|
+
FileUtils.mkdir_p(dir_name) unless File.directory?(dir_name)
|
|
66
68
|
end
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
Log.info msg
|
|
72
|
-
} unless Params.get_init_messages().empty?
|
|
69
|
+
file_outputter = Log4r::FileOutputter.new('file_log', :filename => Params['log_file_name'])
|
|
70
|
+
file_outputter.level = log4r_level
|
|
71
|
+
file_outputter.formatter = formatter
|
|
72
|
+
@log4r.outputters << file_outputter
|
|
73
73
|
end
|
|
74
74
|
|
|
75
|
-
#
|
|
76
|
-
|
|
77
|
-
|
|
75
|
+
#email setup
|
|
76
|
+
if Params['log_write_to_email']
|
|
77
|
+
server_name = `hostname`.strip
|
|
78
|
+
email_outputter = Log4r::EmailOutputter.new('email_log',
|
|
79
|
+
:server => 'smtp.gmail.com',
|
|
80
|
+
:port => 587,
|
|
81
|
+
:subject => "Error happened at #{server_name} server run by #{ENV['USER']}. Service_name is #{Params['service_name']}",
|
|
82
|
+
:acct => Params['from_email'],
|
|
83
|
+
:from => Params['from_email'],
|
|
84
|
+
:passwd => Params['from_email_password'],
|
|
85
|
+
:to => Params['to_email'],
|
|
86
|
+
:immediate_at => 'FATAL,ERROR',
|
|
87
|
+
:authtype => :plain,
|
|
88
|
+
:tls => true,
|
|
89
|
+
:formatfirst => true,
|
|
90
|
+
:buffsize => 9999,
|
|
91
|
+
)
|
|
92
|
+
email_outputter.level = Log4r::ERROR
|
|
93
|
+
email_outputter.formatter = formatter
|
|
94
|
+
@log4r.outputters << email_outputter
|
|
78
95
|
end
|
|
79
96
|
|
|
80
|
-
#
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
97
|
+
# Write init message and user parameters
|
|
98
|
+
@log4r.info('BBFS Log initialized.') # log first data
|
|
99
|
+
Params.get_init_messages().each { |msg|
|
|
100
|
+
@log4r.info(msg)
|
|
101
|
+
}
|
|
102
|
+
end
|
|
84
103
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
@consumers.each { |consumer| consumer.push_data data }
|
|
91
|
-
end
|
|
104
|
+
# Auxiliary method to add the calling method to the message
|
|
105
|
+
def Log.msg_with_caller(msg)
|
|
106
|
+
/([a-zA-Z0-9\-_\.]+:\d+)/ =~ caller[1]
|
|
107
|
+
$1 + ':' + msg
|
|
108
|
+
end
|
|
92
109
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
110
|
+
# Log warning massages
|
|
111
|
+
def Log.warning(msg)
|
|
112
|
+
Log.init if @log4r.nil?
|
|
113
|
+
@log4r.warn(msg_with_caller(msg))
|
|
114
|
+
Log.flush if Params['log_flush_each_message']
|
|
115
|
+
end
|
|
97
116
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
117
|
+
# Log error massages
|
|
118
|
+
def Log.error(msg)
|
|
119
|
+
Log.init if @log4r.nil?
|
|
120
|
+
@log4r.error(msg_with_caller(msg))
|
|
121
|
+
Log.flush if Params['log_flush_each_message']
|
|
122
|
+
end
|
|
102
123
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
124
|
+
# Log info massages
|
|
125
|
+
def Log.info(msg)
|
|
126
|
+
Log.init if @log4r.nil?
|
|
127
|
+
@log4r.info(msg_with_caller(msg))
|
|
128
|
+
Log.flush if Params['log_flush_each_message']
|
|
129
|
+
end
|
|
107
130
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
131
|
+
# Log debug level 1 massages
|
|
132
|
+
def Log.debug1(msg)
|
|
133
|
+
if Params['log_debug_level'] >= 1
|
|
134
|
+
Log.init if @log4r.nil?
|
|
135
|
+
@log4r.debug(msg_with_caller(msg))
|
|
136
|
+
Log.flush if Params['log_flush_each_message']
|
|
113
137
|
end
|
|
138
|
+
end
|
|
114
139
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
140
|
+
# Log debug level 2 massages
|
|
141
|
+
def Log.debug2(msg)
|
|
142
|
+
if Params['log_debug_level'] >= 2
|
|
143
|
+
Log.init if @log4r.nil?
|
|
144
|
+
@log4r.debug(msg_with_caller(msg))
|
|
145
|
+
Log.flush if Params['log_flush_each_message']
|
|
120
146
|
end
|
|
147
|
+
end
|
|
121
148
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
149
|
+
# Log debug level 3 massages
|
|
150
|
+
def Log.debug3(msg)
|
|
151
|
+
if Params['log_debug_level'] >= 3
|
|
152
|
+
Log.init if @log4r.nil?
|
|
153
|
+
@log4r.debug(msg_with_caller(msg))
|
|
154
|
+
Log.flush if Params['log_flush_each_message']
|
|
127
155
|
end
|
|
156
|
+
end
|
|
128
157
|
|
|
158
|
+
# Flush email log
|
|
159
|
+
def Log.flush()
|
|
160
|
+
return if @log4r.nil?
|
|
161
|
+
@log4r.outputters.each { |o|
|
|
162
|
+
# Not flushing to email since this will cause empty emails to be sent
|
|
163
|
+
# Email is already configured to immediately send mail on ERROR|FATAL messages.
|
|
164
|
+
o.flush unless o.is_a?(Log4r::EmailOutputter)
|
|
165
|
+
}
|
|
129
166
|
end
|
|
167
|
+
|
|
168
|
+
private_class_method(:msg_with_caller)
|
|
130
169
|
end
|
data/lib/log/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: log
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0
|
|
4
|
+
version: 1.0.0
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -9,11 +9,11 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date:
|
|
12
|
+
date: 2013-05-01 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: params
|
|
16
|
-
requirement:
|
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
|
17
17
|
none: false
|
|
18
18
|
requirements:
|
|
19
19
|
- - ! '>='
|
|
@@ -21,7 +21,28 @@ dependencies:
|
|
|
21
21
|
version: '0'
|
|
22
22
|
type: :runtime
|
|
23
23
|
prerelease: false
|
|
24
|
-
version_requirements:
|
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
25
|
+
none: false
|
|
26
|
+
requirements:
|
|
27
|
+
- - ! '>='
|
|
28
|
+
- !ruby/object:Gem::Version
|
|
29
|
+
version: '0'
|
|
30
|
+
- !ruby/object:Gem::Dependency
|
|
31
|
+
name: log4r
|
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
|
33
|
+
none: false
|
|
34
|
+
requirements:
|
|
35
|
+
- - ! '>='
|
|
36
|
+
- !ruby/object:Gem::Version
|
|
37
|
+
version: '0'
|
|
38
|
+
type: :runtime
|
|
39
|
+
prerelease: false
|
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
41
|
+
none: false
|
|
42
|
+
requirements:
|
|
43
|
+
- - ! '>='
|
|
44
|
+
- !ruby/object:Gem::Version
|
|
45
|
+
version: '0'
|
|
25
46
|
description: logging data to file, console etc. Data can be pushed using info\warning\error\debug-levels
|
|
26
47
|
categories
|
|
27
48
|
email: yaron.dror.bb@gmail.com
|
|
@@ -30,10 +51,8 @@ extensions: []
|
|
|
30
51
|
extra_rdoc_files: []
|
|
31
52
|
files:
|
|
32
53
|
- lib/log.rb
|
|
33
|
-
- lib/log/log_consumer.rb
|
|
34
54
|
- lib/log/version.rb
|
|
35
|
-
|
|
36
|
-
homepage: http://github.com/yarondbb/bbfs
|
|
55
|
+
homepage: http://github.com/bbfsdev/bbfs
|
|
37
56
|
licenses: []
|
|
38
57
|
post_install_message:
|
|
39
58
|
rdoc_options: []
|
|
@@ -53,9 +72,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
53
72
|
version: '0'
|
|
54
73
|
requirements: []
|
|
55
74
|
rubyforge_project:
|
|
56
|
-
rubygems_version: 1.8.
|
|
75
|
+
rubygems_version: 1.8.24
|
|
57
76
|
signing_key:
|
|
58
77
|
specification_version: 3
|
|
59
78
|
summary: Library for logging data.
|
|
60
|
-
test_files:
|
|
61
|
-
- test/log/log_test.rb
|
|
79
|
+
test_files: []
|
data/lib/log/log_consumer.rb
DELETED
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
# Author: Yaron Dror (yaron.dror.bb@gmail.com)
|
|
2
|
-
# Description: Implementation of the Log module - consumer\producer library.
|
|
3
|
-
# Note: The library could be enhance in the future due to project requirement (such as logging
|
|
4
|
-
# to mail, archives, remote servers etc)
|
|
5
|
-
|
|
6
|
-
require 'thread'
|
|
7
|
-
require 'params'
|
|
8
|
-
|
|
9
|
-
module BBFS
|
|
10
|
-
|
|
11
|
-
module Log
|
|
12
|
-
Params.float 'log_param_thread_sleep_time_in_seconds', 0.5 , \
|
|
13
|
-
'log param. Thread sleep time in seconds'
|
|
14
|
-
|
|
15
|
-
# Base class for all consumers
|
|
16
|
-
# Child consumers must implement the 'consume' virtual method
|
|
17
|
-
class Consumer
|
|
18
|
-
# Initializes the consumer queue and starts a thread. The thread waits for data
|
|
19
|
-
# on the queue, and when data is popped, activates the virtual 'consume' method.
|
|
20
|
-
def initialize
|
|
21
|
-
@consumer_queue = Queue.new
|
|
22
|
-
Thread.new do
|
|
23
|
-
while (true)
|
|
24
|
-
consume @consumer_queue.pop
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
# push incoming data to the consumer queue
|
|
30
|
-
def push_data data
|
|
31
|
-
@consumer_queue.push data.clone
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
# BufferConsumerProducer acts as a consumer and as a producer.
|
|
36
|
-
# It has it's own consumers which are added to it.
|
|
37
|
-
# It saves all the data it consumes in a buffer which has a size and time limits.
|
|
38
|
-
# When one of the limits is exceeded, it flushes the buffer to it's own consumers
|
|
39
|
-
class BufferConsumerProducer < Consumer
|
|
40
|
-
def initialize buffer_size_in_mega_bytes, buffer_time_out_in_seconds
|
|
41
|
-
super()
|
|
42
|
-
@buffer_size_in_bytes = buffer_size_in_mega_bytes * 1000000
|
|
43
|
-
@buffer_time_out_in_seconds = buffer_time_out_in_seconds
|
|
44
|
-
@time_at_last_flush = Time.now.to_i
|
|
45
|
-
@buffer = []
|
|
46
|
-
@consumers = []
|
|
47
|
-
Thread.new do
|
|
48
|
-
while (true)
|
|
49
|
-
if @consumer_queue.empty? then
|
|
50
|
-
@consumer_queue.push nil
|
|
51
|
-
sleep Params['log_param_thread_sleep_time_in_seconds']
|
|
52
|
-
end
|
|
53
|
-
end
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
def add_consumer consumer
|
|
58
|
-
@consumers.push consumer
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
def consume data
|
|
62
|
-
@buffer.push data if not data.nil?
|
|
63
|
-
if (@buffer.inspect.size >= @buffer_size_in_bytes) or
|
|
64
|
-
((Time.now.to_i - @time_at_last_flush) >= @buffer_time_out_in_seconds) then
|
|
65
|
-
flush_to_consumers
|
|
66
|
-
end
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
# flush the DB to the consumers
|
|
70
|
-
def flush_to_consumers
|
|
71
|
-
@consumers.each { |consumer| consumer.push_data @buffer}
|
|
72
|
-
@buffer.clear
|
|
73
|
-
@time_at_last_flush = Time.now.to_i
|
|
74
|
-
end
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
# The console consumer logs the data to the standard output
|
|
78
|
-
class ConsoleConsumer < Consumer
|
|
79
|
-
def consume data
|
|
80
|
-
puts data
|
|
81
|
-
end
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
# The file consumer logs the data to a file
|
|
85
|
-
class FileConsumer < Consumer
|
|
86
|
-
def initialize file_name
|
|
87
|
-
super()
|
|
88
|
-
@file_name = file_name
|
|
89
|
-
if File.exist? @file_name then
|
|
90
|
-
File.delete @file_name
|
|
91
|
-
end
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
def consume data
|
|
95
|
-
FileUtils.mkdir_p(File.dirname(@file_name))
|
|
96
|
-
file_handler = File.new @file_name, 'a'
|
|
97
|
-
file_handler.puts data
|
|
98
|
-
file_handler.close
|
|
99
|
-
end
|
|
100
|
-
end
|
|
101
|
-
end
|
|
102
|
-
end
|
data/test/log/log_test.rb
DELETED
|
@@ -1,165 +0,0 @@
|
|
|
1
|
-
# Author: Yaron Dror (yaron.dror.bb@gmail.com)
|
|
2
|
-
# Description: Log test file.
|
|
3
|
-
# run: rake test.
|
|
4
|
-
# Note: This file will be tested along with all project tests.
|
|
5
|
-
|
|
6
|
-
require 'params'
|
|
7
|
-
require 'test/unit'
|
|
8
|
-
require_relative '../../lib/log.rb'
|
|
9
|
-
require_relative '../../lib/log/log_consumer.rb'
|
|
10
|
-
|
|
11
|
-
module BBFS
|
|
12
|
-
|
|
13
|
-
module Log
|
|
14
|
-
# Creating a test consumer class to be able to read the data pushed
|
|
15
|
-
# to the consumer by the logger
|
|
16
|
-
class TestConsumer < Consumer
|
|
17
|
-
attr_reader :test_queue
|
|
18
|
-
|
|
19
|
-
def initialize
|
|
20
|
-
super
|
|
21
|
-
@test_queue = Queue.new()
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
def consume data
|
|
25
|
-
@test_queue.push data
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
class TestLog < Test::Unit::TestCase
|
|
30
|
-
|
|
31
|
-
LOG_TEST_FILE_NAME = 'log_test.rb:'
|
|
32
|
-
LOG_PREFIX = 'BBFS LOG'
|
|
33
|
-
|
|
34
|
-
def initialize name
|
|
35
|
-
super
|
|
36
|
-
Params['log_write_to_console'] = false
|
|
37
|
-
Params['log_write_to_file'] = false
|
|
38
|
-
Log.init
|
|
39
|
-
@test_consumer = TestConsumer.new
|
|
40
|
-
Log.add_consumer @test_consumer
|
|
41
|
-
@line_regexp = Regexp.new(/\[(.*)\] \[(.*)\] \[(.*)\] \[(.*)\] \[(.*)\]/)
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
#check expected format: [LOG_PREFIX] [Time] [INFO] [FILE_NAME:LINE] [MESSAGE]
|
|
45
|
-
def assert_message line, time, type, file_line, msg
|
|
46
|
-
format_containers = @line_regexp.match(line)
|
|
47
|
-
assert_equal format_containers.captures.size, 5
|
|
48
|
-
if format_containers.captures.size == 5 then
|
|
49
|
-
assert_equal format_containers.captures[0], LOG_PREFIX
|
|
50
|
-
assert_equal format_containers.captures[1], time.to_s
|
|
51
|
-
assert_equal format_containers.captures[2], type
|
|
52
|
-
assert_equal format_containers.captures[3], file_line
|
|
53
|
-
assert_equal format_containers.captures[4], msg
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
def test_check_info_format
|
|
58
|
-
#set test phase
|
|
59
|
-
test_message = 'This is a test INFO message.'
|
|
60
|
-
testTime = Time.now
|
|
61
|
-
Log.info test_message
|
|
62
|
-
line = __LINE__ - 1
|
|
63
|
-
#check test phase
|
|
64
|
-
pop_message = @test_consumer.test_queue.pop
|
|
65
|
-
assert_message pop_message, testTime, 'INFO', LOG_TEST_FILE_NAME + line.to_s, test_message
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
def test_check_warning_format
|
|
69
|
-
#set test phase
|
|
70
|
-
test_message = 'This is a test WARNING message.'
|
|
71
|
-
testTime = Time.now
|
|
72
|
-
Log.warning test_message
|
|
73
|
-
line = __LINE__ - 1
|
|
74
|
-
|
|
75
|
-
#check test phase
|
|
76
|
-
pop_message = @test_consumer.test_queue.pop
|
|
77
|
-
assert_message pop_message, testTime, 'WARNING', LOG_TEST_FILE_NAME + line.to_s, test_message
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
def test_check_error_format
|
|
81
|
-
#set test phase
|
|
82
|
-
test_message = 'This is a test ERROR message.'
|
|
83
|
-
testTime = Time.now
|
|
84
|
-
Log.error test_message
|
|
85
|
-
line = __LINE__ - 1
|
|
86
|
-
|
|
87
|
-
#check test phase
|
|
88
|
-
pop_message = @test_consumer.test_queue.pop
|
|
89
|
-
assert_message pop_message, testTime, 'ERROR', LOG_TEST_FILE_NAME + line.to_s, test_message
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
def test_check_debug_level_0
|
|
93
|
-
#set test phase
|
|
94
|
-
Params['log_debug_level'] = 0
|
|
95
|
-
Log.debug1 'This is a test debug-1 message.'
|
|
96
|
-
Log.debug2 'This is a test debug-2 message.'
|
|
97
|
-
Log.debug3 'This is a test debug-3 message.'
|
|
98
|
-
#check test phase
|
|
99
|
-
queue_size = @test_consumer.test_queue.size
|
|
100
|
-
assert_equal queue_size, 0 , \
|
|
101
|
-
"At debug level 0, no debug messages should be found.Test found:#{queue_size} messages."
|
|
102
|
-
end
|
|
103
|
-
|
|
104
|
-
def test_check_debug_level_1
|
|
105
|
-
#set test phase
|
|
106
|
-
Params['log_debug_level'] = 1
|
|
107
|
-
test_message_1 = 'This is a test DEBUG-1 message.'
|
|
108
|
-
test_message_2 = 'This is a test DEBUG-2 message.'
|
|
109
|
-
test_message_3 = 'This is a test DEBUG-3 message.'
|
|
110
|
-
testTime = Time.now
|
|
111
|
-
Log.debug1 test_message_1
|
|
112
|
-
line = __LINE__ - 1
|
|
113
|
-
Log.debug2 test_message_2
|
|
114
|
-
Log.debug3 test_message_3
|
|
115
|
-
|
|
116
|
-
#check test phase
|
|
117
|
-
pop_message = @test_consumer.test_queue.pop
|
|
118
|
-
assert_message pop_message, testTime, 'DEBUG-1', LOG_TEST_FILE_NAME + line.to_s, test_message_1
|
|
119
|
-
end
|
|
120
|
-
|
|
121
|
-
def test_check_debug_level_2
|
|
122
|
-
#set test phase
|
|
123
|
-
Params['log_debug_level'] = 2
|
|
124
|
-
test_message_1 = 'This is a test DEBUG-1 message.'
|
|
125
|
-
test_message_2 = 'This is a test DEBUG-2 message.'
|
|
126
|
-
test_message_3 = 'This is a test DEBUG-3 message.'
|
|
127
|
-
testTime = Time.now
|
|
128
|
-
Log.debug1 test_message_1
|
|
129
|
-
line_1 = __LINE__ - 1
|
|
130
|
-
Log.debug2 test_message_2
|
|
131
|
-
line_2 = __LINE__ - 1
|
|
132
|
-
Log.debug3 test_message_3
|
|
133
|
-
|
|
134
|
-
#check test phase
|
|
135
|
-
pop_message = @test_consumer.test_queue.pop
|
|
136
|
-
assert_message pop_message, testTime, 'DEBUG-1', LOG_TEST_FILE_NAME + line_1.to_s, test_message_1
|
|
137
|
-
pop_message = @test_consumer.test_queue.pop
|
|
138
|
-
assert_message pop_message, testTime, 'DEBUG-2', LOG_TEST_FILE_NAME + line_2.to_s, test_message_2
|
|
139
|
-
end
|
|
140
|
-
|
|
141
|
-
def test_check_debug_level_3
|
|
142
|
-
#set test phase
|
|
143
|
-
Params['log_debug_level'] = 3
|
|
144
|
-
test_message_1 = 'This is a test DEBUG-1 message.'
|
|
145
|
-
test_message_2 = 'This is a test DEBUG-2 message.'
|
|
146
|
-
test_message_3 = 'This is a test DEBUG-3 message.'
|
|
147
|
-
testTime = Time.now
|
|
148
|
-
Log.debug1 'This is a test DEBUG-1 message.'
|
|
149
|
-
line_1 = __LINE__ - 1
|
|
150
|
-
Log.debug2 'This is a test DEBUG-2 message.'
|
|
151
|
-
line_2 = __LINE__ - 1
|
|
152
|
-
Log.debug3 'This is a test DEBUG-3 message.'
|
|
153
|
-
line_3 = __LINE__ - 1
|
|
154
|
-
|
|
155
|
-
#check test phase
|
|
156
|
-
pop_message = @test_consumer.test_queue.pop
|
|
157
|
-
assert_message pop_message, testTime, 'DEBUG-1', LOG_TEST_FILE_NAME + line_1.to_s, test_message_1
|
|
158
|
-
pop_message = @test_consumer.test_queue.pop
|
|
159
|
-
assert_message pop_message, testTime, 'DEBUG-2', LOG_TEST_FILE_NAME + line_2.to_s, test_message_2
|
|
160
|
-
pop_message = @test_consumer.test_queue.pop
|
|
161
|
-
assert_message pop_message, testTime, 'DEBUG-3', LOG_TEST_FILE_NAME + line_3.to_s, test_message_3
|
|
162
|
-
end
|
|
163
|
-
end
|
|
164
|
-
end
|
|
165
|
-
end
|