rubysl-syslog 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.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.travis.yml +8 -0
- data/Gemfile +4 -0
- data/LICENSE +25 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/lib/rubysl/syslog.rb +2 -0
- data/lib/rubysl/syslog/extconf.rb +15 -0
- data/lib/rubysl/syslog/syslog.rb.ffi +307 -0
- data/lib/rubysl/syslog/version.rb +5 -0
- data/lib/syslog.rb +1 -0
- data/rubysl-syslog.gemspec +28 -0
- data/spec/alert_spec.rb +6 -0
- data/spec/close_spec.rb +54 -0
- data/spec/constants_spec.rb +54 -0
- data/spec/crit_spec.rb +6 -0
- data/spec/debug_spec.rb +6 -0
- data/spec/emerg_spec.rb +12 -0
- data/spec/err_spec.rb +6 -0
- data/spec/facility_spec.rb +44 -0
- data/spec/ident_spec.rb +31 -0
- data/spec/info_spec.rb +6 -0
- data/spec/inspect_spec.rb +35 -0
- data/spec/instance_spec.rb +9 -0
- data/spec/log_spec.rb +52 -0
- data/spec/mask_spec.rb +129 -0
- data/spec/notice_spec.rb +6 -0
- data/spec/open_spec.rb +83 -0
- data/spec/opened_spec.rb +35 -0
- data/spec/options_spec.rb +44 -0
- data/spec/reopen_spec.rb +6 -0
- data/spec/shared/log.rb +41 -0
- data/spec/shared/reopen.rb +40 -0
- data/spec/warning_spec.rb +6 -0
- metadata +171 -0
data/spec/alert_spec.rb
ADDED
data/spec/close_spec.rb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'syslog'
|
2
|
+
|
3
|
+
describe "Syslog.close" do
|
4
|
+
platform_is_not :windows do
|
5
|
+
|
6
|
+
before :each do
|
7
|
+
Syslog.opened?.should be_false
|
8
|
+
end
|
9
|
+
|
10
|
+
after :each do
|
11
|
+
Syslog.opened?.should be_false
|
12
|
+
end
|
13
|
+
|
14
|
+
it "closes the log" do
|
15
|
+
Syslog.opened?.should be_false
|
16
|
+
Syslog.open
|
17
|
+
Syslog.opened?.should be_true
|
18
|
+
Syslog.close
|
19
|
+
Syslog.opened?.should be_false
|
20
|
+
end
|
21
|
+
|
22
|
+
it "raises a RuntimeError if the log's already closed" do
|
23
|
+
lambda { Syslog.close }.should raise_error(RuntimeError)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "it does not work inside blocks" do
|
27
|
+
lambda {
|
28
|
+
Syslog.open { |s| s.close }
|
29
|
+
}.should raise_error(RuntimeError)
|
30
|
+
Syslog.opened?.should == false
|
31
|
+
end
|
32
|
+
|
33
|
+
it "sets the identity to nil" do
|
34
|
+
Syslog.open("rubyspec")
|
35
|
+
Syslog.ident.should == "rubyspec"
|
36
|
+
Syslog.close
|
37
|
+
Syslog.ident.should be_nil
|
38
|
+
end
|
39
|
+
|
40
|
+
it "sets the options to nil" do
|
41
|
+
Syslog.open("rubyspec", Syslog::LOG_PID)
|
42
|
+
Syslog.options.should == Syslog::LOG_PID
|
43
|
+
Syslog.close
|
44
|
+
Syslog.options.should == nil
|
45
|
+
end
|
46
|
+
|
47
|
+
it "sets the facility to nil" do
|
48
|
+
Syslog.open
|
49
|
+
Syslog.facility.should == 8
|
50
|
+
Syslog.close
|
51
|
+
Syslog.facility.should == nil
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'syslog'
|
2
|
+
|
3
|
+
describe "Syslog::Constants" do
|
4
|
+
platform_is_not :windows do
|
5
|
+
|
6
|
+
before :all do
|
7
|
+
|
8
|
+
@constants = %w(LOG_AUTHPRIV LOG_USER LOG_LOCAL2 LOG_NOTICE LOG_NDELAY
|
9
|
+
LOG_SYSLOG LOG_ALERT LOG_FTP LOG_LOCAL5 LOG_ERR LOG_AUTH
|
10
|
+
LOG_LOCAL1 LOG_ODELAY LOG_NEWS LOG_DAEMON LOG_LOCAL4
|
11
|
+
LOG_CRIT LOG_INFO LOG_PERROR LOG_LOCAL0 LOG_CONS LOG_LPR
|
12
|
+
LOG_LOCAL7 LOG_WARNING LOG_CRON LOG_LOCAL3 LOG_EMERG
|
13
|
+
LOG_NOWAIT LOG_UUCP LOG_PID LOG_KERN LOG_MAIL LOG_LOCAL6
|
14
|
+
LOG_DEBUG)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "includes the Syslog constants" do
|
18
|
+
@constants.each do |c|
|
19
|
+
Syslog::Constants.should have_constant(c)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
# The masks are defined in <syslog.h>
|
26
|
+
|
27
|
+
describe "Syslog::Constants.LOG_MASK" do
|
28
|
+
it "returns the mask value for a priority" do
|
29
|
+
Syslog::Constants.LOG_MASK(Syslog::LOG_DEBUG).should == 128
|
30
|
+
Syslog::Constants.LOG_MASK(Syslog::LOG_WARNING).should == 16
|
31
|
+
end
|
32
|
+
|
33
|
+
not_compliant_on :rubinius do
|
34
|
+
it "works on undefined constants" do
|
35
|
+
Syslog::Constants.LOG_MASK(1337).should == 33554432
|
36
|
+
Syslog::Constants.LOG_MASK(7331).should == 8
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "Syslog::Constants.LOG_UPTO" do
|
42
|
+
it "returns a mask for the priorities up to a given argument" do
|
43
|
+
Syslog::Constants.LOG_UPTO(Syslog::LOG_ALERT).should == 3
|
44
|
+
Syslog::Constants.LOG_UPTO(Syslog::LOG_DEBUG).should == 255
|
45
|
+
end
|
46
|
+
|
47
|
+
not_compliant_on :rubinius do
|
48
|
+
it "works on undefined constants" do
|
49
|
+
Syslog::Constants.LOG_UPTO(1337).should == 67108863
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
data/spec/crit_spec.rb
ADDED
data/spec/debug_spec.rb
ADDED
data/spec/emerg_spec.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require File.expand_path('../shared/log', __FILE__)
|
2
|
+
require 'syslog'
|
3
|
+
|
4
|
+
describe "Syslog.emerg" do
|
5
|
+
# Some way needs do be found to prevent this spec
|
6
|
+
# from causing output on all open terminals. If this
|
7
|
+
# is not possible, this spec may need a special guard
|
8
|
+
# that only runs when requested.
|
9
|
+
quarantine! do
|
10
|
+
it_behaves_like :syslog_log, :emerg
|
11
|
+
end
|
12
|
+
end
|
data/spec/err_spec.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'syslog'
|
2
|
+
|
3
|
+
describe "Syslog.facility" do
|
4
|
+
platform_is_not :windows do
|
5
|
+
|
6
|
+
before :each do
|
7
|
+
Syslog.opened?.should be_false
|
8
|
+
end
|
9
|
+
|
10
|
+
after :each do
|
11
|
+
Syslog.opened?.should be_false
|
12
|
+
end
|
13
|
+
|
14
|
+
it "returns the logging facility" do
|
15
|
+
Syslog.open("rubyspec", 3, Syslog::LOG_MAIL)
|
16
|
+
Syslog.facility.should == Syslog::LOG_MAIL
|
17
|
+
Syslog.close
|
18
|
+
end
|
19
|
+
|
20
|
+
it "returns nil if the log is closed" do
|
21
|
+
Syslog.opened?.should be_false
|
22
|
+
Syslog.facility.should == nil
|
23
|
+
end
|
24
|
+
|
25
|
+
it "defaults to LOG_USER" do
|
26
|
+
Syslog.open
|
27
|
+
Syslog.facility.should == Syslog::LOG_USER
|
28
|
+
Syslog.close
|
29
|
+
end
|
30
|
+
|
31
|
+
it "resets after each open call" do
|
32
|
+
Syslog.open
|
33
|
+
Syslog.facility.should == Syslog::LOG_USER
|
34
|
+
|
35
|
+
Syslog.open!("rubyspec", 3, Syslog::LOG_MAIL)
|
36
|
+
Syslog.facility.should == Syslog::LOG_MAIL
|
37
|
+
Syslog.close
|
38
|
+
|
39
|
+
Syslog.open
|
40
|
+
Syslog.facility.should == Syslog::LOG_USER
|
41
|
+
Syslog.close
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/spec/ident_spec.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'syslog'
|
2
|
+
|
3
|
+
describe "Syslog.ident" do
|
4
|
+
platform_is_not :windows do
|
5
|
+
|
6
|
+
before :each do
|
7
|
+
Syslog.opened?.should be_false
|
8
|
+
end
|
9
|
+
|
10
|
+
after :each do
|
11
|
+
Syslog.opened?.should be_false
|
12
|
+
end
|
13
|
+
|
14
|
+
it "returns the logging identity" do
|
15
|
+
Syslog.open("rubyspec")
|
16
|
+
Syslog.ident.should == "rubyspec"
|
17
|
+
Syslog.close
|
18
|
+
end
|
19
|
+
|
20
|
+
it "returns nil if the log is closed" do
|
21
|
+
Syslog.opened?.should == false
|
22
|
+
Syslog.ident.should == nil
|
23
|
+
end
|
24
|
+
|
25
|
+
it "defaults to $0" do
|
26
|
+
Syslog.open
|
27
|
+
Syslog.ident.should == $0
|
28
|
+
Syslog.close
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/spec/info_spec.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'syslog'
|
2
|
+
|
3
|
+
describe "Syslog.inspect" do
|
4
|
+
platform_is_not :windows do
|
5
|
+
|
6
|
+
before :each do
|
7
|
+
Syslog.opened?.should be_false
|
8
|
+
end
|
9
|
+
|
10
|
+
after :each do
|
11
|
+
Syslog.opened?.should be_false
|
12
|
+
end
|
13
|
+
|
14
|
+
it "returns a string a closed log" do
|
15
|
+
Syslog.inspect.should =~ /opened=false/
|
16
|
+
end
|
17
|
+
|
18
|
+
it "returns a string for an opened log" do
|
19
|
+
Syslog.open
|
20
|
+
Syslog.inspect.should =~ /opened=true.*/
|
21
|
+
Syslog.close
|
22
|
+
end
|
23
|
+
|
24
|
+
it "includes the ident, options, facility and mask" do
|
25
|
+
Syslog.open("rubyspec", Syslog::LOG_PID, Syslog::LOG_USER)
|
26
|
+
inspect_str = Syslog.inspect.split ", "
|
27
|
+
inspect_str[0].should =~ /opened=true/
|
28
|
+
inspect_str[1].should == "ident=\"rubyspec\""
|
29
|
+
inspect_str[2].should == "options=#{Syslog::LOG_PID}"
|
30
|
+
inspect_str[3].should == "facility=#{Syslog::LOG_USER}"
|
31
|
+
inspect_str[4].should == "mask=255>"
|
32
|
+
Syslog.close
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/spec/log_spec.rb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'syslog'
|
2
|
+
|
3
|
+
describe "Syslog.log" do
|
4
|
+
platform_is_not [:windows, :darwin] do
|
5
|
+
|
6
|
+
before :each do
|
7
|
+
Syslog.opened?.should be_false
|
8
|
+
end
|
9
|
+
|
10
|
+
after :each do
|
11
|
+
Syslog.opened?.should be_false
|
12
|
+
end
|
13
|
+
|
14
|
+
it "receives a priority as first argument" do
|
15
|
+
lambda {
|
16
|
+
Syslog.open("rubyspec", Syslog::LOG_PERROR) do |s|
|
17
|
+
s.log(Syslog::LOG_ALERT, "Hello")
|
18
|
+
s.log(Syslog::LOG_CRIT, "World")
|
19
|
+
end
|
20
|
+
}.should output_to_fd("rubyspec: Hello\nrubyspec: World\n", $stderr)
|
21
|
+
end
|
22
|
+
|
23
|
+
it "accepts undefined priorites" do
|
24
|
+
lambda {
|
25
|
+
Syslog.open("rubyspec", Syslog::LOG_PERROR) do |s|
|
26
|
+
s.log(1337, "Hello")
|
27
|
+
end
|
28
|
+
# use a regex since it'll output unknown facility/priority messages
|
29
|
+
}.should output_to_fd(/rubyspec: Hello/, $stderr)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "fails with TypeError on nil log messages" do
|
33
|
+
Syslog.open do |s|
|
34
|
+
lambda { s.log(1, nil) }.should raise_error(TypeError)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
it "fails if the log is closed" do
|
39
|
+
lambda {
|
40
|
+
Syslog.log(Syslog::LOG_ALERT, "test")
|
41
|
+
}.should raise_error(RuntimeError)
|
42
|
+
end
|
43
|
+
|
44
|
+
it "accepts printf parameters" do
|
45
|
+
lambda {
|
46
|
+
Syslog.open("rubyspec", Syslog::LOG_PERROR) do |s|
|
47
|
+
s.log(Syslog::LOG_ALERT, "%s x %d", "chunky bacon", 2)
|
48
|
+
end
|
49
|
+
}.should output_to_fd("rubyspec: chunky bacon x 2\n", $stderr)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
data/spec/mask_spec.rb
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
require 'syslog'
|
2
|
+
|
3
|
+
describe "Syslog.mask" do
|
4
|
+
platform_is_not :windows do
|
5
|
+
|
6
|
+
before :each do
|
7
|
+
Syslog.opened?.should be_false
|
8
|
+
end
|
9
|
+
|
10
|
+
after :each do
|
11
|
+
Syslog.opened?.should be_false
|
12
|
+
end
|
13
|
+
|
14
|
+
# make sure we return the mask to the default value
|
15
|
+
after :all do
|
16
|
+
Syslog.open { |s| s.mask = 255 }
|
17
|
+
end
|
18
|
+
|
19
|
+
it "returns the log priority mask" do
|
20
|
+
Syslog.open("rubyspec") do
|
21
|
+
Syslog.mask.should == 255
|
22
|
+
Syslog.mask = 3
|
23
|
+
Syslog.mask.should == 3
|
24
|
+
Syslog.mask = 255
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
it "defaults to 255" do
|
29
|
+
Syslog.open do |s|
|
30
|
+
s.mask.should == 255
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
it "returns nil if the log is closed" do
|
35
|
+
Syslog.opened?.should == false
|
36
|
+
Syslog.mask.should == nil
|
37
|
+
end
|
38
|
+
|
39
|
+
platform_is :darwin do
|
40
|
+
it "resets if the log is reopened" do
|
41
|
+
Syslog.open
|
42
|
+
Syslog.mask.should == 255
|
43
|
+
Syslog.mask = 64
|
44
|
+
|
45
|
+
Syslog.reopen("rubyspec") do
|
46
|
+
Syslog.mask.should == 255
|
47
|
+
end
|
48
|
+
|
49
|
+
Syslog.open do
|
50
|
+
Syslog.mask.should == 255
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
platform_is_not :darwin do
|
56
|
+
it "persists if the log is reopened" do
|
57
|
+
Syslog.open
|
58
|
+
Syslog.mask.should == 255
|
59
|
+
Syslog.mask = 64
|
60
|
+
|
61
|
+
Syslog.reopen("rubyspec") do
|
62
|
+
Syslog.mask.should == 64
|
63
|
+
end
|
64
|
+
|
65
|
+
Syslog.open do
|
66
|
+
Syslog.mask.should == 64
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe "Syslog.mask=" do
|
74
|
+
platform_is_not :windows do
|
75
|
+
|
76
|
+
before :each do
|
77
|
+
Syslog.opened?.should be_false
|
78
|
+
end
|
79
|
+
|
80
|
+
after :each do
|
81
|
+
Syslog.opened?.should be_false
|
82
|
+
end
|
83
|
+
|
84
|
+
# make sure we return the mask to the default value
|
85
|
+
after :all do
|
86
|
+
Syslog.open { |s| s.mask = 255 }
|
87
|
+
end
|
88
|
+
|
89
|
+
it "sets the log priority mask" do
|
90
|
+
Syslog.open do
|
91
|
+
Syslog.mask = 64
|
92
|
+
Syslog.mask.should == 64
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
it "persists if the log is reopened" do
|
97
|
+
Syslog.open
|
98
|
+
Syslog.mask = 64
|
99
|
+
|
100
|
+
Syslog.reopen("rubyspec") do
|
101
|
+
Syslog.mask.should == 64
|
102
|
+
Syslog.mask = 255
|
103
|
+
end
|
104
|
+
|
105
|
+
Syslog.open do
|
106
|
+
Syslog.mask.should == 255
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
it "raises an error if the log is closed" do
|
111
|
+
lambda { Syslog.mask = 1337 }.should raise_error(RuntimeError)
|
112
|
+
end
|
113
|
+
|
114
|
+
it "only accepts numbers" do
|
115
|
+
Syslog.open do
|
116
|
+
|
117
|
+
Syslog.mask = 1337
|
118
|
+
Syslog.mask.should == 1337
|
119
|
+
|
120
|
+
Syslog.mask = 3.1416
|
121
|
+
Syslog.mask.should == 3
|
122
|
+
|
123
|
+
lambda { Syslog.mask = "oh hai" }.should raise_error(TypeError)
|
124
|
+
lambda { Syslog.mask = "43" }.should raise_error(TypeError)
|
125
|
+
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|