logentries-logging 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4aa1be56131c441aba8a607fc521dc0435c267c4
4
+ data.tar.gz: b94b253b02d7d7a2b6b3fc8191822d9d170797a2
5
+ SHA512:
6
+ metadata.gz: 156e1b0247f2124d4efdc98ded58aeb555d3614e911ea229163f649975b5d5b3069477dea4d8e8dd250062ea4aaa9a552787edfaeb0c44f24ec84ac8a6745eee
7
+ data.tar.gz: a7a0f8947450f4d85b7f428c8d36f351ac16ded5876ce36cc9db160566d58a0e92ef8d75f3f1ccdfa4fddf1381a9f1ee54d6d4ad2ae42d82998c0491ebd481ea
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright (C) 2015 by Gametime United Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,85 @@
1
+ require 'socket'
2
+ require 'openssl'
3
+ require 'thread'
4
+ require 'timeout'
5
+
6
+ module Logging
7
+ module Appenders
8
+
9
+ # Accessor / Factory for the Logentries appender.
10
+ def self.logentries_logging( *args )
11
+ return ::Logging::Appenders::LogentriesLogging if args.empty?
12
+ ::Logging::Appenders::LogentriesLogging.new(*args)
13
+ end
14
+
15
+ # Provides an appender that can send log messages to loggly
16
+
17
+ class LogentriesLogging < ::Logging::Appender
18
+ attr_accessor :token, :logentries, :levels
19
+ def initialize( name, opts = {} )
20
+ opts[:header] = false
21
+ super(name, opts)
22
+ # customer token for logentries
23
+ self.token = opts.fetch(:token)
24
+ raise ArgumentError, 'Must specify token' if @token.nil?
25
+ self.logentries = open_connection
26
+ self.layout.items = %w(timestamp level logger message pid hostname thread_id mdc)
27
+ self.levels = Logging::LEVELS.invert
28
+ end
29
+
30
+ # SSL socket setup/closing pulled from https://github.com/logentries/le_ruby
31
+ def open_connection
32
+ host = 'api.logentries.com'
33
+ socket = TCPSocket.new(host, 20000)
34
+
35
+ cert_store = OpenSSL::X509::Store.new
36
+ cert_store.set_default_paths
37
+
38
+ ssl_context = OpenSSL::SSL::SSLContext.new()
39
+ ssl_context.cert_store = cert_store
40
+
41
+ ssl_version_candidates = [:TLSv1_2, :TLSv1_1, :TLSv1]
42
+ ssl_version_candidates = ssl_version_candidates.select { |version| OpenSSL::SSL::SSLContext::METHODS.include? version }
43
+ if ssl_version_candidates.empty?
44
+ raise "Could not find suitable TLS version"
45
+ end
46
+ # currently we only set the version when we have no choice
47
+ ssl_context.ssl_version = ssl_version_candidates[0] if ssl_version_candidates.length == 1
48
+ ssl_context.verify_mode = OpenSSL::SSL::VERIFY_PEER
49
+ ssl_socket = OpenSSL::SSL::SSLSocket.new(socket, ssl_context)
50
+ ssl_socket.hostname = host if ssl_socket.respond_to?(:hostname=)
51
+ ssl_socket.sync_close = true
52
+ Timeout::timeout(10) do
53
+ ssl_socket.connect
54
+ end
55
+ ssl_socket
56
+ end
57
+
58
+ def close_connection
59
+ if @logentries.respond_to?(:sysclose)
60
+ @logentries.sysclose
61
+ elsif @logentries.respond_to?(:close)
62
+ @logentries.close
63
+ end
64
+ end
65
+
66
+ def write(event)
67
+ data = "#{@token} #{self.layout.format(event)} \n"
68
+ @logentries.write(data)
69
+ rescue TimeoutError, Errno::EHOSTUNREACH, Errno::ECONNREFUSED, Errno::ECONNRESET, Errno::ETIMEDOUT, EOFError
70
+ close_connection
71
+ @logentries = open_connection
72
+ @logentries.write(data)
73
+ end
74
+
75
+ def reopen
76
+ @logentries = open_connection
77
+ end
78
+
79
+ def close( *args )
80
+ close_connection
81
+ super(false)
82
+ end
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,13 @@
1
+ module Logging
2
+ module Plugins
3
+ module LogentriesLogging
4
+ extend self
5
+
6
+ VERSION = '1.0.0'.freeze
7
+
8
+ def initialize_logentries_logging
9
+ require File.expand_path('../../appenders/logentries_logging', __FILE__)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,20 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "logentries-logging"
3
+ s.version = "0.0.4"
4
+
5
+ s.authors = ["Eric Nicholas"]
6
+ s.require_paths = ["lib"]
7
+ s.date = "2015-08-20"
8
+ s.description = "Appender for logging to logentries with logging gem"
9
+ s.email = "eric@gametime.co"
10
+ s.files = [
11
+ "LICENSE",
12
+ "logentries-logging.gemspec",
13
+ "lib/logging/appenders/logentries_logging.rb",
14
+ "lib/logging/plugins/logentries_logging.rb",
15
+ ]
16
+ s.license = 'MIT'
17
+ s.homepage = "http://github.com/gametimesf/logentries-logging"
18
+ s.summary = "appender for logging to logentries"
19
+
20
+ end
metadata ADDED
@@ -0,0 +1,47 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: logentries-logging
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.4
5
+ platform: ruby
6
+ authors:
7
+ - Eric Nicholas
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-08-20 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Appender for logging to logentries with logging gem
14
+ email: eric@gametime.co
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - LICENSE
20
+ - lib/logging/appenders/logentries_logging.rb
21
+ - lib/logging/plugins/logentries_logging.rb
22
+ - logentries-logging.gemspec
23
+ homepage: http://github.com/gametimesf/logentries-logging
24
+ licenses:
25
+ - MIT
26
+ metadata: {}
27
+ post_install_message:
28
+ rdoc_options: []
29
+ require_paths:
30
+ - lib
31
+ required_ruby_version: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ required_rubygems_version: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ requirements: []
42
+ rubyforge_project:
43
+ rubygems_version: 2.4.5.1
44
+ signing_key:
45
+ specification_version: 4
46
+ summary: appender for logging to logentries
47
+ test_files: []