rubysl-syslog 2.1.0 → 3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bfebde7dcce150345a9455b71f9704eef695d9dd
4
- data.tar.gz: 1307cccdf46e9a8f62f5b7188b0ac7f20568c13c
3
+ metadata.gz: c74d6cb5e7117f5e623643b2777dba721ad72ca3
4
+ data.tar.gz: 0468a141e697a94a2e960172ac949fe741081c89
5
5
  SHA512:
6
- metadata.gz: 94a117ef9961ac3aaaa0a1b747f273771b0eaa9b1ee760769a3a6bfc81d351cb684d20c3e3534a866485e52d0b74642b1960ae5d8d9f6dc2a2ba3c7be04fd191
7
- data.tar.gz: a85cbefaf15ca5c869ef4eec24d263ba7a841ead120d53cea2289914f34b03bef5b44062cd7ac588d058d5eb014258975e120200a66ae405b65cc5270d586d6b
6
+ metadata.gz: 7c969d2513897aca2a02f4b221d10ccdda4a7040ef4be895e8b7debc4744191c72ce18106b51b026b8b886380febad86ba4f18146d07c6ec0771a082edc97b56
7
+ data.tar.gz: 9e28b3378ff68547905ca647e61d6e0fc8e5e29095a952b44ec5021a0e7dd53a9a0573530378f58eed3c949d79810b0132c2c913da6e33266f8dcf73524a2b25
@@ -0,0 +1,56 @@
1
+ Ruby is copyrighted free software by Yukihiro Matsumoto <matz@netlab.jp>.
2
+ You can redistribute it and/or modify it under either the terms of the
3
+ 2-clause BSDL (see the file BSDL), or the conditions below:
4
+
5
+ 1. You may make and give away verbatim copies of the source form of the
6
+ software without restriction, provided that you duplicate all of the
7
+ original copyright notices and associated disclaimers.
8
+
9
+ 2. You may modify your copy of the software in any way, provided that
10
+ you do at least ONE of the following:
11
+
12
+ a) place your modifications in the Public Domain or otherwise
13
+ make them Freely Available, such as by posting said
14
+ modifications to Usenet or an equivalent medium, or by allowing
15
+ the author to include your modifications in the software.
16
+
17
+ b) use the modified software only within your corporation or
18
+ organization.
19
+
20
+ c) give non-standard binaries non-standard names, with
21
+ instructions on where to get the original software distribution.
22
+
23
+ d) make other distribution arrangements with the author.
24
+
25
+ 3. You may distribute the software in object code or binary form,
26
+ provided that you do at least ONE of the following:
27
+
28
+ a) distribute the binaries and library files of the software,
29
+ together with instructions (in the manual page or equivalent)
30
+ on where to get the original distribution.
31
+
32
+ b) accompany the distribution with the machine-readable source of
33
+ the software.
34
+
35
+ c) give non-standard binaries non-standard names, with
36
+ instructions on where to get the original software distribution.
37
+
38
+ d) make other distribution arrangements with the author.
39
+
40
+ 4. You may modify and include the part of the software into any other
41
+ software (possibly commercial). But some files in the distribution
42
+ are not written by the author, so that they are not under these terms.
43
+
44
+ For the list of those files and their copying conditions, see the
45
+ file LEGAL.
46
+
47
+ 5. The scripts and library files supplied as input to or produced as
48
+ output from the software do not automatically fall under the
49
+ copyright of the software, but belong to whomever generated them,
50
+ and may be sold commercially, and may be aggregated with this
51
+ software.
52
+
53
+ 6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
54
+ IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
55
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
56
+ PURPOSE.
@@ -1,2 +1,2 @@
1
- require "rubysl/syslog/syslog"
1
+ require "syslog"
2
2
  require "rubysl/syslog/version"
@@ -1,5 +1,5 @@
1
1
  module RubySL
2
2
  module Syslog
3
- VERSION = "2.1.0"
3
+ VERSION = "3.0"
4
4
  end
5
5
  end
@@ -1 +1,303 @@
1
- require "rubysl/syslog"
1
+ # This file is generated FFI::FileProcessor from syslog.rb.ffi.
2
+
3
+ # Created by Ari Brown on 2008-02-23.
4
+ # For rubinius. All pwnage reserved.
5
+ #
6
+
7
+ # ** Syslog(Module)
8
+
9
+ # Included Modules: Syslog::Constants
10
+
11
+ # require 'syslog'
12
+
13
+ # A Simple wrapper for the UNIX syslog system calls that might be handy
14
+ # if you're writing a server in Ruby. For the details of the syslog(8)
15
+ # architecture and constants, see the syslog(3) manual page of your
16
+ # platform.
17
+
18
+ module Syslog
19
+ FFI = Rubinius::FFI
20
+
21
+ module Constants
22
+ LOG_ALERT = Rubinius::Config['rbx.platform.syslog.LOG_ALERT']
23
+ LOG_AUTH = Rubinius::Config['rbx.platform.syslog.LOG_AUTH']
24
+ LOG_AUTHPRIV = Rubinius::Config['rbx.platform.syslog.LOG_AUTHPRIV']
25
+ LOG_CONS = Rubinius::Config['rbx.platform.syslog.LOG_CONS']
26
+ LOG_CONSOLE = Rubinius::Config['rbx.platform.syslog.LOG_CONSOLE']
27
+ LOG_CRIT = Rubinius::Config['rbx.platform.syslog.LOG_CRIT']
28
+ LOG_CRON = Rubinius::Config['rbx.platform.syslog.LOG_CRON']
29
+ LOG_DAEMON = Rubinius::Config['rbx.platform.syslog.LOG_DAEMON']
30
+ LOG_DEBUG = Rubinius::Config['rbx.platform.syslog.LOG_DEBUG']
31
+ LOG_EMERG = Rubinius::Config['rbx.platform.syslog.LOG_EMERG']
32
+ LOG_ERR = Rubinius::Config['rbx.platform.syslog.LOG_ERR']
33
+ LOG_FTP = Rubinius::Config['rbx.platform.syslog.LOG_FTP']
34
+ LOG_INFO = Rubinius::Config['rbx.platform.syslog.LOG_INFO']
35
+ LOG_KERN = Rubinius::Config['rbx.platform.syslog.LOG_KERN']
36
+ LOG_LOCAL0 = Rubinius::Config['rbx.platform.syslog.LOG_LOCAL0']
37
+ LOG_LOCAL1 = Rubinius::Config['rbx.platform.syslog.LOG_LOCAL1']
38
+ LOG_LOCAL2 = Rubinius::Config['rbx.platform.syslog.LOG_LOCAL2']
39
+ LOG_LOCAL3 = Rubinius::Config['rbx.platform.syslog.LOG_LOCAL3']
40
+ LOG_LOCAL4 = Rubinius::Config['rbx.platform.syslog.LOG_LOCAL4']
41
+ LOG_LOCAL5 = Rubinius::Config['rbx.platform.syslog.LOG_LOCAL5']
42
+ LOG_LOCAL6 = Rubinius::Config['rbx.platform.syslog.LOG_LOCAL6']
43
+ LOG_LOCAL7 = Rubinius::Config['rbx.platform.syslog.LOG_LOCAL7']
44
+ LOG_LPR = Rubinius::Config['rbx.platform.syslog.LOG_LPR']
45
+ LOG_MAIL = Rubinius::Config['rbx.platform.syslog.LOG_MAIL']
46
+ LOG_NDELAY = Rubinius::Config['rbx.platform.syslog.LOG_NDELAY']
47
+ LOG_NEWS = Rubinius::Config['rbx.platform.syslog.LOG_NEWS']
48
+ LOG_NOTICE = Rubinius::Config['rbx.platform.syslog.LOG_NOTICE']
49
+ LOG_NOWAIT = Rubinius::Config['rbx.platform.syslog.LOG_NOWAIT']
50
+ LOG_NTP = Rubinius::Config['rbx.platform.syslog.LOG_NTP']
51
+ LOG_ODELAY = Rubinius::Config['rbx.platform.syslog.LOG_ODELAY']
52
+ LOG_PERROR = Rubinius::Config['rbx.platform.syslog.LOG_PERROR']
53
+ LOG_PID = Rubinius::Config['rbx.platform.syslog.LOG_PID']
54
+ LOG_SECURITY = Rubinius::Config['rbx.platform.syslog.LOG_SECURITY']
55
+ LOG_SYSLOG = Rubinius::Config['rbx.platform.syslog.LOG_SYSLOG']
56
+ LOG_USER = Rubinius::Config['rbx.platform.syslog.LOG_USER']
57
+ LOG_UUCP = Rubinius::Config['rbx.platform.syslog.LOG_UUCP']
58
+ LOG_WARNING = Rubinius::Config['rbx.platform.syslog.LOG_WARNING']
59
+
60
+ ##
61
+ # LOG_MASK(pri)
62
+ #
63
+ # HACK copied from macro
64
+ # Creates a mask for one priority.
65
+ def self.LOG_MASK(pri)
66
+ 1 << pri
67
+ end
68
+
69
+ ##
70
+ # LOG_UPTO(pri)
71
+ # HACK copied from macro
72
+ # Creates a mask for all priorities up to pri.
73
+ def self.LOG_UPTO(pri)
74
+ (1 << ((pri)+1)) - 1
75
+ end
76
+ end
77
+
78
+ include Constants
79
+
80
+ module Foreign
81
+ extend FFI::Library
82
+
83
+ # methods
84
+ attach_function :open, "openlog", [:pointer, :int, :int], :void
85
+ attach_function :close, "closelog", [], :void
86
+ attach_function :write, "syslog", [:int, :string, :string], :void
87
+ attach_function :set_mask, "setlogmask", [:int], :int
88
+ end
89
+
90
+ # Not open by default.
91
+ #
92
+ # Yes, a normal ivar, on Syslog, the module.
93
+ @open = false
94
+
95
+ ##
96
+ # returns the ident of the last open call
97
+ def self.ident
98
+ @open ? @ident : nil
99
+ end
100
+
101
+ ##
102
+ # returns the options of the last open call
103
+ def self.options
104
+ @open ? @options : nil
105
+ end
106
+
107
+ ##
108
+ # returns the facility of the last open call
109
+ def self.facility
110
+ @open ? @facility : nil
111
+ end
112
+
113
+ ##
114
+ # mask
115
+ # mask=(mask)
116
+ #
117
+ # Returns or sets the log priority mask. The value of the mask
118
+ # is persistent and will not be reset by Syslog::open or
119
+ # Syslog::close.
120
+ #
121
+ # Example:
122
+ # Syslog.mask = Syslog::LOG_UPTO(Syslog::LOG_ERR)
123
+ def self.mask=(mask)
124
+ unless @open
125
+ raise RuntimeError, "must open syslog before setting log mask"
126
+ end
127
+
128
+ @mask_before_reopen = nil
129
+
130
+ @mask = Rubinius::Type.coerce_to mask, Fixnum, :to_int
131
+
132
+ Foreign.set_mask(@mask)
133
+ end
134
+
135
+ def self.mask
136
+ @open ? @mask : nil
137
+ end
138
+
139
+ ##
140
+ # open(ident = $0, logopt = Syslog::LOG_PID | Syslog::LOG_CONS, facility = Syslog::LOG_USER) [{ |syslog| ... }]
141
+ #
142
+ # Opens syslog with the given options and returns the module
143
+ # itself. If a block is given, calls it with an argument of
144
+ # itself. If syslog is already opened, raises RuntimeError.
145
+ #
146
+ # Examples:
147
+ # Syslog.open('ftpd', Syslog::LOG_PID | Syslog::LOG_NDELAY, Syslog::LOG_FTP)
148
+ # open!(ident = $0, logopt = Syslog::LOG_PID | Syslog::LOG_CONS, facility = Syslog::LOG_USER)
149
+ # reopen(ident = $0, logopt = Syslog::LOG_PID | Syslog::LOG_CONS, facility = Syslog::LOG_USER)
150
+ def self.open(ident=nil, opt=nil, fac=nil)
151
+ raise "Syslog already open" unless not @open
152
+
153
+ ident ||= $0
154
+ opt ||= Constants::LOG_PID | Constants::LOG_CONS
155
+ fac ||= Constants::LOG_USER
156
+
157
+ @ident = ident
158
+ @options = opt
159
+ @facility = fac
160
+
161
+ # syslog rereads the string everytime syslog() is called, so we have to use
162
+ # an FFI pointer to keep the memory the string is in alive
163
+ @ident_pointer = FFI::MemoryPointer.new(@ident.size + 1)
164
+ @ident_pointer.write_string(@ident)
165
+
166
+ Foreign.open(@ident_pointer, opt, fac)
167
+
168
+ @open = true
169
+
170
+ # Calling set_mask twice is the standard way to set the 'default' mask
171
+ self.mask = @mask_before_reopen || Foreign.set_mask(0)
172
+
173
+ if block_given?
174
+ begin
175
+ yield self
176
+ ensure
177
+ close
178
+ end
179
+ end
180
+
181
+ self
182
+ end
183
+
184
+ def self.reopen(*args, &block)
185
+ @mask_before_reopen = mask
186
+ close
187
+ open(*args, &block)
188
+ end
189
+
190
+ class << self
191
+ alias_method :open!, :reopen
192
+ end
193
+
194
+ ##
195
+ # Is it open?
196
+ def self.opened?
197
+ @open
198
+ end
199
+
200
+ ##
201
+ # Close the log
202
+ # close will raise an error if it is already closed
203
+ def self.close
204
+ raise "Syslog not opened" unless @open
205
+
206
+ Foreign.close
207
+ @ident = nil
208
+ @options = @facility = @mask = nil;
209
+ @open = false
210
+ end
211
+
212
+ ##
213
+ # log(Syslog::LOG_CRIT, "The %s is falling!", "sky")
214
+ #
215
+ # Doesn't take any platform specific printf statements
216
+ # logs things to $stderr
217
+ # log(Syslog::LOG_CRIT, "Welcome, %s, to my %s!", "leethaxxor", "lavratory")
218
+ def self.log(pri, format, *args)
219
+ raise "Syslog must be opened before write" unless @open
220
+
221
+ pri = Rubinius::Type.coerce_to(pri, Fixnum, :to_i)
222
+
223
+ message = StringValue(format) % args
224
+ Foreign.write(pri, "%s", message)
225
+ end
226
+
227
+ ##
228
+ # handy little shortcut for LOG_EMERG as the priority
229
+ def self.emerg(*args);
230
+ log(LOG_EMERG, *args)
231
+ end
232
+
233
+ ##
234
+ # handy little shortcut for LOG_ALERT as the priority
235
+ def self.alert(*args)
236
+ log(LOG_ALERT, *args)
237
+ end
238
+
239
+ ##
240
+ # handy little shortcut for LOG_ERR as the priority
241
+ def self.err(*args)
242
+ log(LOG_ERR, *args)
243
+ end
244
+
245
+ ##
246
+ # handy little shortcut for LOG_CRIT as the priority
247
+ def self.crit(*args)
248
+ log(LOG_CRIT, *args)
249
+ end
250
+
251
+ ##
252
+ # handy little shortcut for LOG_WARNING as the priority
253
+ def self.warning(*args)
254
+ log(LOG_WARNING, *args)
255
+ end
256
+
257
+ ##
258
+ # handy little shortcut for LOG_NOTICE as the priority
259
+ def self.notice(*args)
260
+ log(LOG_NOTICE, *args)
261
+ end
262
+
263
+ ##
264
+ # handy little shortcut for LOG_INFO as the priority
265
+ def self.info(*args)
266
+ log(LOG_INFO, *args)
267
+ end
268
+
269
+ ##
270
+ # handy little shortcut for LOG_DEBUG as the priority
271
+ def self.debug(*args)
272
+ log(LOG_DEBUG, *args)
273
+ end
274
+
275
+ def self.LOG_MASK(pri)
276
+ Constants.LOG_MASK(pri)
277
+ end
278
+
279
+ ##
280
+ # LOG_UPTO(pri)
281
+ # HACK copied from macro
282
+ # Creates a mask for all priorities up to pri.
283
+ def self.LOG_UPTO(pri)
284
+ Constants.LOG_UPTO(pri)
285
+ end
286
+
287
+ def self.inspect
288
+ if @open
289
+ "#<%s: opened=true, ident=\"%s\", options=%d, facility=%d, mask=%d>" %
290
+ [self.name, @ident, @options, @facility, @mask]
291
+ else
292
+ "#<#{self.name}: opened=false>"
293
+ end
294
+ end
295
+
296
+ ##
297
+ # Syslog.instance # => Syslog
298
+ # Returns the Syslog module
299
+ def self.instance
300
+ self
301
+ end
302
+ end
303
+
@@ -13,7 +13,7 @@ Gem::Specification.new do |spec|
13
13
 
14
14
  spec.files = `git ls-files`.split($/)
15
15
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
16
- spec.extensions = ["lib/rubysl/syslog/extconf.rb"]
16
+ spec.extensions = []
17
17
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
18
  spec.require_paths = ["lib"]
19
19
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubysl-syslog
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: '3.0'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Shirai
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-20 00:00:00.000000000 Z
11
+ date: 2017-11-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi2-generators
@@ -84,19 +84,17 @@ description: Ruby standard library syslog.
84
84
  email:
85
85
  - brixen@gmail.com
86
86
  executables: []
87
- extensions:
88
- - lib/rubysl/syslog/extconf.rb
87
+ extensions: []
89
88
  extra_rdoc_files: []
90
89
  files:
91
90
  - ".gitignore"
92
91
  - ".travis.yml"
93
92
  - Gemfile
94
93
  - LICENSE
94
+ - MRI_LICENSE
95
95
  - README.md
96
96
  - Rakefile
97
97
  - lib/rubysl/syslog.rb
98
- - lib/rubysl/syslog/extconf.rb
99
- - lib/rubysl/syslog/syslog.rb.ffi
100
98
  - lib/rubysl/syslog/version.rb
101
99
  - lib/syslog.rb
102
100
  - lib/syslog/logger.rb
@@ -143,7 +141,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
143
141
  version: '0'
144
142
  requirements: []
145
143
  rubyforge_project:
146
- rubygems_version: 2.2.2
144
+ rubygems_version: 2.5.1
147
145
  signing_key:
148
146
  specification_version: 4
149
147
  summary: Ruby standard library syslog.
@@ -1,15 +0,0 @@
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
@@ -1,307 +0,0 @@
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
-