remote_logger 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/HISTORY +4 -0
- data/VERSION +1 -1
- data/lib/remote_logger/drb_logger.rb +30 -0
- data/lib/remote_logger/logger.rb +63 -0
- data/lib/remote_logger/ringy_logger.rb +37 -0
- data/lib/remote_logger.rb +1 -1
- data/spec/remote_logger/drb_logger_spec.rb +19 -0
- data/spec/remote_logger/logger_spec.rb +12 -0
- data/spec/remote_logger/shared_spec.rb +131 -0
- data/spec/spec_helper.rb +7 -0
- metadata +12 -6
- data/lib/remote_logger/remote_logger.rb +0 -104
- data/spec/remote_logger/remote_logger_spec.rb +0 -132
data/HISTORY
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.4
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module RemoteLogger
|
2
|
+
|
3
|
+
# Subclass of RemoteLogger::Logger communicating via DRb protocol
|
4
|
+
class DrbLogger < RemoteLogger::Logger
|
5
|
+
|
6
|
+
def self.start(name = LOGGER_NAME, options = {})
|
7
|
+
# Adding some security (disable remote eval)
|
8
|
+
$SAFE = 1
|
9
|
+
|
10
|
+
# Creating logger instance
|
11
|
+
logger = new options
|
12
|
+
|
13
|
+
# Raising new RingyDingy service
|
14
|
+
logger.info "#{name}: Initializing service..." if options[:verbose]
|
15
|
+
DRb.start_service(options[:uri]||DRB_URI, logger)
|
16
|
+
logger.info "#{name}: Service started" if options[:verbose]
|
17
|
+
|
18
|
+
DRb.thread.join
|
19
|
+
|
20
|
+
# Never reaches this point...
|
21
|
+
logger.info "#{name}: Service finished" if options[:verbose]
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.find(name = LOGGER_NAME, options = {})
|
25
|
+
DRb.start_service
|
26
|
+
# Connecting to Logger
|
27
|
+
DRbObject.new_with_uri(options[:uri]||DRB_URI)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
#encoding: UTF-8
|
2
|
+
|
3
|
+
# TODO: Set up ACL, SSL and other security stuff
|
4
|
+
module RemoteLogger
|
5
|
+
DRB_URI = 'druby://127.0.0.1:61626'
|
6
|
+
LOGGER_NAME = 'RemoteLogger'
|
7
|
+
# Default service/logger name - used by Ring or retrieved via Log4R::Logger[LOGGER_NAME]
|
8
|
+
FILE_NAME = 'remote.log'
|
9
|
+
# File name of log file
|
10
|
+
FILE_ENCODING = 'CP1251:UTF-8'
|
11
|
+
# Encoding pair of log file ('File external:Ruby internal')
|
12
|
+
STDOUT_ENCODING = 'CP866:UTF-8'
|
13
|
+
# Encoding pair of stdout ('Stdout external:Ruby internal')
|
14
|
+
PATTERN = '%1.1l %d - %m'
|
15
|
+
# Log entry pattern
|
16
|
+
DATE_PATTERN = '%Y-%m-%d %H:%M:%S.%3N'
|
17
|
+
|
18
|
+
# A subclass of Log4r::Logger pre-configured with specific logging settings
|
19
|
+
class Logger < Log4r::Logger
|
20
|
+
include Log4r
|
21
|
+
|
22
|
+
# Creates new remote logger. The following options are available:
|
23
|
+
#
|
24
|
+
# <tt>:name</tt>:: Service/logger name - default 'RemoteLogger'
|
25
|
+
# <tt>:outputters</tt>:: Replace outputters (should be Log4r::Outputter subclasses) - default [log file, stdout]
|
26
|
+
# <tt>:file_name</tt>:: Log file name - default 'remote.log'
|
27
|
+
# <tt>:file_encoding</tt>:: Log file encoding - default FILE_ENCODING (Windows Cyrillic)
|
28
|
+
# <tt>:stdout_encoding</tt>:: Stdout encoding - default STDOUT_ENCODING (DOS/IBM Cyrillic)
|
29
|
+
# <tt>:replace</tt>:: Replacement for undefined conversion chars - default '?'
|
30
|
+
# <tt>:pattern</tt>:: Log message pattern - default PATTERN
|
31
|
+
# <tt>:date_pattern</tt>:: Timestamp pattern - default DATE_PATTERN
|
32
|
+
# <tt>:trunc</tt>:: Truncate (rewrite) log file upon creation - default false (append to file)
|
33
|
+
# <tt>:verbose</tt>:: Log all internal messages of RemoteLogger - default false (do not log logger-specific messages)
|
34
|
+
#
|
35
|
+
def initialize options = {}
|
36
|
+
# define outputters: http://log4r.sourceforge.net/rdoc/files/log4r/outputter/outputter_rb.html
|
37
|
+
if options[:outputters]
|
38
|
+
outputters = options[:outputters]
|
39
|
+
else
|
40
|
+
# specify log message format: http://log4r.sourceforge.net/rdoc/files/log4r/formatter/patternformatter_rb.html
|
41
|
+
format = PatternFormatter.new :pattern => options[:pattern]||PATTERN,
|
42
|
+
:date_pattern => options[:date_pattern]||DATE_PATTERN
|
43
|
+
|
44
|
+
# Set up IO streams with correct transcoding and conversion options: log file and (Windows) console
|
45
|
+
conversion = {:undef=>:replace, :replace=>options[:replace]||'?'}
|
46
|
+
file = File.new( options[:file_name]||FILE_NAME, (options[:trunc] ? 'w:' : 'a:') +
|
47
|
+
(options[:file_encoding]||FILE_ENCODING), conversion)
|
48
|
+
$stdout.set_encoding(options[:stdout_encoding]||STDOUT_ENCODING, conversion)
|
49
|
+
|
50
|
+
outputters = [StdoutOutputter.new('console', :formatter => format),
|
51
|
+
IOOutputter.new('file', file, :formatter => format)]
|
52
|
+
# file_o = FileOutputter.new 'file', :filename => 'remote.log', :trunc => false, :formatter => format # wrong encoding
|
53
|
+
# err_o = StderrOutputter.new 'error', :formatter => format # just in case
|
54
|
+
end
|
55
|
+
|
56
|
+
# create new logger named LOG_NAME
|
57
|
+
super(options[:name]||LOGGER_NAME).tap do |logger|
|
58
|
+
logger.outputters = outputters
|
59
|
+
logger.info "#{name}: Logger created" if options[:verbose]
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module RemoteLogger
|
2
|
+
|
3
|
+
# Subclass of RemoteLogger::Logger communicating via DRb protocol
|
4
|
+
class RingyLogger < Logger
|
5
|
+
|
6
|
+
def self.start(name = LOGGER_NAME, options = {})
|
7
|
+
# Adding some security (disable remote eval)
|
8
|
+
$SAFE = 1
|
9
|
+
|
10
|
+
# Creating logger instance
|
11
|
+
logger = RemoteLogger::Logger.new options
|
12
|
+
|
13
|
+
DRb.start_service
|
14
|
+
|
15
|
+
# Raising new RingyDingy service
|
16
|
+
logger.info "#{name}: Initializing service..." if options[:verbose]
|
17
|
+
RingyDingy.new(logger, name.to_sym).run
|
18
|
+
logger.info "#{name}: Service started" if options[:verbose]
|
19
|
+
|
20
|
+
DRb.thread.join
|
21
|
+
|
22
|
+
# Never reaches this point...
|
23
|
+
logger.info "#{name}: Service finished" if options[:verbose]
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.find(name = LOGGER_NAME, options = {})
|
27
|
+
DRb.start_service
|
28
|
+
|
29
|
+
# Connecting to Ring server
|
30
|
+
ring_server = Rinda::RingFinger.primary
|
31
|
+
|
32
|
+
# Requesting logger service by name
|
33
|
+
service = ring_server.read [:name, name.to_sym, nil, nil]
|
34
|
+
service[2]
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/lib/remote_logger.rb
CHANGED
@@ -25,5 +25,5 @@ end # module RemoteLogger
|
|
25
25
|
|
26
26
|
# Require all ruby source files located under directory lib/remote_logger
|
27
27
|
# If you need files in specific order, you should specify it here before the glob
|
28
|
-
RemoteLogger.require_libs %W[**/*]
|
28
|
+
RemoteLogger.require_libs %W[logger **/*]
|
29
29
|
|
@@ -0,0 +1,19 @@
|
|
1
|
+
#encoding: UTF-8
|
2
|
+
require_relative '../spec_helper'
|
3
|
+
require_relative 'shared_spec'
|
4
|
+
|
5
|
+
module RemoteLoggerTest
|
6
|
+
describe RemoteLogger::DrbLogger do
|
7
|
+
spec { use { include RemoteLogger } }
|
8
|
+
|
9
|
+
context 'creating Drb logger' do
|
10
|
+
spec { pending; use { RemoteLogger.start_drb_logger(name = 'RemoteLogger', options = {}) } }
|
11
|
+
|
12
|
+
it_should_behave_like 'Logger'
|
13
|
+
|
14
|
+
it 'instantiates drb logger service'
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
@@ -0,0 +1,131 @@
|
|
1
|
+
#encoding: UTF-8
|
2
|
+
require_relative '../spec_helper'
|
3
|
+
|
4
|
+
module RemoteLoggerTest
|
5
|
+
|
6
|
+
shared_examples_for 'Logger' do
|
7
|
+
before(:each) do
|
8
|
+
File.stub!(:new) { |name, mode, opts| @logfile_mock = StringIO.new('', mode) }
|
9
|
+
end
|
10
|
+
|
11
|
+
context ' by default' do
|
12
|
+
it 'creates a subclass of Log4r logger with default name "RemoteLogger"' do
|
13
|
+
logger = described_class.new
|
14
|
+
logger.should be_a_kind_of Log4r::Logger
|
15
|
+
logger.should == Log4r::Logger['RemoteLogger']
|
16
|
+
logger.should == RemoteLogger::Logger['RemoteLogger']
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'outputs log messages to IOstream(file) and stdout simultaneously' do
|
20
|
+
outputters = described_class.new.outputters
|
21
|
+
outputters.should have(2).outputters
|
22
|
+
outputters.first.should be_an_instance_of Log4r::StdoutOutputter
|
23
|
+
outputters.last.should be_an_instance_of Log4r::IOOutputter
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'appends to logfile "remote.log" with Windows-1251(Cyrillic) encoding' do
|
27
|
+
File.should_receive(:new) do |filename, mode, options|
|
28
|
+
filename.should == "remote.log"
|
29
|
+
mode.should =~ /^a:/
|
30
|
+
mode.should =~ /(CP|cp)1251:/
|
31
|
+
end
|
32
|
+
logger = described_class.new
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'writes to stdout with IBM-866(DOS-Cyrillic) encoding' do
|
36
|
+
$stdout.should_receive(:set_encoding).with(/(CP|cp)866:/, hash_including(:undef))
|
37
|
+
logger = described_class.new
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'logs string messages using default pattern' do
|
41
|
+
logger = described_class.new
|
42
|
+
logger_should_log 'I %Y-%m-%d %H:%M:\d{2}.\d{3} - My message\n'
|
43
|
+
logger.info 'My message'
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'does not log logger creation announcement' do
|
47
|
+
pending 'both @logfile_mock creation and announcement happens in sequence, impossible to set expectations'
|
48
|
+
logger_should_not_log 'Logger created'
|
49
|
+
logger = described_class.new
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'replaces illegal chars in output codepages with ?' do
|
53
|
+
pending 'Impossible to test without real files, since StringIO does not support :undef option'
|
54
|
+
logger_should_log 'I %Y-%m-%d %H:%M:\d{2}.\d{3} - My ?? message\n'
|
55
|
+
logger = described_class.new
|
56
|
+
logger.info 'My 開始 message'
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
context 'with options' do
|
61
|
+
it 'accepts logger name with :name option' do
|
62
|
+
logger = described_class.new :name=>'MyLogger'
|
63
|
+
logger.should == Log4r::Logger['MyLogger']
|
64
|
+
logger.should == RemoteLogger::Logger['MyLogger']
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'accepts logfile name with :file_name option' do
|
68
|
+
File.should_receive(:new).with('my_name.log', anything, anything)
|
69
|
+
logger = described_class.new :file_name=>'my_name.log'
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'accepts custom log pattern with :pattern option' do
|
73
|
+
logger = described_class.new :pattern=>'%d %l %7.7m'
|
74
|
+
logger_should_log '%Y-%m-%d %H:%M:\d{2}.\d{3} INFO My mess\n'
|
75
|
+
logger.info 'My message'
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'accepts custom date pattern with :date_pattern option' do
|
79
|
+
logger = described_class.new :date_pattern=>'%m/%d/%y'
|
80
|
+
logger_should_log 'I %m/%d/%y - My message\n'
|
81
|
+
logger.info 'My message'
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'accepts custom file encoding with :file_encoding option' do
|
85
|
+
File.should_receive(:new).with(anything, /^a:CP866/, anything)
|
86
|
+
logger = described_class.new :file_encoding=>'CP866'
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'accepts custom stdout encoding with :stdout_encoding option' do
|
90
|
+
$stdout.should_receive(:set_encoding).with(/CP1251/, hash_including(:undef))
|
91
|
+
logger = described_class.new :stdout_encoding=>'CP1251'
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'accepts custom outputters with :outputters option, replacing default outputters' do
|
95
|
+
out_string = StringIO.new
|
96
|
+
$stdout.should_not_receive(:set_encoding)
|
97
|
+
File.should_not_receive(:new)
|
98
|
+
logger = described_class.new :outputters=>Log4r::IOOutputter.new('errors', out_string)
|
99
|
+
$stdout.should_not_receive(:print)
|
100
|
+
out_string.should_receive(:print).with " INFO RemoteLogger: My message\n"
|
101
|
+
logger.info 'My message'
|
102
|
+
end
|
103
|
+
|
104
|
+
it 'rewrites logfile with :trunc option' do
|
105
|
+
File.should_receive(:new).with(anything, /^w:/, anything)
|
106
|
+
# File.new(options[:file_name]||FILE_NAME, (options[:trunc] ? 'w:' : 'a:') +
|
107
|
+
# (options[:file_encoding]||FILE_ENCODING), :undef => options[:undef]||:replace)
|
108
|
+
logger = described_class.new( trunc: true)
|
109
|
+
end
|
110
|
+
|
111
|
+
it 'specifies conversion replacement char with :replace option' do
|
112
|
+
pending 'Impossible to test without real files, since StringIO does not support :undef option'
|
113
|
+
File.should_receive(:new).with(anything, anything, hash_including(:replace))
|
114
|
+
# File.new(options[:file_name]||FILE_NAME, (options[:trunc] ? 'w:' : 'a:') +
|
115
|
+
# (options[:file_encoding]||FILE_ENCODING), :undef => options[:undef]||:replace)
|
116
|
+
logger = described_class.new
|
117
|
+
#:replace=>'-'
|
118
|
+
logger_should_log '%Y-%m-%d %H:%M:\d{2}.\d{3} INFO My -- message\n'
|
119
|
+
logger.info 'My 開始 message'
|
120
|
+
p @logfile_mock
|
121
|
+
end
|
122
|
+
|
123
|
+
it 'logs logger creation announcement with :verbose option' do
|
124
|
+
pending 'both @logfile_mock creation and announcement happens in sequence, impossible to set expectations'
|
125
|
+
logger_should_log 'Logger created'
|
126
|
+
logger = described_class.new( verbose: true )
|
127
|
+
end
|
128
|
+
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -45,4 +45,11 @@ module RemoteLoggerTest
|
|
45
45
|
@logfile_mock.should_receive(:print).with(Regexp.new(formatted_message))
|
46
46
|
$stdout.should_receive(:print).with(Regexp.new(formatted_message))
|
47
47
|
end
|
48
|
+
|
49
|
+
def logger_should_not_log message
|
50
|
+
formatted_message = Time.now.strftime message
|
51
|
+
@logfile_mock.should_not_receive(:print).with(Regexp.new(formatted_message))
|
52
|
+
$stdout.should_not_receive(:print).with(Regexp.new(formatted_message))
|
53
|
+
end
|
54
|
+
|
48
55
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: remote_logger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 4
|
10
|
+
version: 0.0.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- arvicco
|
@@ -92,10 +92,14 @@ extra_rdoc_files:
|
|
92
92
|
- README.rdoc
|
93
93
|
files:
|
94
94
|
- bin/remote_logger
|
95
|
-
- lib/remote_logger/
|
95
|
+
- lib/remote_logger/drb_logger.rb
|
96
|
+
- lib/remote_logger/logger.rb
|
97
|
+
- lib/remote_logger/ringy_logger.rb
|
96
98
|
- lib/remote_logger.rb
|
97
99
|
- lib/version.rb
|
98
|
-
- spec/remote_logger/
|
100
|
+
- spec/remote_logger/drb_logger_spec.rb
|
101
|
+
- spec/remote_logger/logger_spec.rb
|
102
|
+
- spec/remote_logger/shared_spec.rb
|
99
103
|
- spec/spec.opts
|
100
104
|
- spec/spec_helper.rb
|
101
105
|
- features/remote_logger.feature
|
@@ -153,6 +157,8 @@ signing_key:
|
|
153
157
|
specification_version: 3
|
154
158
|
summary: Client/server for remote logger using multiple communication methods
|
155
159
|
test_files:
|
156
|
-
- spec/remote_logger/
|
160
|
+
- spec/remote_logger/drb_logger_spec.rb
|
161
|
+
- spec/remote_logger/logger_spec.rb
|
162
|
+
- spec/remote_logger/shared_spec.rb
|
157
163
|
- spec/spec.opts
|
158
164
|
- spec/spec_helper.rb
|
@@ -1,104 +0,0 @@
|
|
1
|
-
#encoding: UTF-8
|
2
|
-
# TODO: Set up ACL, SSL and other security stuff
|
3
|
-
module RemoteLogger
|
4
|
-
include Log4r
|
5
|
-
|
6
|
-
DRB_URI = 'druby://127.0.0.1:61626'
|
7
|
-
LOGGER_NAME = 'RemoteLogger' # Default service/logger name - used by Ring or retrieved via Log4R::Logger[LOGGER_NAME]
|
8
|
-
FILE_NAME = 'remote.log' # File name of log file
|
9
|
-
FILE_ENCODING = 'CP1251:UTF-8' # Encoding pair of log file ('File external:Ruby internal')
|
10
|
-
STDOUT_ENCODING = 'CP866:UTF-8' # Encoding pair of stdout ('Stdout external:Ruby internal')
|
11
|
-
PATTERN = '%1.1l %d - %m' # Log entry pattern
|
12
|
-
DATE_PATTERN = '%Y-%m-%d %H:%M:%S.%3N'
|
13
|
-
|
14
|
-
# Creates a new Log4r logger. The following options are available:
|
15
|
-
#
|
16
|
-
# <tt>:name</tt>:: Service/logger name - default 'RemoteLogger'
|
17
|
-
# <tt>:outputters</tt>:: Replace outputters (should be Log4r::Outputter subclasses) - default [log file, stdout]
|
18
|
-
# <tt>:file_name</tt>:: Log file name - default 'remote.log'
|
19
|
-
# <tt>:file_encoding</tt>:: Log file encoding - default FILE_ENCODING (Windows Cyrillic)
|
20
|
-
# <tt>:stdout_encoding</tt>:: Stdout encoding - default STDOUT_ENCODING (DOS/IBM Cyrillic)
|
21
|
-
# <tt>:replace</tt>:: Replacement for undefined conversion chars - default '?'
|
22
|
-
# <tt>:pattern</tt>:: Log message pattern - default PATTERN
|
23
|
-
# <tt>:date_pattern</tt>:: Timestamp pattern - default DATE_PATTERN
|
24
|
-
# <tt>:trunc</tt>:: Truncate (rewrite) log file upon creation - default false (append to file)
|
25
|
-
# <tt>:verbose</tt>:: Log all internal messages of RemoteLogger - default false (do not log logger-specific messages)
|
26
|
-
#
|
27
|
-
def self.create_logger options = {}
|
28
|
-
# define outputters: http://log4r.sourceforge.net/rdoc/files/log4r/outputter/outputter_rb.html
|
29
|
-
if options[:outputters]
|
30
|
-
outputters = options[:outputters]
|
31
|
-
else
|
32
|
-
# specify log message format: http://log4r.sourceforge.net/rdoc/files/log4r/formatter/patternformatter_rb.html
|
33
|
-
format = PatternFormatter.new :pattern => options[:pattern]||PATTERN,
|
34
|
-
:date_pattern => options[:date_pattern]||DATE_PATTERN
|
35
|
-
|
36
|
-
# Set up IO streams with correct transcoding and conversion options: log file and (Windows) console
|
37
|
-
conversion = {:undef=>:replace, :replace=>options[:replace]||'?'}
|
38
|
-
file = File.new(options[:file_name]||FILE_NAME, (options[:trunc] ? 'w:' : 'a:') +
|
39
|
-
(options[:file_encoding]||FILE_ENCODING), conversion )
|
40
|
-
$stdout.set_encoding(options[:stdout_encoding]||STDOUT_ENCODING, conversion)
|
41
|
-
|
42
|
-
outputters = [StdoutOutputter.new('console', :formatter => format),
|
43
|
-
IOOutputter.new('file', file, :formatter => format) ]
|
44
|
-
# file_o = FileOutputter.new 'file', :filename => 'remote.log', :trunc => false, :formatter => format # wrong encoding
|
45
|
-
# err_o = StderrOutputter.new 'error', :formatter => format # just in case
|
46
|
-
end
|
47
|
-
|
48
|
-
# create new logger named LOG_NAME
|
49
|
-
Logger.new(options[:name]||LOGGER_NAME).tap do |logger|
|
50
|
-
logger.outputters = outputters
|
51
|
-
logger.info "#{name}: Logger created" if options[:verbose]
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
def self.start_ringy_logger(name = LOGGER_NAME, options = {})
|
56
|
-
# Adding some security (disable remote eval)
|
57
|
-
$SAFE = 1
|
58
|
-
|
59
|
-
# Creating logger instance
|
60
|
-
logger = create_logger options
|
61
|
-
|
62
|
-
DRb.start_service
|
63
|
-
|
64
|
-
# Raising new RingyDingy service
|
65
|
-
logger.info "#{name}: Initializing service..." if options[:verbose]
|
66
|
-
RingyDingy.new(logger, name.to_sym).run
|
67
|
-
logger.info "#{name}: Service started" if options[:verbose]
|
68
|
-
|
69
|
-
DRb.thread.join
|
70
|
-
logger.info "#{name}: Service finished" if options[:verbose]
|
71
|
-
end
|
72
|
-
|
73
|
-
def self.find_ringy_logger(name = LOGGER_NAME, options = {})
|
74
|
-
DRb.start_service
|
75
|
-
# Connecting to Logger
|
76
|
-
ring_server = Rinda::RingFinger.primary
|
77
|
-
service = ring_server.read [:name, name.to_sym, nil, nil]
|
78
|
-
service[2]
|
79
|
-
end
|
80
|
-
|
81
|
-
def self.start_drb_logger(name = LOGGER_NAME, options = {})
|
82
|
-
# Adding some security (disable remote eval)
|
83
|
-
$SAFE = 1
|
84
|
-
|
85
|
-
# Creating logger instance
|
86
|
-
logger = create_logger options
|
87
|
-
|
88
|
-
# Raising new RingyDingy service
|
89
|
-
logger.info "#{name}: Initializing service..." if options[:verbose]
|
90
|
-
DRb.start_service(options[:uri]||DRB_URI, logger)
|
91
|
-
logger.info "#{name}: Service started" if options[:verbose]
|
92
|
-
|
93
|
-
DRb.thread.join
|
94
|
-
logger.info "#{name}: Service finished" if options[:verbose]
|
95
|
-
end
|
96
|
-
|
97
|
-
def self.find_drb_logger(name = LOGGER_NAME, options = {})
|
98
|
-
DRb.start_service
|
99
|
-
# Connecting to Logger
|
100
|
-
log = DRbObject.new_with_uri(options[:uri]||DRB_URI)
|
101
|
-
end
|
102
|
-
|
103
|
-
|
104
|
-
end
|
@@ -1,132 +0,0 @@
|
|
1
|
-
#encoding: UTF-8
|
2
|
-
require_relative '../spec_helper'
|
3
|
-
|
4
|
-
module RemoteLoggerTest
|
5
|
-
describe RemoteLogger do
|
6
|
-
before(:each) do
|
7
|
-
File.stub!(:new) {|name, mode, opts| @logfile_mock = StringIO.new('', mode) }
|
8
|
-
end
|
9
|
-
|
10
|
-
spec {use { include RemoteLogger}}
|
11
|
-
|
12
|
-
shared_examples_for 'Log4r proxy' do
|
13
|
-
context ' by default' do
|
14
|
-
it 'creates Log4r logger with default name "RemoteLogger"' do
|
15
|
-
logger = RemoteLogger.create_logger
|
16
|
-
logger.should be_an_instance_of Log4r::Logger
|
17
|
-
logger.should == Log4r::Logger['RemoteLogger']
|
18
|
-
logger.should == RemoteLogger::Logger['RemoteLogger']
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'outputs log messages to IOstream(file) and stdout simultaneously' do
|
22
|
-
outputters = RemoteLogger.create_logger.outputters
|
23
|
-
outputters.should have(2).outputters
|
24
|
-
outputters.first.should be_an_instance_of Log4r::StdoutOutputter
|
25
|
-
outputters.last.should be_an_instance_of Log4r::IOOutputter
|
26
|
-
end
|
27
|
-
|
28
|
-
it 'appends to logfile "remote.log" with Windows-1251(Cyrillic) encoding' do
|
29
|
-
File.should_receive(:new) do |filename, mode, options|
|
30
|
-
filename.should == "remote.log"
|
31
|
-
mode.should =~ /^a:/
|
32
|
-
mode.should =~ /(CP|cp)1251:/
|
33
|
-
end
|
34
|
-
logger = RemoteLogger.create_logger
|
35
|
-
end
|
36
|
-
|
37
|
-
it 'writes to stdout with IBM-866(DOS-Cyrillic) encoding' do
|
38
|
-
$stdout.should_receive(:set_encoding).with(/(CP|cp)866:/, hash_including(:undef))
|
39
|
-
logger = RemoteLogger.create_logger
|
40
|
-
end
|
41
|
-
|
42
|
-
it 'logs string messages using default pattern' do
|
43
|
-
logger = RemoteLogger.create_logger
|
44
|
-
logger_should_log 'I %Y-%m-%d %H:%M:\d{2}.\d{3} - My message\n'
|
45
|
-
logger.info 'My message'
|
46
|
-
end
|
47
|
-
|
48
|
-
it 'logs logger creation announcement'
|
49
|
-
|
50
|
-
it 'replaces illegal chars in output codepages with ?' do
|
51
|
-
pending 'Impossible to test without real files'
|
52
|
-
logger_should_log 'I %Y-%m-%d %H:%M:\d{2}.\d{3} - My ? message\n'
|
53
|
-
logger = RemoteLogger.create_logger
|
54
|
-
logger.info 'My 昔 message'
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
context 'with options' do
|
59
|
-
it 'accepts logger name with :name option' do
|
60
|
-
logger = RemoteLogger.create_logger :name=>'MyLogger'
|
61
|
-
logger.should == Log4r::Logger['MyLogger']
|
62
|
-
logger.should == RemoteLogger::Logger['MyLogger']
|
63
|
-
end
|
64
|
-
|
65
|
-
it 'accepts logfile name with :file_name option' do
|
66
|
-
File.should_receive(:new).with('my_name.log', anything, anything)
|
67
|
-
logger = RemoteLogger.create_logger :file_name=>'my_name.log'
|
68
|
-
end
|
69
|
-
|
70
|
-
it 'accepts custom log pattern with :pattern option' do
|
71
|
-
logger = RemoteLogger.create_logger :pattern=>'%d %l %7.7m'
|
72
|
-
logger_should_log '%Y-%m-%d %H:%M:\d{2}.\d{3} INFO My mess\n'
|
73
|
-
logger.info 'My message'
|
74
|
-
end
|
75
|
-
|
76
|
-
it 'accepts custom date pattern with :date_pattern option' do
|
77
|
-
logger = RemoteLogger.create_logger :date_pattern=>'%m/%d/%y'
|
78
|
-
logger_should_log 'I %m/%d/%y - My message\n'
|
79
|
-
logger.info 'My message'
|
80
|
-
end
|
81
|
-
|
82
|
-
it 'accepts custom file encoding with :file_encoding option' do
|
83
|
-
File.should_receive(:new).with(anything, /^a:CP866/, anything)
|
84
|
-
logger = RemoteLogger.create_logger :file_encoding=>'CP866'
|
85
|
-
end
|
86
|
-
|
87
|
-
it 'accepts custom stdout encoding with :stdout_encoding option' do
|
88
|
-
$stdout.should_receive(:set_encoding).with(/CP1251/, hash_including(:undef))
|
89
|
-
logger = RemoteLogger.create_logger :stdout_encoding=>'CP1251'
|
90
|
-
end
|
91
|
-
|
92
|
-
it 'accepts custom outputters with :outputters option, replacing default outputters' do
|
93
|
-
out_string = StringIO.new
|
94
|
-
$stdout.should_not_receive(:set_encoding)
|
95
|
-
File.should_not_receive(:new)
|
96
|
-
logger = RemoteLogger.create_logger :outputters=>Log4r::IOOutputter.new('errors', out_string)
|
97
|
-
$stdout.should_not_receive(:print)
|
98
|
-
out_string.should_receive(:print).with " INFO RemoteLogger: My message\n"
|
99
|
-
logger.info 'My message'
|
100
|
-
end
|
101
|
-
|
102
|
-
it 'rewrites logfile with :trunc option' do
|
103
|
-
File.should_receive(:new).with(anything, /^w:/, anything)
|
104
|
-
# File.new(options[:file_name]||FILE_NAME, (options[:trunc] ? 'w:' : 'a:') +
|
105
|
-
# (options[:file_encoding]||FILE_ENCODING), :undef => options[:undef]||:replace)
|
106
|
-
logger = RemoteLogger.create_logger :trunc=>true
|
107
|
-
end
|
108
|
-
|
109
|
-
it 'specifies conversion replacement char with :replace option' do
|
110
|
-
pending 'Impossible to test without real files'
|
111
|
-
File.should_receive(:new).with(anything, anything, hash_including(:replace))
|
112
|
-
# File.new(options[:file_name]||FILE_NAME, (options[:trunc] ? 'w:' : 'a:') +
|
113
|
-
# (options[:file_encoding]||FILE_ENCODING), :undef => options[:undef]||:replace)
|
114
|
-
logger = RemoteLogger.create_logger #:replace=>'-'
|
115
|
-
logger_should_log '%Y-%m-%d %H:%M:\d{2}.\d{3} INFO My - message\n'
|
116
|
-
logger.info 'My 昔 message'
|
117
|
-
end
|
118
|
-
|
119
|
-
it 'skips logger creation announcement with :silent option'
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
|
-
context 'creating Drb logger' do
|
124
|
-
spec{ pending; use{ RemoteLogger.start_drb_logger(name = 'RemoteLogger', options = {})}}
|
125
|
-
it_should_behave_like 'Log4r proxy'
|
126
|
-
|
127
|
-
it 'instantiates drb logger service' do
|
128
|
-
|
129
|
-
end
|
130
|
-
end
|
131
|
-
end
|
132
|
-
end
|