logstash-logger 0.13.0 → 0.14.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: cc77de67a993f6d92e48eb51a03403545adb4a36
4
- data.tar.gz: 155105ccaa41672d379ba39f1f58891079814ef1
3
+ metadata.gz: 7d1a717987bfefa4eae1faafea2f61fcc0e3b1b5
4
+ data.tar.gz: 5f7251bf59a5a3a288d773c22b75d085f7f0ce2d
5
5
  SHA512:
6
- metadata.gz: 49065907ddd39ea7dce437da0d9e4d640667a48d056f487b23948a6a4a97bb2d8a117c6370a430b9465f739b3225a1ac8cb9419f8144928b30af78a118c18a96
7
- data.tar.gz: 945c34c855bf8f0fe36b1a40d8b6daaf72ac452590da3e8f3d74069f3fdcc41865f6926513255bd2bca91e661130dbe7ec8a1f82d5813879ca625fd9df7ee135
6
+ metadata.gz: 1bbc32714b3f38930d53f44a7164f9cfef9d15ae77d6e38c2846577c3be7a681b330097cbdc999657f37768e1f708159dec43880e84c5a9bb5d236066582f961
7
+ data.tar.gz: 2d7807cc5d58da6de21fa2319cf6c1709a28d31184246109cb85cfa2e4206f92b946e39b8f407f12fa16e73d6168daa56075433e13faeaf29b56533e24e822b5
@@ -1,3 +1,6 @@
1
+ ## 0.14.0
2
+ - Support for Syslog output. [#59](https://github.com/dwbutler/logstash-logger/pull/59)
3
+
1
4
  ## 0.13.0
2
5
  - Support for sending messages to multiple loggers. Each one can have a different formatter. [#58](https://github.com/dwbutler/logstash-logger/pull/58)
3
6
  - Fixes tagged logging support when using a custom formatter.
data/README.md CHANGED
@@ -8,7 +8,7 @@ writing to a file or syslog since logstash can receive the structured data direc
8
8
  ## Features
9
9
 
10
10
  * Can write directly to logstash over a UDP or TCP/SSL connection.
11
- * Can write to a file, Redis, a unix socket, stdout or stderr.
11
+ * Can write to a file, Redis, Kafka, a unix socket, syslog, stdout, or stderr.
12
12
  * Writes in logstash JSON format, but supports other formats as well.
13
13
  * Can write to multiple outputs.
14
14
  * Logger can take a string message, a hash, a `LogStash::Event`, an object, or a JSON string as input.
@@ -44,6 +44,7 @@ tcp_logger = LogStashLogger.new(type: :tcp, host: 'localhost', port: 5229)
44
44
  # Other types of loggers
45
45
  file_logger = LogStashLogger.new(type: :file, path: 'log/development.log', sync: true)
46
46
  unix_logger = LogStashLogger.new(type: :unix, path: '/tmp/sock')
47
+ syslog_logger = LogStashLogger.new(type: :syslog)
47
48
  redis_logger = LogStashLogger.new(type: :redis)
48
49
  kafka_logger = LogStashLogger.new(type: :kafka)
49
50
  stdout_logger = LogStashLogger.new(type: :stdout)
@@ -75,6 +76,7 @@ ruby_default_formatter_logger = LogStashLogger.new(
75
76
  )
76
77
 
77
78
  # Send messages to multiple outputs. Each output will have the same format.
79
+ # Syslog cannot be an output because it requires a separate logger.
78
80
  multi_delegating_logger = LogStashLogger.new(
79
81
  type: :multi_delegator,
80
82
  outputs: [
@@ -82,7 +84,8 @@ multi_delegating_logger = LogStashLogger.new(
82
84
  { type: :udp, host: 'localhost', port: 5228 }
83
85
  ])
84
86
 
85
- # Balance messages between several outputs
87
+ # Balance messages between several outputs.
88
+ # Works the same as multi delegator, but randomly chooses an output to send each message.
86
89
  balancer_logger = LogStashLogger.new(
87
90
  type: :balancer,
88
91
  outputs: [
@@ -92,6 +95,7 @@ balancer_logger = LogStashLogger.new(
92
95
 
93
96
  # Send messages to multiple loggers.
94
97
  # Use this if you need to send different formats to different outputs.
98
+ # If you need to log to syslog, you must use this.
95
99
  multi_logger = LogStashLogger.new(
96
100
  type: :multi_logger,
97
101
  outputs: [
@@ -305,6 +309,25 @@ config.logstash.type = :unix
305
309
  config.logstash.path = '/tmp/sock'
306
310
  ```
307
311
 
312
+ #### Syslog
313
+
314
+ If you're on Ruby 1.9, add `Syslog::Logger` v2 to your Gemfile:
315
+
316
+ gem 'SyslogLogger', '2.0'
317
+
318
+ If you're on Ruby 2+, `Syslog::Logger` is already built into the standard library.
319
+
320
+ ```ruby
321
+ # Required
322
+ config.logstash.type = :syslog
323
+
324
+ # Optional. Defaults to 'ruby'
325
+ config.logstash.program_name = 'MyApp'
326
+
327
+ # Optional default facility level. Only works in Ruby 2+
328
+ config.logstash.facility = Syslog::LOG_LOCAL0
329
+ ```
330
+
308
331
  #### Redis
309
332
 
310
333
  Add the redis gem to your Gemfile:
@@ -1,6 +1,11 @@
1
1
  require 'logger'
2
2
  require 'logstash-logger/tagged_logging'
3
3
 
4
+ autoload :Syslog, 'syslog'
5
+ module Syslog
6
+ autoload :Logger, 'syslog/logger'
7
+ end
8
+
4
9
  module LogStashLogger
5
10
  autoload :MultiLogger, 'logstash-logger/multi_logger'
6
11
 
@@ -45,20 +50,45 @@ module LogStashLogger
45
50
  end
46
51
 
47
52
  def self.build_logger(opts)
48
- case opts[:type]
53
+ formatter = Formatter.new(opts.delete(:formatter))
54
+
55
+ logger = case opts[:type]
49
56
  when :multi_logger
50
- loggers = opts[:outputs].map {|logger_opts| build_logger(logger_opts) }
51
- MultiLogger.new(loggers)
57
+ build_multi_logger(opts)
58
+ when :syslog
59
+ build_syslog_logger(opts)
52
60
  else
53
- formatter = Formatter.new(opts.delete(:formatter))
54
- device = Device.new(opts)
55
-
56
- ::Logger.new(device).tap do |logger|
57
- logger.instance_variable_set(:@device, device)
58
- logger.extend(self)
59
- logger.extend(TaggedLogging)
60
- logger.formatter = formatter
61
- end
61
+ build_default_logger(opts)
62
62
  end
63
+
64
+ logger.formatter = formatter if formatter
65
+ logger
66
+ end
67
+
68
+ private
69
+
70
+ def self.build_default_logger(opts)
71
+ device = Device.new(opts)
72
+ ::Logger.new(device).tap do |logger|
73
+ logger.instance_variable_set(:@device, device)
74
+ logger.extend(self)
75
+ logger.extend(TaggedLogging)
76
+ end
77
+ end
78
+
79
+ def self.build_multi_logger(opts)
80
+ loggers = opts[:outputs].map { |logger_opts| build_logger(logger_opts) }
81
+ MultiLogger.new(loggers)
82
+ end
83
+
84
+ def self.build_syslog_logger(opts)
85
+ logger = begin
86
+ Syslog::Logger.new(opts[:program_name], opts[:facility])
87
+ rescue ArgumentError
88
+ Syslog::Logger.new(opts[:program_name])
89
+ end
90
+
91
+ logger.extend(self)
92
+ logger.extend(TaggedLogging)
63
93
  end
64
94
  end
@@ -1,3 +1,3 @@
1
1
  module LogStashLogger
2
- VERSION = "0.13.0"
2
+ VERSION = "0.14.0"
3
3
  end
@@ -25,6 +25,10 @@ Gem::Specification.new do |gem|
25
25
  gem.add_development_dependency 'redis'
26
26
  gem.add_development_dependency 'poseidon'
27
27
 
28
+ if RUBY_VERSION < '2'
29
+ gem.add_development_dependency 'SyslogLogger'
30
+ end
31
+
28
32
  gem.add_development_dependency 'rspec', '>= 3'
29
33
  gem.add_development_dependency 'rake'
30
34
  gem.add_development_dependency 'pry'
@@ -0,0 +1,10 @@
1
+ input {
2
+ syslog {
3
+ codec => json_lines
4
+ }
5
+ }
6
+ output {
7
+ stdout {
8
+ codec => json_lines
9
+ }
10
+ }
@@ -0,0 +1,25 @@
1
+ require 'logstash-logger'
2
+
3
+ describe LogStashLogger do
4
+ context "Syslog" do
5
+ let(:program_name) { "MyApp" }
6
+ let(:facility) { Syslog::LOG_LOCAL0 }
7
+ subject { LogStashLogger.new(type: :syslog, program_name: program_name, facility: facility) }
8
+ let(:syslog) { subject.class.class_variable_get(:@@syslog) }
9
+
10
+ it { is_expected.to be_a Syslog::Logger }
11
+
12
+ it "writes formatted messages to syslog" do
13
+ expect(syslog).to receive(:log)
14
+ subject.info("test")
15
+ end
16
+
17
+ it "sets the syslog identity" do
18
+ expect(syslog.ident).to eq(program_name)
19
+ end
20
+
21
+ it "sets the default facility if supported" do
22
+ expect(subject.facility).to eq(facility) if subject.respond_to?(:facility)
23
+ end
24
+ end
25
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-logger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.0
4
+ version: 0.14.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Butler
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-07 00:00:00.000000000 Z
11
+ date: 2015-09-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: logstash-event
@@ -205,6 +205,7 @@ files:
205
205
  - samples/file.conf
206
206
  - samples/redis.conf
207
207
  - samples/ssl.conf
208
+ - samples/syslog.conf
208
209
  - samples/tcp.conf
209
210
  - samples/udp.conf
210
211
  - samples/unix.conf
@@ -233,6 +234,7 @@ files:
233
234
  - spec/multi_logger_spec.rb
234
235
  - spec/rails_spec.rb
235
236
  - spec/spec_helper.rb
237
+ - spec/syslog_spec.rb
236
238
  - spec/tagged_logging_spec.rb
237
239
  homepage: http://github.com/dwbutler/logstash-logger
238
240
  licenses:
@@ -284,4 +286,5 @@ test_files:
284
286
  - spec/multi_logger_spec.rb
285
287
  - spec/rails_spec.rb
286
288
  - spec/spec_helper.rb
289
+ - spec/syslog_spec.rb
287
290
  - spec/tagged_logging_spec.rb