rubysl-syslog 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- 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
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 894d206e352212f68ad2cb0defbaa38990263981
|
4
|
+
data.tar.gz: 4757483d1db5f76795b993b88f9529268981064e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 82d6bb7c726e989f0417f8c7115499a0d8982b99e2c6906eea23bfbed8dec6166277a5182cf3cd57132ea7ed2fc329a6196b0ba90c060abf7fd0a65a3ef7d8c4
|
7
|
+
data.tar.gz: 55a005fdb0bf1f9d1bf79055ab7ca16e0a6d7b321a1d6b877d2e4d549bcb473146b65aa4084e26d8c69f355d726666e5ebdede742a2884ca1e7186ec23568dff
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
Copyright (c) 2013, Brian Shirai
|
2
|
+
All rights reserved.
|
3
|
+
|
4
|
+
Redistribution and use in source and binary forms, with or without
|
5
|
+
modification, are permitted provided that the following conditions are met:
|
6
|
+
|
7
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
8
|
+
list of conditions and the following disclaimer.
|
9
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
10
|
+
this list of conditions and the following disclaimer in the documentation
|
11
|
+
and/or other materials provided with the distribution.
|
12
|
+
3. Neither the name of the library nor the names of its contributors may be
|
13
|
+
used to endorse or promote products derived from this software without
|
14
|
+
specific prior written permission.
|
15
|
+
|
16
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
17
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
18
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
19
|
+
DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY DIRECT,
|
20
|
+
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
21
|
+
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
22
|
+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
23
|
+
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
24
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
25
|
+
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Rubysl::Syslog
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'rubysl-syslog'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install rubysl-syslog
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require "ffi2/generators"
|
2
|
+
|
3
|
+
FFI::FileProcessor.new "syslog.rb.ffi", "syslog.rb"
|
4
|
+
|
5
|
+
# Fake out rubygem's expected build steps with extconf.rb
|
6
|
+
File.open "Makefile", "w" do |f|
|
7
|
+
f.puts <<-EOM
|
8
|
+
.PHONY: all install
|
9
|
+
|
10
|
+
all:
|
11
|
+
|
12
|
+
install:
|
13
|
+
|
14
|
+
EOM
|
15
|
+
end
|
@@ -0,0 +1,307 @@
|
|
1
|
+
# Created by Ari Brown on 2008-02-23.
|
2
|
+
# For rubinius. All pwnage reserved.
|
3
|
+
#
|
4
|
+
|
5
|
+
# ** Syslog(Module)
|
6
|
+
|
7
|
+
# Included Modules: Syslog::Constants
|
8
|
+
|
9
|
+
# require 'syslog'
|
10
|
+
|
11
|
+
# A Simple wrapper for the UNIX syslog system calls that might be handy
|
12
|
+
# if you're writing a server in Ruby. For the details of the syslog(8)
|
13
|
+
# architecture and constants, see the syslog(3) manual page of your
|
14
|
+
# platform.
|
15
|
+
|
16
|
+
module Syslog
|
17
|
+
FFI = Rubinius::FFI
|
18
|
+
|
19
|
+
module Constants
|
20
|
+
@@@
|
21
|
+
constants do |c|
|
22
|
+
c.include 'syslog.h'
|
23
|
+
|
24
|
+
c.const 'LOG_EMERG'
|
25
|
+
c.const 'LOG_ALERT'
|
26
|
+
c.const 'LOG_ERR'
|
27
|
+
c.const 'LOG_CRIT'
|
28
|
+
c.const 'LOG_WARNING'
|
29
|
+
c.const 'LOG_NOTICE'
|
30
|
+
c.const 'LOG_INFO'
|
31
|
+
c.const 'LOG_DEBUG'
|
32
|
+
c.const 'LOG_PID'
|
33
|
+
c.const 'LOG_CONS'
|
34
|
+
c.const 'LOG_ODELAY'
|
35
|
+
c.const 'LOG_NDELAY'
|
36
|
+
c.const 'LOG_NOWAIT'
|
37
|
+
c.const 'LOG_PERROR'
|
38
|
+
c.const 'LOG_AUTH'
|
39
|
+
c.const 'LOG_AUTHPRIV'
|
40
|
+
c.const 'LOG_CONSOLE'
|
41
|
+
c.const 'LOG_CRON'
|
42
|
+
c.const 'LOG_DAEMON'
|
43
|
+
c.const 'LOG_FTP'
|
44
|
+
c.const 'LOG_KERN'
|
45
|
+
c.const 'LOG_LPR'
|
46
|
+
c.const 'LOG_MAIL'
|
47
|
+
c.const 'LOG_NEWS'
|
48
|
+
c.const 'LOG_NTP'
|
49
|
+
c.const 'LOG_SECURITY'
|
50
|
+
c.const 'LOG_SYSLOG'
|
51
|
+
c.const 'LOG_USER'
|
52
|
+
c.const 'LOG_UUCP'
|
53
|
+
c.const 'LOG_LOCAL0'
|
54
|
+
c.const 'LOG_LOCAL1'
|
55
|
+
c.const 'LOG_LOCAL2'
|
56
|
+
c.const 'LOG_LOCAL3'
|
57
|
+
c.const 'LOG_LOCAL4'
|
58
|
+
c.const 'LOG_LOCAL5'
|
59
|
+
c.const 'LOG_LOCAL6'
|
60
|
+
c.const 'LOG_LOCAL7'
|
61
|
+
end
|
62
|
+
@@@
|
63
|
+
|
64
|
+
##
|
65
|
+
# LOG_MASK(pri)
|
66
|
+
#
|
67
|
+
# HACK copied from macro
|
68
|
+
# Creates a mask for one priority.
|
69
|
+
def self.LOG_MASK(pri)
|
70
|
+
1 << pri
|
71
|
+
end
|
72
|
+
|
73
|
+
##
|
74
|
+
# LOG_UPTO(pri)
|
75
|
+
# HACK copied from macro
|
76
|
+
# Creates a mask for all priorities up to pri.
|
77
|
+
def self.LOG_UPTO(pri)
|
78
|
+
(1 << ((pri)+1)) - 1
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
include Constants
|
83
|
+
|
84
|
+
module Foreign
|
85
|
+
extend FFI::Library
|
86
|
+
|
87
|
+
# methods
|
88
|
+
attach_function :open, "openlog", [:pointer, :int, :int], :void
|
89
|
+
attach_function :close, "closelog", [], :void
|
90
|
+
attach_function :write, "syslog", [:int, :string, :string], :void
|
91
|
+
attach_function :set_mask, "setlogmask", [:int], :int
|
92
|
+
end
|
93
|
+
|
94
|
+
# Not open by default.
|
95
|
+
#
|
96
|
+
# Yes, a normal ivar, on Syslog, the module.
|
97
|
+
@open = false
|
98
|
+
|
99
|
+
##
|
100
|
+
# returns the ident of the last open call
|
101
|
+
def self.ident
|
102
|
+
@open ? @ident : nil
|
103
|
+
end
|
104
|
+
|
105
|
+
##
|
106
|
+
# returns the options of the last open call
|
107
|
+
def self.options
|
108
|
+
@open ? @options : nil
|
109
|
+
end
|
110
|
+
|
111
|
+
##
|
112
|
+
# returns the facility of the last open call
|
113
|
+
def self.facility
|
114
|
+
@open ? @facility : nil
|
115
|
+
end
|
116
|
+
|
117
|
+
##
|
118
|
+
# mask
|
119
|
+
# mask=(mask)
|
120
|
+
#
|
121
|
+
# Returns or sets the log priority mask. The value of the mask
|
122
|
+
# is persistent and will not be reset by Syslog::open or
|
123
|
+
# Syslog::close.
|
124
|
+
#
|
125
|
+
# Example:
|
126
|
+
# Syslog.mask = Syslog::LOG_UPTO(Syslog::LOG_ERR)
|
127
|
+
def self.mask=(mask)
|
128
|
+
unless @open
|
129
|
+
raise RuntimeError, "must open syslog before setting log mask"
|
130
|
+
end
|
131
|
+
|
132
|
+
@mask_before_reopen = nil
|
133
|
+
|
134
|
+
@mask = Rubinius::Type.coerce_to mask, Fixnum, :to_int
|
135
|
+
|
136
|
+
Foreign.set_mask(@mask)
|
137
|
+
end
|
138
|
+
|
139
|
+
def self.mask
|
140
|
+
@open ? @mask : nil
|
141
|
+
end
|
142
|
+
|
143
|
+
##
|
144
|
+
# open(ident = $0, logopt = Syslog::LOG_PID | Syslog::LOG_CONS, facility = Syslog::LOG_USER) [{ |syslog| ... }]
|
145
|
+
#
|
146
|
+
# Opens syslog with the given options and returns the module
|
147
|
+
# itself. If a block is given, calls it with an argument of
|
148
|
+
# itself. If syslog is already opened, raises RuntimeError.
|
149
|
+
#
|
150
|
+
# Examples:
|
151
|
+
# Syslog.open('ftpd', Syslog::LOG_PID | Syslog::LOG_NDELAY, Syslog::LOG_FTP)
|
152
|
+
# open!(ident = $0, logopt = Syslog::LOG_PID | Syslog::LOG_CONS, facility = Syslog::LOG_USER)
|
153
|
+
# reopen(ident = $0, logopt = Syslog::LOG_PID | Syslog::LOG_CONS, facility = Syslog::LOG_USER)
|
154
|
+
def self.open(ident=nil, opt=nil, fac=nil)
|
155
|
+
raise "Syslog already open" unless not @open
|
156
|
+
|
157
|
+
ident ||= $0
|
158
|
+
opt ||= Constants::LOG_PID | Constants::LOG_CONS
|
159
|
+
fac ||= Constants::LOG_USER
|
160
|
+
|
161
|
+
@ident = ident
|
162
|
+
@options = opt
|
163
|
+
@facility = fac
|
164
|
+
|
165
|
+
# syslog rereads the string everytime syslog() is called, so we have to use
|
166
|
+
# an FFI pointer to keep the memory the string is in alive
|
167
|
+
@ident_pointer = FFI::MemoryPointer.new(@ident.size + 1)
|
168
|
+
@ident_pointer.write_string(@ident)
|
169
|
+
|
170
|
+
Foreign.open(@ident_pointer, opt, fac)
|
171
|
+
|
172
|
+
@open = true
|
173
|
+
|
174
|
+
# Calling set_mask twice is the standard way to set the 'default' mask
|
175
|
+
self.mask = @mask_before_reopen || Foreign.set_mask(0)
|
176
|
+
|
177
|
+
if block_given?
|
178
|
+
begin
|
179
|
+
yield self
|
180
|
+
ensure
|
181
|
+
close
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
self
|
186
|
+
end
|
187
|
+
|
188
|
+
def self.reopen(*args, &block)
|
189
|
+
@mask_before_reopen = mask
|
190
|
+
close
|
191
|
+
open(*args, &block)
|
192
|
+
end
|
193
|
+
|
194
|
+
class << self
|
195
|
+
alias_method :open!, :reopen
|
196
|
+
end
|
197
|
+
|
198
|
+
##
|
199
|
+
# Is it open?
|
200
|
+
def self.opened?
|
201
|
+
@open
|
202
|
+
end
|
203
|
+
|
204
|
+
##
|
205
|
+
# Close the log
|
206
|
+
# close will raise an error if it is already closed
|
207
|
+
def self.close
|
208
|
+
raise "Syslog not opened" unless @open
|
209
|
+
|
210
|
+
Foreign.close
|
211
|
+
@ident = nil
|
212
|
+
@options = @facility = @mask = nil;
|
213
|
+
@open = false
|
214
|
+
end
|
215
|
+
|
216
|
+
##
|
217
|
+
# log(Syslog::LOG_CRIT, "The %s is falling!", "sky")
|
218
|
+
#
|
219
|
+
# Doesn't take any platform specific printf statements
|
220
|
+
# logs things to $stderr
|
221
|
+
# log(Syslog::LOG_CRIT, "Welcome, %s, to my %s!", "leethaxxor", "lavratory")
|
222
|
+
def self.log(pri, format, *args)
|
223
|
+
raise "Syslog must be opened before write" unless @open
|
224
|
+
|
225
|
+
pri = Rubinius::Type.coerce_to(pri, Fixnum, :to_i)
|
226
|
+
|
227
|
+
message = StringValue(format) % args
|
228
|
+
Foreign.write(pri, "%s", message)
|
229
|
+
end
|
230
|
+
|
231
|
+
##
|
232
|
+
# handy little shortcut for LOG_EMERG as the priority
|
233
|
+
def self.emerg(*args);
|
234
|
+
log(LOG_EMERG, *args)
|
235
|
+
end
|
236
|
+
|
237
|
+
##
|
238
|
+
# handy little shortcut for LOG_ALERT as the priority
|
239
|
+
def self.alert(*args)
|
240
|
+
log(LOG_ALERT, *args)
|
241
|
+
end
|
242
|
+
|
243
|
+
##
|
244
|
+
# handy little shortcut for LOG_ERR as the priority
|
245
|
+
def self.err(*args)
|
246
|
+
log(LOG_ERR, *args)
|
247
|
+
end
|
248
|
+
|
249
|
+
##
|
250
|
+
# handy little shortcut for LOG_CRIT as the priority
|
251
|
+
def self.crit(*args)
|
252
|
+
log(LOG_CRIT, *args)
|
253
|
+
end
|
254
|
+
|
255
|
+
##
|
256
|
+
# handy little shortcut for LOG_WARNING as the priority
|
257
|
+
def self.warning(*args)
|
258
|
+
log(LOG_WARNING, *args)
|
259
|
+
end
|
260
|
+
|
261
|
+
##
|
262
|
+
# handy little shortcut for LOG_NOTICE as the priority
|
263
|
+
def self.notice(*args)
|
264
|
+
log(LOG_NOTICE, *args)
|
265
|
+
end
|
266
|
+
|
267
|
+
##
|
268
|
+
# handy little shortcut for LOG_INFO as the priority
|
269
|
+
def self.info(*args)
|
270
|
+
log(LOG_INFO, *args)
|
271
|
+
end
|
272
|
+
|
273
|
+
##
|
274
|
+
# handy little shortcut for LOG_DEBUG as the priority
|
275
|
+
def self.debug(*args)
|
276
|
+
log(LOG_DEBUG, *args)
|
277
|
+
end
|
278
|
+
|
279
|
+
def self.LOG_MASK(pri)
|
280
|
+
Constants.LOG_MASK(pri)
|
281
|
+
end
|
282
|
+
|
283
|
+
##
|
284
|
+
# LOG_UPTO(pri)
|
285
|
+
# HACK copied from macro
|
286
|
+
# Creates a mask for all priorities up to pri.
|
287
|
+
def self.LOG_UPTO(pri)
|
288
|
+
Constants.LOG_UPTO(pri)
|
289
|
+
end
|
290
|
+
|
291
|
+
def self.inspect
|
292
|
+
if @open
|
293
|
+
"#<%s: opened=true, ident=\"%s\", options=%d, facility=%d, mask=%d>" %
|
294
|
+
[self.name, @ident, @options, @facility, @mask]
|
295
|
+
else
|
296
|
+
"#<#{self.name}: opened=false>"
|
297
|
+
end
|
298
|
+
end
|
299
|
+
|
300
|
+
##
|
301
|
+
# Syslog.instance # => Syslog
|
302
|
+
# Returns the Syslog module
|
303
|
+
def self.instance
|
304
|
+
self
|
305
|
+
end
|
306
|
+
end
|
307
|
+
|
data/lib/syslog.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "rubysl/syslog"
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require './lib/rubysl/syslog/version'
|
3
|
+
|
4
|
+
Gem::Specification.new do |spec|
|
5
|
+
spec.name = "rubysl-syslog"
|
6
|
+
spec.version = RubySL::Syslog::VERSION
|
7
|
+
spec.authors = ["Brian Shirai"]
|
8
|
+
spec.email = ["brixen@gmail.com"]
|
9
|
+
spec.description = %q{Ruby standard library syslog.}
|
10
|
+
spec.summary = %q{Ruby standard library syslog.}
|
11
|
+
spec.homepage = "https://github.com/rubysl/rubysl-syslog"
|
12
|
+
spec.license = "BSD"
|
13
|
+
|
14
|
+
spec.files = `git ls-files`.split($/)
|
15
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
16
|
+
spec.extensions = ["lib/rubysl/syslog/extconf.rb"]
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.required_ruby_version = "~> 1.8.7"
|
21
|
+
|
22
|
+
spec.add_runtime_dependency "ffi2-generators", "~> 0.1"
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
spec.add_development_dependency "mspec", "~> 1.5"
|
27
|
+
spec.add_development_dependency "rubysl-prettyprint", "~> 1.0"
|
28
|
+
end
|