sysloggly 0.3.2 → 0.4.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.
- checksums.yaml +5 -5
- data/CHANGELOG.md +3 -0
- data/lib/sysloggly.rb +11 -35
- data/lib/sysloggly/formatters/simple_formatter.rb +13 -7
- data/lib/sysloggly/formatters/syslog_formatter.rb +4 -1
- data/lib/sysloggly/logger.rb +34 -0
- data/lib/sysloggly/rails.rb +1 -4
- data/lib/sysloggly/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: cdbef2d70a52185bd9eecc6bbcc28f2ce3b94863a430ab4598151f8cf1db4e2a
|
4
|
+
data.tar.gz: fe673d581bd2ecb232c36555c70e39360bc4e4c7d1f8b6215920f50557fb9d5e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 10d5c7d1acef408121a62546122ba551dd5ae379848ef3d60689c34d625371ca9ba418ccb6acecf8be4aab6bb5fef90a1d79270eab2189c6e5d860088577dbc1
|
7
|
+
data.tar.gz: e98f897a90fbaae14d7825ac325b746da61d70cf40ff33c431c5f6b91b8bd2c0bfc73dc71aa9d2a2a85c46eddcd9c99f3b2e4e337f05fc74c20b9de0245e4255
|
data/CHANGELOG.md
CHANGED
data/lib/sysloggly.rb
CHANGED
@@ -7,13 +7,14 @@ require "sysloggly/clients/filelog"
|
|
7
7
|
require "sysloggly/clients/networklog"
|
8
8
|
require "sysloggly/formatters/simple_formatter"
|
9
9
|
require "sysloggly/formatters/syslog_formatter"
|
10
|
+
require "sysloggly/logger"
|
10
11
|
|
11
12
|
#
|
12
13
|
# Sysloggly
|
13
14
|
#
|
14
15
|
# @config [uri] only supports [udp|tcp|file]
|
15
16
|
module Sysloggly
|
16
|
-
class
|
17
|
+
class InvalidInputURL < ArgumentError; end
|
17
18
|
class UnsupportedScheme < ArgumentError; end
|
18
19
|
class UnknownFacility < ArgumentError; end
|
19
20
|
|
@@ -24,39 +25,14 @@ module Sysloggly
|
|
24
25
|
def self.configure
|
25
26
|
yield self
|
26
27
|
end
|
27
|
-
|
28
|
-
|
29
|
-
# Creates a new logger instance
|
30
|
-
#
|
31
|
-
# @return [Logger]
|
32
|
-
# @api public
|
33
|
-
def self.new(url, opts = {})
|
34
|
-
raise InputURLRequired.new unless url
|
35
|
-
|
36
|
-
begin
|
37
|
-
input_uri = URI.parse(url)
|
38
|
-
rescue URI::InvalidURIError => e
|
39
|
-
raise InputURLRequired.new("Invalid Input URL: #{url}")
|
40
|
-
end
|
41
|
-
|
42
|
-
client, formatter = nil
|
43
|
-
|
44
|
-
case input_uri.scheme
|
45
|
-
when "file"
|
46
|
-
client = Sysloggly::Clients::Filelog.new(input_uri.path)
|
47
|
-
formatter = Sysloggly::Formatters::SimpleFormatter.new(input_uri, opts)
|
48
|
-
when "udp", "tcp"
|
49
|
-
client = Sysloggly::Clients::Networklog.new(input_uri)
|
50
|
-
formatter = Sysloggly::Formatters::SyslogFormatter.new(input_uri, opts)
|
51
|
-
else
|
52
|
-
raise Sysloggly::UnsupportedScheme.new("#{input_uri.scheme} is unsupported")
|
53
|
-
end
|
54
|
-
|
55
|
-
logger = Logger.new(client)
|
56
|
-
logger.formatter = formatter
|
57
|
-
|
58
|
-
logger
|
59
|
-
end
|
60
28
|
end
|
61
29
|
|
62
|
-
|
30
|
+
#
|
31
|
+
# load extensions
|
32
|
+
#
|
33
|
+
if Object.const_defined?(:Rails) && Rails.const_defined?(:Railtie)
|
34
|
+
require "sysloggly/rails"
|
35
|
+
end
|
36
|
+
if defined?(Honeybadger)
|
37
|
+
require 'sysloggly/extensions/honeybadger'
|
38
|
+
end
|
@@ -1,18 +1,24 @@
|
|
1
1
|
require "multi_json"
|
2
2
|
require "socket"
|
3
3
|
|
4
|
+
#
|
5
|
+
# Simple formatter to output error messages as JSON.
|
6
|
+
#
|
4
7
|
module Sysloggly
|
5
8
|
module Formatters
|
6
9
|
class SimpleFormatter
|
7
|
-
attr_reader :input_uri, :
|
10
|
+
attr_reader :input_uri, :custom_fields
|
8
11
|
|
9
|
-
def initialize(input_uri, opts)
|
12
|
+
def initialize(input_uri, opts = {})
|
10
13
|
@input_uri = input_uri
|
11
|
-
@opts = opts
|
12
14
|
|
15
|
+
@env = opts[:env] || Sysloggly.env
|
13
16
|
@hostname = opts[:hostname] || Socket.gethostname.split(".").first
|
14
17
|
@progname = opts[:progname]
|
15
|
-
@
|
18
|
+
@custom_fields = opts.except(:progname).merge({
|
19
|
+
env: @env,
|
20
|
+
hostname: @hostname
|
21
|
+
})
|
16
22
|
|
17
23
|
if ["udp", "tcp"].include?(@input_uri.scheme) && !@input_uri.path.empty?
|
18
24
|
if @facility = @input_uri.path.split("/")[1]
|
@@ -35,10 +41,10 @@ module Sysloggly
|
|
35
41
|
|
36
42
|
# @api public
|
37
43
|
def call(severity, datetime, progname, payload)
|
38
|
-
message = "#{severity} [#{datetime.strftime(datetime_format)}]
|
44
|
+
message = "#{severity} [#{datetime.strftime(datetime_format)}] "
|
39
45
|
|
40
|
-
message << MultiJson.dump(hashify_message(payload).merge(
|
41
|
-
message << "\r\n" if ["file", "tcp"].include?(
|
46
|
+
message << MultiJson.dump(hashify_message(payload).merge(custom_fields))
|
47
|
+
message << "\r\n" if ["file", "tcp"].include?(input_uri.scheme)
|
42
48
|
|
43
49
|
message
|
44
50
|
end
|
@@ -1,3 +1,6 @@
|
|
1
|
+
#
|
2
|
+
# Formatter to output messages as JSON in Rsyslog format.
|
3
|
+
#
|
1
4
|
module Sysloggly
|
2
5
|
module Formatters
|
3
6
|
class SyslogFormatter < SimpleFormatter
|
@@ -29,7 +32,7 @@ module Sysloggly
|
|
29
32
|
# Include process ID in progname/log tag - RFC3164 § 5.3
|
30
33
|
message << "#{@progname || progname || $0}[#{Process.pid}]: "
|
31
34
|
|
32
|
-
message << MultiJson.dump(hashify_message(payload).merge(
|
35
|
+
message << MultiJson.dump(hashify_message(payload).merge(custom_fields))
|
33
36
|
message << "\r\n" if ["file", "tcp"].include?(@input_uri.scheme)
|
34
37
|
|
35
38
|
message
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Sysloggly
|
2
|
+
module Logger
|
3
|
+
#
|
4
|
+
# Return new Ruby logger instance configured for Sysloggly.
|
5
|
+
#
|
6
|
+
# @return [Logger]
|
7
|
+
# @api public
|
8
|
+
def self.new(url, opts = {})
|
9
|
+
begin
|
10
|
+
input_uri = URI.parse(url)
|
11
|
+
rescue URI::InvalidURIError => e
|
12
|
+
raise InvalidInputURL, "Invalid Input URL `#{url.inspect}`"
|
13
|
+
end
|
14
|
+
|
15
|
+
client, formatter = nil
|
16
|
+
|
17
|
+
case input_uri.scheme
|
18
|
+
when "file"
|
19
|
+
client = Sysloggly::Clients::Filelog.new(input_uri.path)
|
20
|
+
formatter = Sysloggly::Formatters::SimpleFormatter.new(input_uri, opts)
|
21
|
+
when "udp", "tcp"
|
22
|
+
client = Sysloggly::Clients::Networklog.new(input_uri)
|
23
|
+
formatter = Sysloggly::Formatters::SyslogFormatter.new(input_uri, opts)
|
24
|
+
else
|
25
|
+
raise Sysloggly::UnsupportedScheme.new("#{input_uri.scheme} is unsupported")
|
26
|
+
end
|
27
|
+
|
28
|
+
logger = ::Logger.new(client)
|
29
|
+
logger.formatter = formatter
|
30
|
+
|
31
|
+
logger
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/sysloggly/rails.rb
CHANGED
@@ -16,8 +16,7 @@ module Sysloggly
|
|
16
16
|
config.uri ||= "file://#{Rails.root.join("log","sysloggly.log")}"
|
17
17
|
config.ignore_user_agents ||= ["Pingdom.com_bot"]
|
18
18
|
|
19
|
-
config.logger = Sysloggly.new(config.uri, {
|
20
|
-
env: config.env,
|
19
|
+
config.logger = Sysloggly::Logger.new(config.uri, {
|
21
20
|
progname: config.progname
|
22
21
|
})
|
23
22
|
end
|
@@ -41,8 +40,6 @@ module Sysloggly
|
|
41
40
|
end
|
42
41
|
|
43
42
|
Lograge.setup(app)
|
44
|
-
|
45
|
-
require 'sysloggly/extensions/honeybadger' if defined?(Honeybadger)
|
46
43
|
end
|
47
44
|
end
|
48
45
|
end
|
data/lib/sysloggly/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sysloggly
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joergen Dahlke
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-06-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: multi_json
|
@@ -86,6 +86,7 @@ files:
|
|
86
86
|
- lib/sysloggly/extensions/honeybadger.rb
|
87
87
|
- lib/sysloggly/formatters/simple_formatter.rb
|
88
88
|
- lib/sysloggly/formatters/syslog_formatter.rb
|
89
|
+
- lib/sysloggly/logger.rb
|
89
90
|
- lib/sysloggly/rails.rb
|
90
91
|
- lib/sysloggly/version.rb
|
91
92
|
- sysloggly.gemspec
|
@@ -109,7 +110,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
109
110
|
version: '0'
|
110
111
|
requirements: []
|
111
112
|
rubyforge_project: sysloggly
|
112
|
-
rubygems_version: 2.
|
113
|
+
rubygems_version: 2.7.6
|
113
114
|
signing_key:
|
114
115
|
specification_version: 4
|
115
116
|
summary: Lograge and Syslog integration for Rails apps.
|