rubysl-syslog 2.0.1 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +10 -9
- data/lib/rubysl/syslog/version.rb +1 -1
- data/lib/syslog/logger.rb +208 -0
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bfebde7dcce150345a9455b71f9704eef695d9dd
|
4
|
+
data.tar.gz: 1307cccdf46e9a8f62f5b7188b0ac7f20568c13c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 94a117ef9961ac3aaaa0a1b747f273771b0eaa9b1ee760769a3a6bfc81d351cb684d20c3e3534a866485e52d0b74642b1960ae5d8d9f6dc2a2ba3c7be04fd191
|
7
|
+
data.tar.gz: a85cbefaf15ca5c869ef4eec24d263ba7a841ead120d53cea2289914f34b03bef5b44062cd7ac588d058d5eb014258975e120200a66ae405b65cc5270d586d6b
|
data/.travis.yml
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
language: ruby
|
2
|
-
before_install:
|
3
|
-
- rvm use $RVM --install --binary --fuzzy
|
4
|
-
- gem update --system
|
5
|
-
- gem --version
|
6
|
-
- gem install rubysl-bundler
|
7
|
-
- gem install rubysl-rake
|
8
|
-
- rake
|
9
2
|
env:
|
10
|
-
-
|
11
|
-
script:
|
3
|
+
- RUBYLIB=lib:.
|
4
|
+
script: mspec spec
|
5
|
+
branches:
|
6
|
+
only:
|
7
|
+
- 1.0
|
8
|
+
- 2.0
|
9
|
+
rvm:
|
10
|
+
- 2.1.0
|
11
|
+
- rbx-2
|
12
|
+
|
@@ -0,0 +1,208 @@
|
|
1
|
+
require 'syslog'
|
2
|
+
require 'logger'
|
3
|
+
|
4
|
+
##
|
5
|
+
# Syslog::Logger is a Logger work-alike that logs via syslog instead of to a
|
6
|
+
# file. You can use Syslog::Logger to aggregate logs between multiple
|
7
|
+
# machines.
|
8
|
+
#
|
9
|
+
# By default, Syslog::Logger uses the program name 'ruby', but this can be
|
10
|
+
# changed via the first argument to Syslog::Logger.new.
|
11
|
+
#
|
12
|
+
# NOTE! You can only set the Syslog::Logger program name when you initialize
|
13
|
+
# Syslog::Logger for the first time. This is a limitation of the way
|
14
|
+
# Syslog::Logger uses syslog (and in some ways, a limitation of the way
|
15
|
+
# syslog(3) works). Attempts to change Syslog::Logger's program name after
|
16
|
+
# the first initialization will be ignored.
|
17
|
+
#
|
18
|
+
# === Example
|
19
|
+
#
|
20
|
+
# The following will log to syslogd on your local machine:
|
21
|
+
#
|
22
|
+
# require 'syslog/logger'
|
23
|
+
#
|
24
|
+
# log = Syslog::Logger.new 'my_program'
|
25
|
+
# log.info 'this line will be logged via syslog(3)'
|
26
|
+
#
|
27
|
+
# Also the facility may be set to specify the facility level which will be used:
|
28
|
+
#
|
29
|
+
# log.info 'this line will be logged using Syslog default facility level'
|
30
|
+
#
|
31
|
+
# log_local1 = Syslog::Logger.new 'my_program', Syslog::LOG_LOCAL1
|
32
|
+
# log_local1.info 'this line will be logged using local1 facility level'
|
33
|
+
#
|
34
|
+
#
|
35
|
+
# You may need to perform some syslog.conf setup first. For a BSD machine add
|
36
|
+
# the following lines to /etc/syslog.conf:
|
37
|
+
#
|
38
|
+
# !my_program
|
39
|
+
# *.* /var/log/my_program.log
|
40
|
+
#
|
41
|
+
# Then touch /var/log/my_program.log and signal syslogd with a HUP
|
42
|
+
# (killall -HUP syslogd, on FreeBSD).
|
43
|
+
#
|
44
|
+
# If you wish to have logs automatically roll over and archive, see the
|
45
|
+
# newsyslog.conf(5) and newsyslog(8) man pages.
|
46
|
+
|
47
|
+
class Syslog::Logger
|
48
|
+
# Default formatter for log messages.
|
49
|
+
class Formatter
|
50
|
+
def call severity, time, progname, msg
|
51
|
+
clean msg
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
##
|
57
|
+
# Clean up messages so they're nice and pretty.
|
58
|
+
|
59
|
+
def clean message
|
60
|
+
message = message.to_s.strip
|
61
|
+
message.gsub!(/\e\[[0-9;]*m/, '') # remove useless ansi color codes
|
62
|
+
return message
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
##
|
67
|
+
# The version of Syslog::Logger you are using.
|
68
|
+
|
69
|
+
VERSION = '2.0'
|
70
|
+
|
71
|
+
##
|
72
|
+
# Maps Logger warning types to syslog(3) warning types.
|
73
|
+
#
|
74
|
+
# Messages from Ruby applications are not considered as critical as messages
|
75
|
+
# from other system daemons using syslog(3), so most messages are reduced by
|
76
|
+
# one level. For example, a fatal message for Ruby's Logger is considered
|
77
|
+
# an error for syslog(3).
|
78
|
+
|
79
|
+
LEVEL_MAP = {
|
80
|
+
::Logger::UNKNOWN => Syslog::LOG_ALERT,
|
81
|
+
::Logger::FATAL => Syslog::LOG_ERR,
|
82
|
+
::Logger::ERROR => Syslog::LOG_WARNING,
|
83
|
+
::Logger::WARN => Syslog::LOG_NOTICE,
|
84
|
+
::Logger::INFO => Syslog::LOG_INFO,
|
85
|
+
::Logger::DEBUG => Syslog::LOG_DEBUG,
|
86
|
+
}
|
87
|
+
|
88
|
+
##
|
89
|
+
# Returns the internal Syslog object that is initialized when the
|
90
|
+
# first instance is created.
|
91
|
+
|
92
|
+
def self.syslog
|
93
|
+
@@syslog
|
94
|
+
end
|
95
|
+
|
96
|
+
##
|
97
|
+
# Specifies the internal Syslog object to be used.
|
98
|
+
|
99
|
+
def self.syslog= syslog
|
100
|
+
@@syslog = syslog
|
101
|
+
end
|
102
|
+
|
103
|
+
##
|
104
|
+
# Builds a methods for level +meth+.
|
105
|
+
|
106
|
+
def self.make_methods meth
|
107
|
+
level = ::Logger.const_get(meth.upcase)
|
108
|
+
eval <<-EOM, nil, __FILE__, __LINE__ + 1
|
109
|
+
def #{meth}(message = nil, &block)
|
110
|
+
add(#{level}, message, &block)
|
111
|
+
end
|
112
|
+
|
113
|
+
def #{meth}?
|
114
|
+
@level <= #{level}
|
115
|
+
end
|
116
|
+
EOM
|
117
|
+
end
|
118
|
+
|
119
|
+
##
|
120
|
+
# :method: unknown
|
121
|
+
#
|
122
|
+
# Logs a +message+ at the unknown (syslog alert) log level, or logs the
|
123
|
+
# message returned from the block.
|
124
|
+
|
125
|
+
##
|
126
|
+
# :method: fatal
|
127
|
+
#
|
128
|
+
# Logs a +message+ at the fatal (syslog err) log level, or logs the message
|
129
|
+
# returned from the block.
|
130
|
+
|
131
|
+
##
|
132
|
+
# :method: error
|
133
|
+
#
|
134
|
+
# Logs a +message+ at the error (syslog warning) log level, or logs the
|
135
|
+
# message returned from the block.
|
136
|
+
|
137
|
+
##
|
138
|
+
# :method: warn
|
139
|
+
#
|
140
|
+
# Logs a +message+ at the warn (syslog notice) log level, or logs the
|
141
|
+
# message returned from the block.
|
142
|
+
|
143
|
+
##
|
144
|
+
# :method: info
|
145
|
+
#
|
146
|
+
# Logs a +message+ at the info (syslog info) log level, or logs the message
|
147
|
+
# returned from the block.
|
148
|
+
|
149
|
+
##
|
150
|
+
# :method: debug
|
151
|
+
#
|
152
|
+
# Logs a +message+ at the debug (syslog debug) log level, or logs the
|
153
|
+
# message returned from the block.
|
154
|
+
|
155
|
+
Logger::Severity::constants.each do |severity|
|
156
|
+
make_methods severity.downcase
|
157
|
+
end
|
158
|
+
|
159
|
+
##
|
160
|
+
# Log level for Logger compatibility.
|
161
|
+
|
162
|
+
attr_accessor :level
|
163
|
+
|
164
|
+
# Logging formatter, as a +Proc+ that will take four arguments and
|
165
|
+
# return the formatted message. The arguments are:
|
166
|
+
#
|
167
|
+
# +severity+:: The Severity of the log message.
|
168
|
+
# +time+:: A Time instance representing when the message was logged.
|
169
|
+
# +progname+:: The #progname configured, or passed to the logger method.
|
170
|
+
# +msg+:: The _Object_ the user passed to the log message; not necessarily a
|
171
|
+
# String.
|
172
|
+
#
|
173
|
+
# The block should return an Object that can be written to the logging
|
174
|
+
# device via +write+. The default formatter is used when no formatter is
|
175
|
+
# set.
|
176
|
+
attr_accessor :formatter
|
177
|
+
|
178
|
+
##
|
179
|
+
# The facility argument is used to specify what type of program is logging the message.
|
180
|
+
|
181
|
+
attr_accessor :facility
|
182
|
+
|
183
|
+
##
|
184
|
+
# Fills in variables for Logger compatibility. If this is the first
|
185
|
+
# instance of Syslog::Logger, +program_name+ may be set to change the logged
|
186
|
+
# program name. The +facility+ may be set to specify the facility level which will be used.
|
187
|
+
#
|
188
|
+
# Due to the way syslog works, only one program name may be chosen.
|
189
|
+
|
190
|
+
def initialize program_name = 'ruby', facility = nil
|
191
|
+
@level = ::Logger::DEBUG
|
192
|
+
@formatter = Formatter.new
|
193
|
+
|
194
|
+
@@syslog ||= Syslog.open(program_name)
|
195
|
+
|
196
|
+
@facility = (facility || @@syslog.facility)
|
197
|
+
end
|
198
|
+
|
199
|
+
##
|
200
|
+
# Almost duplicates Logger#add. +progname+ is ignored.
|
201
|
+
|
202
|
+
def add severity, message = nil, progname = nil, &block
|
203
|
+
severity ||= ::Logger::UNKNOWN
|
204
|
+
@level <= severity and
|
205
|
+
@@syslog.log( (LEVEL_MAP[severity] | @facility), '%s', formatter.call(severity, Time.now, progname, (message || block.call)) )
|
206
|
+
true
|
207
|
+
end
|
208
|
+
end
|
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.0
|
4
|
+
version: 2.1.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:
|
11
|
+
date: 2014-11-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ffi2-generators
|
@@ -99,6 +99,7 @@ files:
|
|
99
99
|
- lib/rubysl/syslog/syslog.rb.ffi
|
100
100
|
- lib/rubysl/syslog/version.rb
|
101
101
|
- lib/syslog.rb
|
102
|
+
- lib/syslog/logger.rb
|
102
103
|
- rubysl-syslog.gemspec
|
103
104
|
- spec/alert_spec.rb
|
104
105
|
- spec/close_spec.rb
|
@@ -142,7 +143,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
142
143
|
version: '0'
|
143
144
|
requirements: []
|
144
145
|
rubyforge_project:
|
145
|
-
rubygems_version: 2.
|
146
|
+
rubygems_version: 2.2.2
|
146
147
|
signing_key:
|
147
148
|
specification_version: 4
|
148
149
|
summary: Ruby standard library syslog.
|
@@ -169,4 +170,3 @@ test_files:
|
|
169
170
|
- spec/shared/log.rb
|
170
171
|
- spec/shared/reopen.rb
|
171
172
|
- spec/warning_spec.rb
|
172
|
-
has_rdoc:
|