logging-rtail 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.rubocop.yml +38 -0
- data/Gemfile +4 -0
- data/README.md +73 -0
- data/Rakefile +6 -0
- data/TODO.org +4 -0
- data/bin/console +10 -0
- data/bin/setup +7 -0
- data/lib/logging/appenders/rtail.rb +73 -0
- data/lib/logging/plugins/rtail.rb +15 -0
- data/logging-rtail.gemspec +37 -0
- metadata +154 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: cc4e9e5dfdd6a40e40713d3084a09fa303f0fb27
|
4
|
+
data.tar.gz: 3dc9d2c14d07668cf3912f528f1197c4599a9827
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d016b3fe9ab2c153a73c8a49da6aaafa61c381c659086f70eee6354d732b6390cf57c59a77ee95e90f793d05080a02c076408243aa116d76c3061c3cb57f2430
|
7
|
+
data.tar.gz: 9541536876b1b754f40552fd1f6e5abc07cdceed4674165a3a22d77f10a8efff7f7d2cb5c9d55cf1537ac11d5bf06ea7d2932627bf1608de6b4e9dcf4ea93e38
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# Most of these are disabling existing cops, primarily
|
2
|
+
# due to a smattering of different styles and loose
|
3
|
+
# guidlines for contributions.
|
4
|
+
#
|
5
|
+
# Any of these may be changed.
|
6
|
+
|
7
|
+
# I personally believe double-quotes is more-idiomatic Ruby
|
8
|
+
# StringLiterals:
|
9
|
+
# EnforcedStyle: double_quotes
|
10
|
+
# Enabled: false
|
11
|
+
|
12
|
+
Style/PercentLiteralDelimiters:
|
13
|
+
PreferredDelimiters:
|
14
|
+
'%': '{}'
|
15
|
+
'%i': '{}'
|
16
|
+
'%q': '{}'
|
17
|
+
'%Q': '{}'
|
18
|
+
'%r': '{}'
|
19
|
+
'%s': '{}'
|
20
|
+
'%w': '{}'
|
21
|
+
'%W': '{}'
|
22
|
+
'%x': '{}'
|
23
|
+
|
24
|
+
SpaceInsideBlockBraces:
|
25
|
+
SpaceBeforeBlockParameters: false
|
26
|
+
|
27
|
+
LineLength:
|
28
|
+
Max: 120
|
29
|
+
|
30
|
+
# Style/ClassAndModuleChildren:
|
31
|
+
# EnforcedStyle: compact
|
32
|
+
|
33
|
+
Style/FileName:
|
34
|
+
Enabled: false
|
35
|
+
|
36
|
+
# TODO: Disable before release
|
37
|
+
# Documentation:
|
38
|
+
# Enabled: false
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
# Logging::Plugins::Rtail
|
2
|
+
|
3
|
+
This is an "Appender" for the [Logging](https://rubygems.org/gems/logging) gem, to allow you to forward Logs directly to an
|
4
|
+
[Rtail](https://github.com/kilianc/rtail) Service.
|
5
|
+
|
6
|
+
Normally, you'd use the Rtail client to read logs from another process (e.g. `tail -F process.log | rtail --name WildTest`) but
|
7
|
+
this Gem allows you to send the logs directly.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'logging'
|
15
|
+
gem 'logging-rtail'
|
16
|
+
```
|
17
|
+
|
18
|
+
And then execute:
|
19
|
+
|
20
|
+
$ bundle
|
21
|
+
|
22
|
+
Or install it yourself as:
|
23
|
+
|
24
|
+
$ gem install logging-rtail
|
25
|
+
|
26
|
+
## Usage
|
27
|
+
|
28
|
+
The Logging gem uses [little-plugger](https://rubygems.org/gems/little-plugger) gem to manage
|
29
|
+
[extending Logger](https://github.com/TwP/logging#extending).
|
30
|
+
This means it will automatically load and initialise the `logging-rtail` code as soon as it loads the Logging code.
|
31
|
+
|
32
|
+
To configure Logging to use Rtail, you simply have to add the appender to your configuring of Logging.
|
33
|
+
|
34
|
+
e.g. The following will send the "Wootles" log-output to STDERR and the Rtail service running on the localhost:
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
l = Logging.logger["The Wild Wild Test"]
|
38
|
+
l.add_appenders(
|
39
|
+
Logging.appenders.stderr,
|
40
|
+
Logging.appenders.rtail("Wild Test stream")
|
41
|
+
)
|
42
|
+
|
43
|
+
l.info "Wootles"
|
44
|
+
```
|
45
|
+
|
46
|
+
The default host is `localhost` and port is `9999`, as per [Rtail's defaults](https://github.com/kilianc/rtail#params-1).
|
47
|
+
|
48
|
+
If you want to connect to an Rtail service on a different host or port, pass the `host` or `port` options to the `rtail` appender factory:
|
49
|
+
|
50
|
+
```ruby
|
51
|
+
l.add_appenders(
|
52
|
+
Logging.appenders.rtail("Wild Test stream", host: "other.host.nowhere", port: 10010)
|
53
|
+
)
|
54
|
+
```
|
55
|
+
|
56
|
+
## Development
|
57
|
+
|
58
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests.
|
59
|
+
You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
60
|
+
|
61
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in
|
62
|
+
`lib/logging/plugins/rtail.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits
|
63
|
+
and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
64
|
+
|
65
|
+
### To Do's
|
66
|
+
|
67
|
+
I track major "To Do's" in a [TODO.org](TODO.org) file.
|
68
|
+
|
69
|
+
I track context-sensitive and minor ones with `TODO` and `FIXME` comments in the source code.
|
70
|
+
|
71
|
+
### Contributing
|
72
|
+
|
73
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/fairfaxmedia/logging-rtail.
|
data/Rakefile
ADDED
data/TODO.org
ADDED
data/bin/console
ADDED
data/bin/setup
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'socket'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module Logging
|
5
|
+
module Appenders
|
6
|
+
# Factory for the Rtail appender.
|
7
|
+
def self.rtail(*args)
|
8
|
+
fail ArgumentError, '::Logging::Appenders::Rtail needs a name as first argument.' if args.empty?
|
9
|
+
::Logging::Appenders::Rtail.new(*args)
|
10
|
+
end
|
11
|
+
|
12
|
+
# This class provides an Appender that can write to a Rtail service over UDP.
|
13
|
+
class Rtail < ::Logging::Appenders::IO
|
14
|
+
# Creates a new Rtail Appender that will use the given host and port
|
15
|
+
# as the Rtail server destination.
|
16
|
+
#
|
17
|
+
# @param name [String] Stream ID to differentiate in the Rtail server
|
18
|
+
# @param host [String] Host / IP of the Rtail server's UDP receiver (defaults to "localhost")
|
19
|
+
# @param port [Integer] Port of the Rtail server's UDP receiver (defaults to 9999)
|
20
|
+
def initialize(name, opts = {})
|
21
|
+
@host = opts.fetch(:host, 'localhost')
|
22
|
+
@port = opts.fetch(:port, 9999)
|
23
|
+
|
24
|
+
fail ArgumentError, 'Empty host and port is not appropriate' unless host && !host.empty? && port
|
25
|
+
|
26
|
+
# Because it's UDP, we want it flushed to the server, immediately:
|
27
|
+
super(name, connect(@host, @port), opts.merge(auto_flushing: true))
|
28
|
+
end
|
29
|
+
|
30
|
+
def host
|
31
|
+
@host.dup
|
32
|
+
end
|
33
|
+
|
34
|
+
attr_reader :port
|
35
|
+
|
36
|
+
# Reopen the connection to the underlying logging destination. If the
|
37
|
+
# connection is currently closed then it will be opened. If the connection
|
38
|
+
# is currently open then it will be closed and immediately opened.
|
39
|
+
def reopen
|
40
|
+
@mutex.synchronize do
|
41
|
+
if defined? @io && @io
|
42
|
+
flush
|
43
|
+
close rescue nil
|
44
|
+
end
|
45
|
+
@io = connect(@host, @port)
|
46
|
+
end
|
47
|
+
|
48
|
+
super
|
49
|
+
self
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def connect(host, port)
|
55
|
+
UDPSocket.new.tap {|s| s.connect(host, port) }
|
56
|
+
end
|
57
|
+
|
58
|
+
def canonical_write(str)
|
59
|
+
return self if @io.nil?
|
60
|
+
|
61
|
+
str = str.force_encoding(encoding) if encoding && str.encoding != encoding
|
62
|
+
@io.syswrite JSON.generate(id: name, timestamp: Time.now, content: str)
|
63
|
+
|
64
|
+
self
|
65
|
+
|
66
|
+
rescue StandardError => err
|
67
|
+
self.level = :off
|
68
|
+
::Logging.log_internal { "appender #{name.inspect} has been disabled" }
|
69
|
+
::Logging.log_internal_error(err)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Logging
|
2
|
+
module Plugins
|
3
|
+
# This is plugin-intialisation module used by `little-plugger` to find the code:
|
4
|
+
module Rtail
|
5
|
+
extend self
|
6
|
+
|
7
|
+
VERSION = '0.1.2'.freeze unless defined? VERSION
|
8
|
+
|
9
|
+
# Initialiser for `little-plugger`:
|
10
|
+
def initialize_rtail
|
11
|
+
require File.expand_path('../../appenders/rtail', __FILE__)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'logging/plugins/rtail'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'logging-rtail'
|
8
|
+
spec.version = Logging::Plugins::Rtail::VERSION
|
9
|
+
spec.authors = ['Will']
|
10
|
+
spec.email = ['wildjim+dev@kiwinet.org']
|
11
|
+
|
12
|
+
spec.summary = 'An appender for the Logging gem that sends messages to an Rtail server'
|
13
|
+
# spec.description = %q{TODO: Write a longer description or delete this line.}
|
14
|
+
spec.homepage = 'https://github.com/fairfaxmedia/logging-rtail'
|
15
|
+
|
16
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
17
|
+
# delete this section to allow pushing this gem to any host.
|
18
|
+
# if spec.respond_to?(:metadata)
|
19
|
+
# spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
|
20
|
+
# else
|
21
|
+
# raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
22
|
+
# end
|
23
|
+
|
24
|
+
spec.files = `git ls-files -z`.split("\x0").reject {|f| f.match(%r{^(test|spec|features)/}) }
|
25
|
+
spec.bindir = 'exe'
|
26
|
+
spec.executables = spec.files.grep(%r{^exe/}) {|f| File.basename(f) }
|
27
|
+
spec.require_paths = ['lib']
|
28
|
+
|
29
|
+
spec.add_development_dependency 'bundler', '~> 1.10'
|
30
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
31
|
+
spec.add_development_dependency 'rspec', '~> 3.3'
|
32
|
+
spec.add_development_dependency 'pry-byebug', '~> 3.2'
|
33
|
+
|
34
|
+
spec.add_runtime_dependency 'little-plugger', '~> 1.1'
|
35
|
+
spec.add_runtime_dependency 'logging', '~> 2.0'
|
36
|
+
spec.add_runtime_dependency 'json', '~> 1.8'
|
37
|
+
end
|
metadata
ADDED
@@ -0,0 +1,154 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: logging-rtail
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Will
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-10-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.10'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.10'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.3'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.3'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry-byebug
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.2'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.2'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: little-plugger
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.1'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.1'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: logging
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '2.0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '2.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: json
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '1.8'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '1.8'
|
111
|
+
description:
|
112
|
+
email:
|
113
|
+
- wildjim+dev@kiwinet.org
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- ".gitignore"
|
119
|
+
- ".rspec"
|
120
|
+
- ".rubocop.yml"
|
121
|
+
- Gemfile
|
122
|
+
- README.md
|
123
|
+
- Rakefile
|
124
|
+
- TODO.org
|
125
|
+
- bin/console
|
126
|
+
- bin/setup
|
127
|
+
- lib/logging/appenders/rtail.rb
|
128
|
+
- lib/logging/plugins/rtail.rb
|
129
|
+
- logging-rtail.gemspec
|
130
|
+
homepage: https://github.com/fairfaxmedia/logging-rtail
|
131
|
+
licenses: []
|
132
|
+
metadata: {}
|
133
|
+
post_install_message:
|
134
|
+
rdoc_options: []
|
135
|
+
require_paths:
|
136
|
+
- lib
|
137
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
138
|
+
requirements:
|
139
|
+
- - ">="
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
142
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
143
|
+
requirements:
|
144
|
+
- - ">="
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
version: '0'
|
147
|
+
requirements: []
|
148
|
+
rubyforge_project:
|
149
|
+
rubygems_version: 2.4.8
|
150
|
+
signing_key:
|
151
|
+
specification_version: 4
|
152
|
+
summary: An appender for the Logging gem that sends messages to an Rtail server
|
153
|
+
test_files: []
|
154
|
+
has_rdoc:
|