sinatra-syslog-logger 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c56fcf238831aa7c036de8d68185dbba7a6e369c
4
+ data.tar.gz: a0f3ee70c7f75487d6b3f6e1af1639cd0ceae04b
5
+ SHA512:
6
+ metadata.gz: 8f1fe278f2e4e7c771cb82c8c4174577bbed64e0fed20f997bc88483d7437426e24f7cb1de0d497423efdbed3feb3f0d809e208414829747c88440083663974f
7
+ data.tar.gz: 52d65db6a143f083dd2ec182695ce591259742334b3560fcad256bbb230dfca6a0a7ddc1eba6bc267dd566e5893199f89a6c393113e997c13ae95244b5407708
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ .idea
2
+ Gemfile.lock
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/README.md ADDED
@@ -0,0 +1,12 @@
1
+ Sinatra Syslog logger
2
+ =========
3
+
4
+ This gem sends STDOUT and STDERR of Sinatra to Syslog service.
5
+
6
+ #### USAGE
7
+
8
+ Just include gem in your `Gemfile` and require it `require sinatra-syslog-logger` **after requiring sinatra**.
9
+
10
+ #### TODO
11
+
12
+ Make syslog IP and PORT configurable
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler/setup'
2
+ require 'bundler/gem_tasks'
@@ -0,0 +1,3 @@
1
+ require_relative 'sinatra-syslog-logger/logger'
2
+ require_relative 'sinatra-syslog-logger/sinatra'
3
+
@@ -0,0 +1,38 @@
1
+ require 'socket'
2
+
3
+ class SyslogLogger
4
+
5
+ SYSLOG_IP = '127.0.0.1'
6
+ SYSLOG_PORT = 514
7
+
8
+ def initialize(error_log_file = nil)
9
+ @udp = UDPSocket.new
10
+ @error_log_file = error_log_file
11
+ end
12
+
13
+ def <<(msg)
14
+ send_logs_to_syslog(msg)
15
+ end
16
+
17
+ def puts(msg)
18
+ send_logs_to_syslog(msg)
19
+ end
20
+
21
+ def flush; end
22
+
23
+ private
24
+
25
+ def send_logs_to_syslog(log_msg)
26
+ # max packet size to send is 9210 chars, so do it in chunks
27
+ chunk_string(log_msg).each do |chunk|
28
+ @udp.send(log_msg[0..9210], 0, SYSLOG_IP, SYSLOG_PORT)
29
+ end
30
+ @error_log_file.write(log_msg) unless @error_log_file.nil?
31
+ end
32
+
33
+ def chunk_string(msg)
34
+ msg.scan(/.{1,9000}/)
35
+ end
36
+
37
+ end
38
+
@@ -0,0 +1,9 @@
1
+ class Sinatra::Base
2
+ configure do
3
+ use Rack::CommonLogger, SyslogLogger.new
4
+ end
5
+
6
+ before do
7
+ env["rack.errors"] = SyslogLogger.new unless env["rack.errors"].is_a? StringIO
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ module SinatraSyslogLogger
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib/', __FILE__)
3
+ $:.unshift lib unless $:.include?(lib)
4
+
5
+ require 'sinatra-syslog-logger/version'
6
+
7
+ Gem::Specification.new do |s|
8
+ s.name = 'sinatra-syslog-logger'
9
+ s.version = SinatraSyslogLogger::VERSION
10
+
11
+ s.authors = ['Lukas Maciulis', 'Ben Snape']
12
+ s.email = ['ben.snape@itv.com']
13
+ s.description = 'Send Sinatra webserver logs to syslog'
14
+
15
+ s.files = `git ls-files`.split("\n")
16
+
17
+ s.require_paths = ["lib"]
18
+ s.summary = 'Send Sinatra webserver logs to syslog'
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
20
+
21
+ s.add_development_dependency('rake', '~> 10')
22
+ end
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sinatra-syslog-logger
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Lukas Maciulis
8
+ - Ben Snape
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2015-06-04 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '10'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '10'
28
+ description: Send Sinatra webserver logs to syslog
29
+ email:
30
+ - ben.snape@itv.com
31
+ executables: []
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - ".gitignore"
36
+ - Gemfile
37
+ - README.md
38
+ - Rakefile
39
+ - lib/sinatra-syslog-logger.rb
40
+ - lib/sinatra-syslog-logger/logger.rb
41
+ - lib/sinatra-syslog-logger/sinatra.rb
42
+ - lib/sinatra-syslog-logger/version.rb
43
+ - sinatra-syslog-logger.gemspec
44
+ homepage:
45
+ licenses: []
46
+ metadata: {}
47
+ post_install_message:
48
+ rdoc_options: []
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ requirements: []
62
+ rubyforge_project:
63
+ rubygems_version: 2.2.2
64
+ signing_key:
65
+ specification_version: 4
66
+ summary: Send Sinatra webserver logs to syslog
67
+ test_files: []