syslog 0.1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ddb6ed968d877f312af6f7f03878492b0a90488d5bc3c0262d8655405520cd83
4
+ data.tar.gz: d3d22a728f8144fdc97dba1a637e8abf212366f3b6e928d4b02849c876517542
5
+ SHA512:
6
+ metadata.gz: 47bd387f3709fb5331e33b4f89c1e605eb18bfe20ab4fc3a4921198c5bcaa9db20f032f03c13d5d6feb02b38b1d76807ee28db0c676ef3488d8482264f611a1f
7
+ data.tar.gz: d18c20fe78f8bf9fa967a3717dc72beb653069f015d4fc737b3e85dfe058b5cb59c5f82a4068786d0b57315f3e18e673b40dc63846fa6decacce6207c0ea82bb
@@ -0,0 +1,24 @@
1
+ name: build
2
+
3
+ on: [push, pull_request]
4
+
5
+ jobs:
6
+ build:
7
+ name: build (${{ matrix.ruby }} / ${{ matrix.os }})
8
+ strategy:
9
+ matrix:
10
+ ruby: [ 2.7, 2.6, 2.5, head ]
11
+ os: [ ubuntu-latest, macos-latest ]
12
+ runs-on: ${{ matrix.os }}
13
+ steps:
14
+ - uses: actions/checkout@master
15
+ - name: Set up Ruby
16
+ uses: ruby/setup-ruby@v1
17
+ with:
18
+ ruby-version: ${{ matrix.ruby }}
19
+ - name: Install dependencies
20
+ run: |
21
+ gem install bundler --no-document
22
+ bundle install
23
+ - name: Run test
24
+ run: rake compile test
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ *.bundle
10
+ *.dll
11
+ *.so
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "rake"
4
+ gem "rake-compiler"
5
+ gem "test-unit"
@@ -0,0 +1,22 @@
1
+ Copyright (C) 1993-2013 Yukihiro Matsumoto. All rights reserved.
2
+
3
+ Redistribution and use in source and binary forms, with or without
4
+ modification, are permitted provided that the following conditions
5
+ are met:
6
+ 1. Redistributions of source code must retain the above copyright
7
+ notice, this list of conditions and the following disclaimer.
8
+ 2. Redistributions in binary form must reproduce the above copyright
9
+ notice, this list of conditions and the following disclaimer in the
10
+ documentation and/or other materials provided with the distribution.
11
+
12
+ THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
13
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
14
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
15
+ ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
16
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
17
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
18
+ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
19
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
20
+ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
21
+ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
22
+ SUCH DAMAGE.
@@ -0,0 +1,40 @@
1
+ # Syslog
2
+
3
+ A Simple wrapper for the UNIX syslog system calls that might be handy
4
+ if you're writing a server in Ruby. For the details of the syslog(8)
5
+ architecture and constants, see the syslog(3) manual page of your
6
+ platform.
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'syslog'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle install
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install syslog
23
+
24
+ ## Usage
25
+
26
+ ```ruby
27
+ Syslog.open("webrick", Syslog::LOG_PID,
28
+ Syslog::LOG_DAEMON | Syslog::LOG_LOCAL3)
29
+ ```
30
+
31
+ ## Development
32
+
33
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
34
+
35
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
36
+
37
+ ## Contributing
38
+
39
+ Bug reports and pull requests are welcome on GitHub at https://github.com/ruby/syslog.
40
+
@@ -0,0 +1,12 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/test_*.rb"]
8
+ end
9
+
10
+ require 'rake/extensiontask'
11
+ Rake::ExtensionTask.new("syslog")
12
+ task :default => :test
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "syslog"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: false
2
+ # $RoughId: extconf.rb,v 1.3 2001/11/24 17:49:26 knu Exp $
3
+ # $Id$
4
+
5
+ require 'mkmf'
6
+
7
+ have_library("log") # for Android
8
+
9
+ have_header("syslog.h") &&
10
+ have_func("openlog") &&
11
+ have_func("setlogmask") &&
12
+ create_makefile("syslog")
13
+
@@ -0,0 +1,588 @@
1
+ /*
2
+ * UNIX Syslog extension for Ruby
3
+ * Amos Gouaux, University of Texas at Dallas
4
+ * <amos+ruby@utdallas.edu>
5
+ * Documented by mathew <meta@pobox.com>
6
+ *
7
+ * $RoughId: syslog.c,v 1.21 2002/02/25 12:21:17 knu Exp $
8
+ * $Id$
9
+ */
10
+
11
+ #include "ruby/ruby.h"
12
+ #include "ruby/util.h"
13
+ #include <syslog.h>
14
+
15
+ /* Syslog class */
16
+ static VALUE mSyslog;
17
+ /*
18
+ * Module holding all Syslog constants. See Syslog::log and
19
+ * Syslog::open for constant descriptions.
20
+ */
21
+ static VALUE mSyslogConstants;
22
+ /* Module holding Syslog option constants */
23
+ static VALUE mSyslogOption;
24
+ /* Module holding Syslog facility constants */
25
+ static VALUE mSyslogFacility;
26
+ /* Module holding Syslog level constants */
27
+ static VALUE mSyslogLevel;
28
+ /* Module holding Syslog utility macros */
29
+ static VALUE mSyslogMacros;
30
+
31
+ static const char *syslog_ident = NULL;
32
+ static int syslog_options = -1, syslog_facility = -1, syslog_mask = -1;
33
+ static int syslog_opened = 0;
34
+
35
+ /* Package helper routines */
36
+ static void syslog_write(int pri, int argc, VALUE *argv)
37
+ {
38
+ VALUE str;
39
+
40
+ if (argc < 1) {
41
+ rb_raise(rb_eArgError, "no log message supplied");
42
+ }
43
+
44
+ if (!syslog_opened) {
45
+ rb_raise(rb_eRuntimeError, "must open syslog before write");
46
+ }
47
+
48
+ str = rb_f_sprintf(argc, argv);
49
+
50
+ syslog(pri, "%s", RSTRING_PTR(str));
51
+ }
52
+
53
+ /* Closes the syslog facility.
54
+ * Raises a runtime exception if it is not open.
55
+ */
56
+ static VALUE mSyslog_close(VALUE self)
57
+ {
58
+ if (!syslog_opened) {
59
+ rb_raise(rb_eRuntimeError, "syslog not opened");
60
+ }
61
+
62
+ closelog();
63
+
64
+ xfree((void *)syslog_ident);
65
+ syslog_ident = NULL;
66
+ syslog_options = syslog_facility = syslog_mask = -1;
67
+ syslog_opened = 0;
68
+
69
+ return Qnil;
70
+ }
71
+
72
+ /* call-seq:
73
+ * open(ident, options, facility) => syslog
74
+ *
75
+ * :yields: syslog
76
+ *
77
+ * Open the syslog facility.
78
+ * Raises a runtime exception if it is already open.
79
+ *
80
+ * Can be called with or without a code block. If called with a block, the
81
+ * Syslog object created is passed to the block.
82
+ *
83
+ * If the syslog is already open, raises a RuntimeError.
84
+ *
85
+ * +ident+ is a String which identifies the calling program.
86
+ *
87
+ * +options+ is the logical OR of any of the following:
88
+ *
89
+ * LOG_CONS:: If there is an error while sending to the system logger,
90
+ * write directly to the console instead.
91
+ *
92
+ * LOG_NDELAY:: Open the connection now, rather than waiting for the first
93
+ * message to be written.
94
+ *
95
+ * LOG_NOWAIT:: Don't wait for any child processes created while logging
96
+ * messages. (Has no effect on Linux.)
97
+ *
98
+ * LOG_ODELAY:: Opposite of LOG_NDELAY; wait until a message is sent before
99
+ * opening the connection. (This is the default.)
100
+ *
101
+ * LOG_PERROR:: Print the message to stderr as well as sending it to syslog.
102
+ * (Not in POSIX.1-2001.)
103
+ *
104
+ * LOG_PID:: Include the current process ID with each message.
105
+ *
106
+ * +facility+ describes the type of program opening the syslog, and is
107
+ * the logical OR of any of the following which are defined for the host OS:
108
+ *
109
+ * LOG_AUTH:: Security or authorization. Deprecated, use LOG_AUTHPRIV
110
+ * instead.
111
+ *
112
+ * LOG_AUTHPRIV:: Security or authorization messages which should be kept
113
+ * private.
114
+ *
115
+ * LOG_CONSOLE:: System console message.
116
+ *
117
+ * LOG_CRON:: System task scheduler (cron or at).
118
+ *
119
+ * LOG_DAEMON:: A system daemon which has no facility value of its own.
120
+ *
121
+ * LOG_FTP:: An FTP server.
122
+ *
123
+ * LOG_KERN:: A kernel message (not sendable by user processes, so not of
124
+ * much use to Ruby, but listed here for completeness).
125
+ *
126
+ * LOG_LPR:: Line printer subsystem.
127
+ *
128
+ * LOG_MAIL:: Mail delivery or transport subsystem.
129
+ *
130
+ * LOG_NEWS:: Usenet news system.
131
+ *
132
+ * LOG_NTP:: Network Time Protocol server.
133
+ *
134
+ * LOG_SECURITY:: General security message.
135
+ *
136
+ * LOG_SYSLOG:: Messages generated internally by syslog.
137
+ *
138
+ * LOG_USER:: Generic user-level message.
139
+ *
140
+ * LOG_UUCP:: UUCP subsystem.
141
+ *
142
+ * LOG_LOCAL0 to LOG_LOCAL7:: Locally-defined facilities.
143
+ *
144
+ * Example:
145
+ *
146
+ * Syslog.open("webrick", Syslog::LOG_PID,
147
+ * Syslog::LOG_DAEMON | Syslog::LOG_LOCAL3)
148
+ *
149
+ */
150
+ static VALUE mSyslog_open(int argc, VALUE *argv, VALUE self)
151
+ {
152
+ VALUE ident, opt, fac;
153
+ const char *ident_ptr;
154
+
155
+ if (syslog_opened) {
156
+ rb_raise(rb_eRuntimeError, "syslog already open");
157
+ }
158
+
159
+ rb_scan_args(argc, argv, "03", &ident, &opt, &fac);
160
+
161
+ if (NIL_P(ident)) {
162
+ ident = rb_gv_get("$0");
163
+ }
164
+ ident_ptr = StringValueCStr(ident);
165
+ syslog_ident = strdup(ident_ptr);
166
+
167
+ if (NIL_P(opt)) {
168
+ syslog_options = LOG_PID | LOG_CONS;
169
+ } else {
170
+ syslog_options = NUM2INT(opt);
171
+ }
172
+
173
+ if (NIL_P(fac)) {
174
+ syslog_facility = LOG_USER;
175
+ } else {
176
+ syslog_facility = NUM2INT(fac);
177
+ }
178
+
179
+ openlog(syslog_ident, syslog_options, syslog_facility);
180
+
181
+ syslog_opened = 1;
182
+
183
+ setlogmask(syslog_mask = setlogmask(0));
184
+
185
+ /* be like File.new.open {...} */
186
+ if (rb_block_given_p()) {
187
+ rb_ensure(rb_yield, self, mSyslog_close, self);
188
+ }
189
+
190
+ return self;
191
+ }
192
+
193
+ /* call-seq:
194
+ * reopen(ident, options, facility) => syslog
195
+ *
196
+ * :yields: syslog
197
+ *
198
+ * Closes and then reopens the syslog.
199
+ *
200
+ * Arguments are the same as for open().
201
+ */
202
+ static VALUE mSyslog_reopen(int argc, VALUE *argv, VALUE self)
203
+ {
204
+ mSyslog_close(self);
205
+
206
+ return mSyslog_open(argc, argv, self);
207
+ }
208
+
209
+ /* call-seq:
210
+ * opened?
211
+ *
212
+ * Returns true if the syslog is open.
213
+ */
214
+ static VALUE mSyslog_isopen(VALUE self)
215
+ {
216
+ return syslog_opened ? Qtrue : Qfalse;
217
+ }
218
+
219
+ /* Returns the identity string used in the last call to open()
220
+ */
221
+ static VALUE mSyslog_ident(VALUE self)
222
+ {
223
+ return syslog_opened ? rb_str_new2(syslog_ident) : Qnil;
224
+ }
225
+
226
+ /* Returns the options bitmask used in the last call to open()
227
+ */
228
+ static VALUE mSyslog_options(VALUE self)
229
+ {
230
+ return syslog_opened ? INT2NUM(syslog_options) : Qnil;
231
+ }
232
+
233
+ /* Returns the facility number used in the last call to open()
234
+ */
235
+ static VALUE mSyslog_facility(VALUE self)
236
+ {
237
+ return syslog_opened ? INT2NUM(syslog_facility) : Qnil;
238
+ }
239
+
240
+ /* Returns the log priority mask in effect. The mask is not reset by opening
241
+ * or closing syslog.
242
+ */
243
+ static VALUE mSyslog_get_mask(VALUE self)
244
+ {
245
+ return syslog_opened ? INT2NUM(syslog_mask) : Qnil;
246
+ }
247
+
248
+ /* call-seq:
249
+ * mask=(priority_mask)
250
+ *
251
+ * Sets the log priority mask. A method LOG_UPTO is defined to make it easier
252
+ * to set mask values. Example:
253
+ *
254
+ * Syslog.mask = Syslog::LOG_UPTO(Syslog::LOG_ERR)
255
+ *
256
+ * Alternatively, specific priorities can be selected and added together using
257
+ * binary OR. Example:
258
+ *
259
+ * Syslog.mask = Syslog::LOG_MASK(Syslog::LOG_ERR) | Syslog::LOG_MASK(Syslog::LOG_CRIT)
260
+ *
261
+ * The priority mask persists through calls to open() and close().
262
+ */
263
+ static VALUE mSyslog_set_mask(VALUE self, VALUE mask)
264
+ {
265
+ if (!syslog_opened) {
266
+ rb_raise(rb_eRuntimeError, "must open syslog before setting log mask");
267
+ }
268
+
269
+ setlogmask(syslog_mask = NUM2INT(mask));
270
+
271
+ return mask;
272
+ }
273
+
274
+ /* call-seq:
275
+ * log(priority, format_string, *format_args)
276
+ *
277
+ * Log a message with the specified priority. Example:
278
+ *
279
+ * Syslog.log(Syslog::LOG_CRIT, "Out of disk space")
280
+ * Syslog.log(Syslog::LOG_CRIT, "User %s logged in", ENV['USER'])
281
+ *
282
+ * The priority levels, in descending order, are:
283
+ *
284
+ * LOG_EMERG:: System is unusable
285
+ * LOG_ALERT:: Action needs to be taken immediately
286
+ * LOG_CRIT:: A critical condition has occurred
287
+ * LOG_ERR:: An error occurred
288
+ * LOG_WARNING:: Warning of a possible problem
289
+ * LOG_NOTICE:: A normal but significant condition occurred
290
+ * LOG_INFO:: Informational message
291
+ * LOG_DEBUG:: Debugging information
292
+ *
293
+ * Each priority level also has a shortcut method that logs with it's named priority.
294
+ * As an example, the two following statements would produce the same result:
295
+ *
296
+ * Syslog.log(Syslog::LOG_ALERT, "Out of memory")
297
+ * Syslog.alert("Out of memory")
298
+ *
299
+ */
300
+ static VALUE mSyslog_log(int argc, VALUE *argv, VALUE self)
301
+ {
302
+ VALUE pri;
303
+
304
+ rb_check_arity(argc, 2, UNLIMITED_ARGUMENTS);
305
+
306
+ argc--;
307
+ pri = *argv++;
308
+
309
+ if (!FIXNUM_P(pri)) {
310
+ rb_raise(rb_eTypeError, "type mismatch: %"PRIsVALUE" given", rb_obj_class(pri));
311
+ }
312
+
313
+ syslog_write(FIX2INT(pri), argc, argv);
314
+
315
+ return self;
316
+ }
317
+
318
+ /* Returns an inspect() string summarizing the object state.
319
+ */
320
+ static VALUE mSyslog_inspect(VALUE self)
321
+ {
322
+ Check_Type(self, T_MODULE);
323
+
324
+ if (!syslog_opened)
325
+ return rb_sprintf("<#%"PRIsVALUE": opened=false>", self);
326
+
327
+ return rb_sprintf("<#%"PRIsVALUE": opened=true, ident=\"%s\", options=%d, facility=%d, mask=%d>",
328
+ self,
329
+ syslog_ident,
330
+ syslog_options,
331
+ syslog_facility,
332
+ syslog_mask);
333
+ }
334
+
335
+ /* Returns self, for backward compatibility.
336
+ */
337
+ static VALUE mSyslog_instance(VALUE self)
338
+ {
339
+ return self;
340
+ }
341
+
342
+ #define define_syslog_shortcut_method(pri, name) \
343
+ static VALUE mSyslog_##name(int argc, VALUE *argv, VALUE self) \
344
+ { \
345
+ syslog_write((pri), argc, argv); \
346
+ \
347
+ return self; \
348
+ }
349
+
350
+ #ifdef LOG_EMERG
351
+ define_syslog_shortcut_method(LOG_EMERG, emerg)
352
+ #endif
353
+ #ifdef LOG_ALERT
354
+ define_syslog_shortcut_method(LOG_ALERT, alert)
355
+ #endif
356
+ #ifdef LOG_CRIT
357
+ define_syslog_shortcut_method(LOG_CRIT, crit)
358
+ #endif
359
+ #ifdef LOG_ERR
360
+ define_syslog_shortcut_method(LOG_ERR, err)
361
+ #endif
362
+ #ifdef LOG_WARNING
363
+ define_syslog_shortcut_method(LOG_WARNING, warning)
364
+ #endif
365
+ #ifdef LOG_NOTICE
366
+ define_syslog_shortcut_method(LOG_NOTICE, notice)
367
+ #endif
368
+ #ifdef LOG_INFO
369
+ define_syslog_shortcut_method(LOG_INFO, info)
370
+ #endif
371
+ #ifdef LOG_DEBUG
372
+ define_syslog_shortcut_method(LOG_DEBUG, debug)
373
+ #endif
374
+
375
+ /* call-seq:
376
+ * LOG_MASK(priority_level) => priority_mask
377
+ *
378
+ * Generates a mask bit for a priority level. See #mask=
379
+ */
380
+ static VALUE mSyslogMacros_LOG_MASK(VALUE mod, VALUE pri)
381
+ {
382
+ return INT2FIX(LOG_MASK(NUM2INT(pri)));
383
+ }
384
+
385
+ /* call-seq:
386
+ * LOG_UPTO(priority_level) => priority_mask
387
+ *
388
+ * Generates a mask value for priority levels at or below the level specified.
389
+ * See #mask=
390
+ */
391
+ static VALUE mSyslogMacros_LOG_UPTO(VALUE mod, VALUE pri)
392
+ {
393
+ return INT2FIX(LOG_UPTO(NUM2INT(pri)));
394
+ }
395
+
396
+ static VALUE mSyslogMacros_included(VALUE mod, VALUE target)
397
+ {
398
+ rb_extend_object(target, mSyslogMacros);
399
+ return mod;
400
+ }
401
+
402
+ /* The syslog package provides a Ruby interface to the POSIX system logging
403
+ * facility.
404
+ *
405
+ * Syslog messages are typically passed to a central logging daemon.
406
+ * The daemon may filter them; route them into different files (usually
407
+ * found under /var/log); place them in SQL databases; forward
408
+ * them to centralized logging servers via TCP or UDP; or even alert the
409
+ * system administrator via email, pager or text message.
410
+ *
411
+ * Unlike application-level logging via Logger or Log4r, syslog is designed
412
+ * to allow secure tamper-proof logging.
413
+ *
414
+ * The syslog protocol is standardized in RFC 5424.
415
+ */
416
+ void Init_syslog(void)
417
+ {
418
+ #undef rb_intern
419
+ mSyslog = rb_define_module("Syslog");
420
+
421
+ mSyslogConstants = rb_define_module_under(mSyslog, "Constants");
422
+
423
+ mSyslogOption = rb_define_module_under(mSyslog, "Option");
424
+ mSyslogFacility = rb_define_module_under(mSyslog, "Facility");
425
+ mSyslogLevel = rb_define_module_under(mSyslog, "Level");
426
+ mSyslogMacros = rb_define_module_under(mSyslog, "Macros");
427
+
428
+ rb_define_module_function(mSyslog, "open", mSyslog_open, -1);
429
+ rb_define_module_function(mSyslog, "reopen", mSyslog_reopen, -1);
430
+ rb_define_module_function(mSyslog, "open!", mSyslog_reopen, -1);
431
+ rb_define_module_function(mSyslog, "opened?", mSyslog_isopen, 0);
432
+
433
+ rb_define_module_function(mSyslog, "ident", mSyslog_ident, 0);
434
+ rb_define_module_function(mSyslog, "options", mSyslog_options, 0);
435
+ rb_define_module_function(mSyslog, "facility", mSyslog_facility, 0);
436
+
437
+ rb_define_module_function(mSyslog, "log", mSyslog_log, -1);
438
+ rb_define_module_function(mSyslog, "close", mSyslog_close, 0);
439
+ rb_define_module_function(mSyslog, "mask", mSyslog_get_mask, 0);
440
+ rb_define_module_function(mSyslog, "mask=", mSyslog_set_mask, 1);
441
+
442
+ rb_define_singleton_method(mSyslog, "inspect", mSyslog_inspect, 0);
443
+ rb_define_module_function(mSyslog, "instance", mSyslog_instance, 0);
444
+
445
+ /* Syslog options */
446
+
447
+ #define rb_define_syslog_option(c) \
448
+ rb_define_const(mSyslogOption, #c, INT2NUM(c))
449
+
450
+ #ifdef LOG_PID
451
+ rb_define_syslog_option(LOG_PID);
452
+ #endif
453
+ #ifdef LOG_CONS
454
+ rb_define_syslog_option(LOG_CONS);
455
+ #endif
456
+ #ifdef LOG_ODELAY
457
+ rb_define_syslog_option(LOG_ODELAY); /* deprecated */
458
+ #endif
459
+ #ifdef LOG_NDELAY
460
+ rb_define_syslog_option(LOG_NDELAY);
461
+ #endif
462
+ #ifdef LOG_NOWAIT
463
+ rb_define_syslog_option(LOG_NOWAIT); /* deprecated */
464
+ #endif
465
+ #ifdef LOG_PERROR
466
+ rb_define_syslog_option(LOG_PERROR);
467
+ #endif
468
+
469
+ /* Syslog facilities */
470
+
471
+ #define rb_define_syslog_facility(c) \
472
+ rb_define_const(mSyslogFacility, #c, INT2NUM(c))
473
+
474
+ #ifdef LOG_AUTH
475
+ rb_define_syslog_facility(LOG_AUTH);
476
+ #endif
477
+ #ifdef LOG_AUTHPRIV
478
+ rb_define_syslog_facility(LOG_AUTHPRIV);
479
+ #endif
480
+ #ifdef LOG_CONSOLE
481
+ rb_define_syslog_facility(LOG_CONSOLE);
482
+ #endif
483
+ #ifdef LOG_CRON
484
+ rb_define_syslog_facility(LOG_CRON);
485
+ #endif
486
+ #ifdef LOG_DAEMON
487
+ rb_define_syslog_facility(LOG_DAEMON);
488
+ #endif
489
+ #ifdef LOG_FTP
490
+ rb_define_syslog_facility(LOG_FTP);
491
+ #endif
492
+ #ifdef LOG_KERN
493
+ rb_define_syslog_facility(LOG_KERN);
494
+ #endif
495
+ #ifdef LOG_LPR
496
+ rb_define_syslog_facility(LOG_LPR);
497
+ #endif
498
+ #ifdef LOG_MAIL
499
+ rb_define_syslog_facility(LOG_MAIL);
500
+ #endif
501
+ #ifdef LOG_NEWS
502
+ rb_define_syslog_facility(LOG_NEWS);
503
+ #endif
504
+ #ifdef LOG_NTP
505
+ rb_define_syslog_facility(LOG_NTP);
506
+ #endif
507
+ #ifdef LOG_SECURITY
508
+ rb_define_syslog_facility(LOG_SECURITY);
509
+ #endif
510
+ #ifdef LOG_SYSLOG
511
+ rb_define_syslog_facility(LOG_SYSLOG);
512
+ #endif
513
+ #ifdef LOG_USER
514
+ rb_define_syslog_facility(LOG_USER);
515
+ #endif
516
+ #ifdef LOG_UUCP
517
+ rb_define_syslog_facility(LOG_UUCP);
518
+ #endif
519
+ #ifdef LOG_LOCAL0
520
+ rb_define_syslog_facility(LOG_LOCAL0);
521
+ #endif
522
+ #ifdef LOG_LOCAL1
523
+ rb_define_syslog_facility(LOG_LOCAL1);
524
+ #endif
525
+ #ifdef LOG_LOCAL2
526
+ rb_define_syslog_facility(LOG_LOCAL2);
527
+ #endif
528
+ #ifdef LOG_LOCAL3
529
+ rb_define_syslog_facility(LOG_LOCAL3);
530
+ #endif
531
+ #ifdef LOG_LOCAL4
532
+ rb_define_syslog_facility(LOG_LOCAL4);
533
+ #endif
534
+ #ifdef LOG_LOCAL5
535
+ rb_define_syslog_facility(LOG_LOCAL5);
536
+ #endif
537
+ #ifdef LOG_LOCAL6
538
+ rb_define_syslog_facility(LOG_LOCAL6);
539
+ #endif
540
+ #ifdef LOG_LOCAL7
541
+ rb_define_syslog_facility(LOG_LOCAL7);
542
+ #endif
543
+
544
+ /* Syslog levels and the shortcut methods */
545
+
546
+ #define rb_define_syslog_level(c, m) \
547
+ rb_define_const(mSyslogLevel, #c, INT2NUM(c)); \
548
+ rb_define_module_function(mSyslog, #m, mSyslog_##m, -1)
549
+
550
+ #ifdef LOG_EMERG
551
+ rb_define_syslog_level(LOG_EMERG, emerg);
552
+ #endif
553
+ #ifdef LOG_ALERT
554
+ rb_define_syslog_level(LOG_ALERT, alert);
555
+ #endif
556
+ #ifdef LOG_CRIT
557
+ rb_define_syslog_level(LOG_CRIT, crit);
558
+ #endif
559
+ #ifdef LOG_ERR
560
+ rb_define_syslog_level(LOG_ERR, err);
561
+ #endif
562
+ #ifdef LOG_WARNING
563
+ rb_define_syslog_level(LOG_WARNING, warning);
564
+ #endif
565
+ #ifdef LOG_NOTICE
566
+ rb_define_syslog_level(LOG_NOTICE, notice);
567
+ #endif
568
+ #ifdef LOG_INFO
569
+ rb_define_syslog_level(LOG_INFO, info);
570
+ #endif
571
+ #ifdef LOG_DEBUG
572
+ rb_define_syslog_level(LOG_DEBUG, debug);
573
+ #endif
574
+
575
+ /* Syslog macros */
576
+
577
+ rb_define_method(mSyslogMacros, "LOG_MASK", mSyslogMacros_LOG_MASK, 1);
578
+ rb_define_method(mSyslogMacros, "LOG_UPTO", mSyslogMacros_LOG_UPTO, 1);
579
+ rb_define_singleton_method(mSyslogMacros, "included", mSyslogMacros_included, 1);
580
+
581
+ rb_include_module(mSyslogConstants, mSyslogOption);
582
+ rb_include_module(mSyslogConstants, mSyslogFacility);
583
+ rb_include_module(mSyslogConstants, mSyslogLevel);
584
+ rb_funcall(mSyslogConstants, rb_intern("include"), 1, mSyslogMacros);
585
+
586
+ rb_define_singleton_method(mSyslogConstants, "included", mSyslogMacros_included, 1);
587
+ rb_funcall(mSyslog, rb_intern("include"), 1, mSyslogConstants);
588
+ }
@@ -0,0 +1,124 @@
1
+ .\" syslog.txt - -*- Indented-Text -*-
2
+ $RoughId: syslog.txt,v 1.18 2002/02/25 08:20:14 knu Exp $
3
+ $Id$
4
+
5
+ UNIX Syslog extension for Ruby
6
+ Amos Gouaux, University of Texas at Dallas
7
+ <amos+ruby@utdallas.edu>
8
+ &
9
+ Akinori MUSHA
10
+ <knu@iDaemons.org>
11
+
12
+ Contact:
13
+ - Akinori MUSHA <knu@iDaemons.org> (current maintainer)
14
+
15
+ ** Syslog(Module)
16
+
17
+ Included Modules: Syslog::Constants
18
+
19
+ require 'syslog'
20
+
21
+ A Simple wrapper for the UNIX syslog system calls that might be handy
22
+ if you're writing a server in Ruby. For the details of the syslog(8)
23
+ architecture and constants, see the syslog(3) manual page of your
24
+ platform.
25
+
26
+ Module Methods:
27
+
28
+ open(ident = $0, logopt = Syslog::LOG_PID | Syslog::LOG_CONS,
29
+ facility = Syslog::LOG_USER) [{ |syslog| ... }]
30
+
31
+ Opens syslog with the given options and returns the module
32
+ itself. If a block is given, calls it with an argument of
33
+ itself. If syslog is already opened, raises RuntimeError.
34
+
35
+ Example:
36
+ Syslog.open('ftpd', Syslog::LOG_PID | Syslog::LOG_NDELAY,
37
+ Syslog::LOG_FTP)
38
+
39
+ open!(ident = $0, logopt = Syslog::LOG_PID | Syslog::LOG_CONS,
40
+ facility = Syslog::LOG_USER)
41
+ reopen(ident = $0, logopt = Syslog::LOG_PID | Syslog::LOG_CONS,
42
+ facility = Syslog::LOG_USER)
43
+
44
+ Same as open, but does a close first.
45
+
46
+ opened?
47
+
48
+ Returns true if syslog opened, otherwise false.
49
+
50
+ ident
51
+ options
52
+ facility
53
+
54
+ Returns the parameters given in the last open, respectively.
55
+ Every call of Syslog::open resets these values.
56
+
57
+ log(pri, message, ...)
58
+
59
+ Writes message to syslog.
60
+
61
+ Example:
62
+ Syslog.log(Syslog::LOG_CRIT, "the sky is falling in %d seconds!", 10)
63
+
64
+ crit(message, ...)
65
+ emerg(message, ...)
66
+ alert(message, ...)
67
+ err(message, ...)
68
+ warning(message, ...)
69
+ notice(message, ...)
70
+ info(message, ...)
71
+ debug(message, ...)
72
+
73
+ These are shortcut methods of Syslog::log(). The lineup may
74
+ vary depending on what priorities are defined on your system.
75
+
76
+ Example:
77
+ Syslog.crit("the sky is falling in %d seconds!", 5)
78
+
79
+ mask
80
+ mask=(mask)
81
+
82
+ Returns or sets the log priority mask. The value of the mask
83
+ is persistent and will not be reset by Syslog::open or
84
+ Syslog::close.
85
+
86
+ Example:
87
+ Syslog.mask = Syslog::LOG_UPTO(Syslog::LOG_ERR)
88
+
89
+ close
90
+
91
+ Closes syslog.
92
+
93
+ inspect
94
+
95
+ Returns the "inspect" string of the Syslog module.
96
+
97
+ instance
98
+
99
+ Returns the module itself. (Just for backward compatibility)
100
+
101
+ LOG_MASK(pri)
102
+
103
+ Creates a mask for one priority.
104
+
105
+ LOG_UPTO(pri)
106
+
107
+ Creates a mask for all priorities up to pri.
108
+
109
+ ** Syslog::Constants(Module)
110
+
111
+ require 'syslog'
112
+ include Syslog::Constants
113
+
114
+ This module includes the LOG_* constants available on the system.
115
+
116
+ Module Methods:
117
+
118
+ LOG_MASK(pri)
119
+
120
+ Creates a mask for one priority.
121
+
122
+ LOG_UPTO(pri)
123
+
124
+ Creates a mask for all priorities up to pri.
@@ -0,0 +1,209 @@
1
+ # frozen_string_literal: false
2
+ require 'syslog'
3
+ require 'logger'
4
+
5
+ ##
6
+ # Syslog::Logger is a Logger work-alike that logs via syslog instead of to a
7
+ # file. You can use Syslog::Logger to aggregate logs between multiple
8
+ # machines.
9
+ #
10
+ # By default, Syslog::Logger uses the program name 'ruby', but this can be
11
+ # changed via the first argument to Syslog::Logger.new.
12
+ #
13
+ # NOTE! You can only set the Syslog::Logger program name when you initialize
14
+ # Syslog::Logger for the first time. This is a limitation of the way
15
+ # Syslog::Logger uses syslog (and in some ways, a limitation of the way
16
+ # syslog(3) works). Attempts to change Syslog::Logger's program name after
17
+ # the first initialization will be ignored.
18
+ #
19
+ # === Example
20
+ #
21
+ # The following will log to syslogd on your local machine:
22
+ #
23
+ # require 'syslog/logger'
24
+ #
25
+ # log = Syslog::Logger.new 'my_program'
26
+ # log.info 'this line will be logged via syslog(3)'
27
+ #
28
+ # Also the facility may be set to specify the facility level which will be used:
29
+ #
30
+ # log.info 'this line will be logged using Syslog default facility level'
31
+ #
32
+ # log_local1 = Syslog::Logger.new 'my_program', Syslog::LOG_LOCAL1
33
+ # log_local1.info 'this line will be logged using local1 facility level'
34
+ #
35
+ #
36
+ # You may need to perform some syslog.conf setup first. For a BSD machine add
37
+ # the following lines to /etc/syslog.conf:
38
+ #
39
+ # !my_program
40
+ # *.* /var/log/my_program.log
41
+ #
42
+ # Then touch /var/log/my_program.log and signal syslogd with a HUP
43
+ # (killall -HUP syslogd, on FreeBSD).
44
+ #
45
+ # If you wish to have logs automatically roll over and archive, see the
46
+ # newsyslog.conf(5) and newsyslog(8) man pages.
47
+
48
+ class Syslog::Logger
49
+ # Default formatter for log messages.
50
+ class Formatter
51
+ def call severity, time, progname, msg
52
+ clean msg
53
+ end
54
+
55
+ private
56
+
57
+ ##
58
+ # Clean up messages so they're nice and pretty.
59
+
60
+ def clean message
61
+ message = message.to_s.strip
62
+ message.gsub!(/\e\[[0-9;]*m/, '') # remove useless ansi color codes
63
+ return message
64
+ end
65
+ end
66
+
67
+ ##
68
+ # The version of Syslog::Logger you are using.
69
+
70
+ VERSION = '2.1.0'
71
+
72
+ ##
73
+ # Maps Logger warning types to syslog(3) warning types.
74
+ #
75
+ # Messages from Ruby applications are not considered as critical as messages
76
+ # from other system daemons using syslog(3), so most messages are reduced by
77
+ # one level. For example, a fatal message for Ruby's Logger is considered
78
+ # an error for syslog(3).
79
+
80
+ LEVEL_MAP = {
81
+ ::Logger::UNKNOWN => Syslog::LOG_ALERT,
82
+ ::Logger::FATAL => Syslog::LOG_ERR,
83
+ ::Logger::ERROR => Syslog::LOG_WARNING,
84
+ ::Logger::WARN => Syslog::LOG_NOTICE,
85
+ ::Logger::INFO => Syslog::LOG_INFO,
86
+ ::Logger::DEBUG => Syslog::LOG_DEBUG,
87
+ }
88
+
89
+ ##
90
+ # Returns the internal Syslog object that is initialized when the
91
+ # first instance is created.
92
+
93
+ def self.syslog
94
+ @@syslog
95
+ end
96
+
97
+ ##
98
+ # Specifies the internal Syslog object to be used.
99
+
100
+ def self.syslog= syslog
101
+ @@syslog = syslog
102
+ end
103
+
104
+ ##
105
+ # Builds a methods for level +meth+.
106
+
107
+ def self.make_methods meth
108
+ level = ::Logger.const_get(meth.upcase)
109
+ eval <<-EOM, nil, __FILE__, __LINE__ + 1
110
+ def #{meth}(message = nil, &block)
111
+ add(#{level}, message, &block)
112
+ end
113
+
114
+ def #{meth}?
115
+ level <= #{level}
116
+ end
117
+ EOM
118
+ end
119
+
120
+ ##
121
+ # :method: unknown
122
+ #
123
+ # Logs a +message+ at the unknown (syslog alert) log level, or logs the
124
+ # message returned from the block.
125
+
126
+ ##
127
+ # :method: fatal
128
+ #
129
+ # Logs a +message+ at the fatal (syslog err) log level, or logs the message
130
+ # returned from the block.
131
+
132
+ ##
133
+ # :method: error
134
+ #
135
+ # Logs a +message+ at the error (syslog warning) log level, or logs the
136
+ # message returned from the block.
137
+
138
+ ##
139
+ # :method: warn
140
+ #
141
+ # Logs a +message+ at the warn (syslog notice) log level, or logs the
142
+ # message returned from the block.
143
+
144
+ ##
145
+ # :method: info
146
+ #
147
+ # Logs a +message+ at the info (syslog info) log level, or logs the message
148
+ # returned from the block.
149
+
150
+ ##
151
+ # :method: debug
152
+ #
153
+ # Logs a +message+ at the debug (syslog debug) log level, or logs the
154
+ # message returned from the block.
155
+
156
+ Logger::Severity::constants.each do |severity|
157
+ make_methods severity.downcase
158
+ end
159
+
160
+ ##
161
+ # Log level for Logger compatibility.
162
+
163
+ attr_accessor :level
164
+
165
+ # Logging formatter, as a +Proc+ that will take four arguments and
166
+ # return the formatted message. The arguments are:
167
+ #
168
+ # +severity+:: The Severity of the log message.
169
+ # +time+:: A Time instance representing when the message was logged.
170
+ # +progname+:: The #progname configured, or passed to the logger method.
171
+ # +msg+:: The _Object_ the user passed to the log message; not necessarily a
172
+ # String.
173
+ #
174
+ # The block should return an Object that can be written to the logging
175
+ # device via +write+. The default formatter is used when no formatter is
176
+ # set.
177
+ attr_accessor :formatter
178
+
179
+ ##
180
+ # The facility argument is used to specify what type of program is logging the message.
181
+
182
+ attr_accessor :facility
183
+
184
+ ##
185
+ # Fills in variables for Logger compatibility. If this is the first
186
+ # instance of Syslog::Logger, +program_name+ may be set to change the logged
187
+ # program name. The +facility+ may be set to specify the facility level which will be used.
188
+ #
189
+ # Due to the way syslog works, only one program name may be chosen.
190
+
191
+ def initialize program_name = 'ruby', facility = nil
192
+ @level = ::Logger::DEBUG
193
+ @formatter = Formatter.new
194
+
195
+ @@syslog ||= Syslog.open(program_name)
196
+
197
+ @facility = (facility || @@syslog.facility)
198
+ end
199
+
200
+ ##
201
+ # Almost duplicates Logger#add. +progname+ is ignored.
202
+
203
+ def add severity, message = nil, progname = nil, &block
204
+ severity ||= ::Logger::UNKNOWN
205
+ level <= severity and
206
+ @@syslog.log( (LEVEL_MAP[severity] | @facility), '%s', formatter.call(severity, Time.now, progname, (message || block.call)) )
207
+ true
208
+ end
209
+ end
@@ -0,0 +1,23 @@
1
+ Gem::Specification.new do |spec|
2
+ spec.name = "syslog"
3
+ spec.version = "0.1.0"
4
+ spec.authors = ["Akinori MUSHA"]
5
+ spec.email = ["knu@idaemons.org"]
6
+
7
+ spec.summary = %q{Ruby interface for the POSIX system logging facility.}
8
+ spec.description = %q{Ruby interface for the POSIX system logging facility.}
9
+ spec.homepage = "https://github.com/ruby/syslog"
10
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
11
+ spec.licenses = ["Ruby", "BSD-2-Clause"]
12
+
13
+ spec.metadata["homepage_uri"] = spec.homepage
14
+ spec.metadata["source_code_uri"] = spec.homepage
15
+
16
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
17
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ end
19
+ spec.extensions = ["ext/syslog/extconf.rb"]
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+ end
metadata ADDED
@@ -0,0 +1,60 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: syslog
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Akinori MUSHA
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-09-18 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Ruby interface for the POSIX system logging facility.
14
+ email:
15
+ - knu@idaemons.org
16
+ executables: []
17
+ extensions:
18
+ - ext/syslog/extconf.rb
19
+ extra_rdoc_files: []
20
+ files:
21
+ - ".github/workflows/test.yml"
22
+ - ".gitignore"
23
+ - Gemfile
24
+ - LICENSE.txt
25
+ - README.md
26
+ - Rakefile
27
+ - bin/console
28
+ - bin/setup
29
+ - ext/syslog/extconf.rb
30
+ - ext/syslog/syslog.c
31
+ - ext/syslog/syslog.txt
32
+ - lib/syslog/logger.rb
33
+ - syslog.gemspec
34
+ homepage: https://github.com/ruby/syslog
35
+ licenses:
36
+ - Ruby
37
+ - BSD-2-Clause
38
+ metadata:
39
+ homepage_uri: https://github.com/ruby/syslog
40
+ source_code_uri: https://github.com/ruby/syslog
41
+ post_install_message:
42
+ rdoc_options: []
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: 2.3.0
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ requirements: []
56
+ rubygems_version: 3.2.0.rc.1
57
+ signing_key:
58
+ specification_version: 4
59
+ summary: Ruby interface for the POSIX system logging facility.
60
+ test_files: []