public
Rubygem
Description: Ramaze is a simple, light and modular open-source web application framework written in Ruby.
Homepage: http://ramaze.net
Clone URL: git://github.com/manveru/ramaze.git
Click here to lend your support to: ramaze and make a donation at www.pledgie.com !
Update ramaze syslog support, the old version did not work(anymore?). I 
modified the interface to use the Logging module and I updated the syslog 
spec file to test the syslog support.
Rob Lievaart (author)
Fri Jun 27 02:08:38 -0700 2008
manveru (committer)
Fri Jun 27 02:24:14 -0700 2008
commit  557c01621bb512dd5200360c461745841ef8c49f
tree    fe4bffd9084bbd2949606cff69dbdb5c977e6632
parent  029b39ae46ba10b72f96242993518719ac783537
...
1
 
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
 
 
 
 
 
 
 
31
32
33
34
35
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
37
38
39
...
1
2
3
4
5
6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
8
9
10
11
12
13
14
 
 
 
 
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
 
 
51
0
@@ -1,39 +1,51 @@
0
 # Copyright (c) 2008 Michael Fellinger m.fellinger@gmail.com
0
+# Copyright (c) 2008 rob@rebeltechnologies.nl
0
 # All files in this distribution are subject to the terms of the Ruby license.
0
 
0
 require 'syslog'
0
 
0
-module Ramaze
0
- module Logger
0
-
0
- # Informer for Syslog from rubys standard-library.
0
-
0
- class Syslog
0
- include ::Syslog
0
-
0
- # opens syslog
0
-
0
- def initialize
0
- open unless ::Syslog.opened?
0
- end
0
-
0
- # alias for default syslog methods so they match ramaze
0
- alias error err
0
- alias warn warning
0
- alias dev debug
0
-
0
- # just sends all messages received to ::Syslog
0
- def inform(tag, *args)
0
- self.__send__(tag, *args)
0
- end
0
-
0
- public :error, :warn
0
+# Add aliases for the levelnames used by Ramaze logging
0
+module Syslog
0
+ alias dev debug
0
+ alias warn warning
0
+ alias error err
0
+ module_function :dev, :warn, :error
0
+end
0
 
0
- # Has to call the modules singleton-method.
0
- def inspect
0
- ::Syslog.inspect
0
- end
0
+module Ramaze
0
+ module Logger
0
+ # Logger class for writing to syslog. It is a *very* thin wrapper
0
+ # around the Syslog library.
0
+ class Syslog
0
+ include Logging
0
+
0
+ # Open the syslog library, if it is allready open, we reopen it using the
0
+ # new argument list. The argument list is passed on to the Syslog library
0
+ # so please check that, and man syslog for detailed information.
0
+ # There are 3 parameters:
0
+ #
0
+ # ident: The identification used in the log file, defaults to $0
0
+ # options: defaults to Syslog::LOG_PID | Syslog::LOG_CONS
0
+ # facility: defaults to Syslog::LOG_USER
0
+ #
0
+ def initialize( *args )
0
+ ::Syslog.close if ::Syslog.opened?
0
+ ::Syslog.open( *args )
0
+ end
0
+
0
+ # just sends all messages received to ::Syslog
0
+ # We simply return if the log was closed for some reason, this behavior
0
+ # was copied from Informer. We do not handle levels here. This will
0
+ # be done by te syslog daemon based on it's configuration.
0
+ def log(tag, *messages)
0
+ return if !::Syslog.opened?
0
+ ::Syslog.send(tag, *messages)
0
+ end
0
+
0
+ # Has to call the modules singleton-method.
0
+ def inspect
0
+ ::Syslog.inspect
0
+ end
0
+ end
0
     end
0
-
0
- end
0
 end
...
 
 
 
1
2
3
4
5
6
7
8
9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
...
1
2
3
4
5
6
7
8
 
 
 
 
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
0
@@ -1,10 +1,73 @@
0
+# Copyright (c) 2008 rob@rebeltechnologies.nl
0
+# All files in this distribution are subject to the terms of the Ruby license.
0
+
0
 require 'spec/helper'
0
 
0
 require 'ramaze/log/syslog'
0
 
0
 describe 'Syslog' do
0
- it 'should do something' do
0
- syslog = Ramaze::Logger::Syslog.new
0
- syslog.send(:ident).should =~ /#{Regexp.escape(__FILE__)}$/
0
- end
0
+
0
+ # close the syslog, if it was open for some reason before we
0
+ # start a test.
0
+ before do
0
+ if ( Syslog.opened? )
0
+ ::Syslog.close
0
+ end
0
+ end
0
+
0
+ it 'should default initialize correctly' do
0
+ syslog = Ramaze::Logger::Syslog.new
0
+ ::Syslog.opened?.should == true
0
+ ::Syslog.ident.should == $0
0
+ ::Syslog.options.should == ( ::Syslog::LOG_PID | ::Syslog::LOG_CONS )
0
+ ::Syslog.facility.should == ::Syslog::LOG_USER
0
+ end
0
+
0
+ it 'should handle non default initialization' do
0
+ syslog = Ramaze::Logger::Syslog.new( 'ramaze_syslog_test',
0
+ ::Syslog::LOG_NDELAY | ::Syslog::LOG_NOWAIT,
0
+ ::Syslog::LOG_DAEMON )
0
+ ::Syslog.opened?.should == true
0
+ ::Syslog.ident.should == 'ramaze_syslog_test'
0
+ ::Syslog.options.should == ( ::Syslog::LOG_NDELAY | ::Syslog::LOG_NOWAIT )
0
+ ::Syslog.facility.should == ::Syslog::LOG_DAEMON
0
+ end
0
+
0
+ # We test the actual logging using a trick found in te test code of the
0
+ # syslog module. We create a pipe, fork a child, reroute the childs
0
+ # stderr to the pipe. Then we open the logging using LOG_PERROR, so all
0
+ # log messages are written to stderror. In the parent we read the messages
0
+ # from the pipe and compare them to what we expected.
0
+ def test_log_msg( type, priority, msg )
0
+ logpipe = IO::pipe
0
+ child = fork {
0
+ logpipe[0].close
0
+ STDERR.reopen(logpipe[1])
0
+ syslog = Ramaze::Logger::Syslog.new( 'ramaze_syslog_test',
0
+ ::Syslog::LOG_PID | ::Syslog::LOG_NDELAY | ::Syslog::LOG_PERROR,
0
+ ::Syslog::LOG_USER )
0
+ syslog.send priority, msg
0
+ Process.exit!( 0 )
0
+ }
0
+ logpipe[1].close
0
+ Process.waitpid(child)
0
+
0
+ logpipe[0].gets.should == "ramaze_syslog_test[#{child}]: #{msg}\n"
0
+ end
0
+
0
+ it 'should handle debug' do
0
+ test_log_msg :direct, :debug, "Hello Debug World"
0
+ end
0
+ it 'should handle dev' do
0
+ test_log_msg :direct, :dev, "Hello Dev World"
0
+ end
0
+ it 'should handle info' do
0
+ test_log_msg :direct, :info, 'Hello Info World!'
0
+ end
0
+ it 'should handle warn' do
0
+ test_log_msg :direct, :warn, 'Hello Warn World!'
0
+ end
0
+ it 'should handle error' do
0
+ test_log_msg :direct, :error, 'Hello Error World!'
0
+ end
0
 end

Comments

    No one has commented yet.