sensu-logger 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/.travis.yml +11 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +20 -0
- data/README.md +28 -0
- data/Rakefile +6 -0
- data/lib/sensu/logger.rb +33 -0
- data/lib/sensu/logger/constants.rb +5 -0
- data/lib/sensu/logger/stream.rb +185 -0
- data/sensu-logger.gemspec +25 -0
- data/spec/helpers.rb +29 -0
- data/spec/logger_spec.rb +46 -0
- data/spec/stream_spec.rb +110 -0
- metadata +144 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4db534173e30cf3979d6da7ff7f265295ec81355
|
4
|
+
data.tar.gz: 67965cb16d8007580121d805571a05dbfdff7ebf
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: bea338ccf9f40ca351c1b1a30c8bbe880c041f0544bd45eb670c12db9af20c4c2c60f548ad4707b0f3e64df55a1afdef67ca66c2ebb8b8807e789bcf0d49c183
|
7
|
+
data.tar.gz: 97207727a424296216289e5a9476a6c4ab012285f9df9a04c2694b4d7b4673172461d2877bb203eeb8c7b788bc50e9b5269f2c00f1a15f2923e6a145a425d1f2
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2014 Heavy Water Operations, LLC.
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# Sensu::Logger
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/sensu/sensu-logger.svg?branch=master)](https://travis-ci.org/sensu/sensu-logger)
|
4
|
+
|
5
|
+
[![Code Climate](https://codeclimate.com/github/sensu/sensu-logger.png)](https://codeclimate.com/github/sensu/sensu-logger)
|
6
|
+
[![Code Climate Coverage](https://codeclimate.com/github/sensu/sensu-logger/coverage.png)](https://codeclimate.com/github/sensu/sensu-logger)
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
gem 'sensu-logger'
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
## Usage
|
19
|
+
|
20
|
+
Documentation can be found [here](http://rubydoc.info/github/sensu/sensu-logger/Sensu/Logger).
|
21
|
+
|
22
|
+
## Contributing
|
23
|
+
|
24
|
+
1. [Fork it](https://github.com/sensu/sensu-logger/fork)
|
25
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
26
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
27
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
28
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/lib/sensu/logger.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require "sensu/logger/stream"
|
2
|
+
|
3
|
+
module Sensu
|
4
|
+
module Logger
|
5
|
+
class << self
|
6
|
+
# Setup a log stream.
|
7
|
+
#
|
8
|
+
# @param [Hash] options to create the log stream with.
|
9
|
+
# @option options [String] :log_level to use.
|
10
|
+
# @option options [String] :log_file to use.
|
11
|
+
# @return [Stream] instance of a log stream.
|
12
|
+
def setup(options={})
|
13
|
+
@stream = Stream.new
|
14
|
+
if options[:log_level]
|
15
|
+
@stream.level = options[:log_level]
|
16
|
+
end
|
17
|
+
if options[:log_file]
|
18
|
+
@stream.reopen(options[:log_file])
|
19
|
+
end
|
20
|
+
@stream
|
21
|
+
end
|
22
|
+
|
23
|
+
# Retrieve the current log stream or set one up if there isn't
|
24
|
+
# one. Note: We may need to add a mutex for thread safety.
|
25
|
+
#
|
26
|
+
# @param [Hash] options to pass to setup().
|
27
|
+
# @return [Stream] instance of a log stream.
|
28
|
+
def get(options={})
|
29
|
+
@stream || setup(options)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,185 @@
|
|
1
|
+
gem "sensu-em"
|
2
|
+
|
3
|
+
require "eventmachine"
|
4
|
+
require "multi_json"
|
5
|
+
require "sensu/logger/constants"
|
6
|
+
|
7
|
+
module Sensu
|
8
|
+
module Logger
|
9
|
+
class Stream
|
10
|
+
# @!attribute [rw] level
|
11
|
+
# @return level [Symbol] current log level.
|
12
|
+
attr_accessor :level
|
13
|
+
|
14
|
+
# Initialize a log stream, redirect STDERR to STDOUT, create log
|
15
|
+
# level methods, and setup the reactor log event writer.
|
16
|
+
def initialize
|
17
|
+
@stream = []
|
18
|
+
@stream_callbacks = []
|
19
|
+
@level = :info
|
20
|
+
STDOUT.sync = true
|
21
|
+
STDERR.reopen(STDOUT)
|
22
|
+
self.class.create_level_methods
|
23
|
+
setup_writer
|
24
|
+
end
|
25
|
+
|
26
|
+
# Create a method for each of the log levels, they call add() to
|
27
|
+
# add log events to the log stream.
|
28
|
+
def self.create_level_methods
|
29
|
+
LEVELS.each do |level|
|
30
|
+
define_method(level) do |*args|
|
31
|
+
add(level, *args)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
# Check to see if a log level is currently being filtered.
|
37
|
+
#
|
38
|
+
# @param level [Symbol] log event level.
|
39
|
+
# @return [TrueClass, FalseClass]
|
40
|
+
def level_filtered?(level)
|
41
|
+
LEVELS.index(level) < LEVELS.index(@level)
|
42
|
+
end
|
43
|
+
|
44
|
+
# Add a log event to the log stream.
|
45
|
+
#
|
46
|
+
# @param level [Symbol] log event level.
|
47
|
+
# @param args [Array] to pass to create_log_event().
|
48
|
+
# @return [TrueClass, FalseClass] if the log event was added.
|
49
|
+
def add(level, *args)
|
50
|
+
unless level_filtered?(level)
|
51
|
+
event = create_log_event(level, *args)
|
52
|
+
if EM.reactor_running?
|
53
|
+
schedule_write(event)
|
54
|
+
else
|
55
|
+
safe_write(event)
|
56
|
+
end
|
57
|
+
true
|
58
|
+
else
|
59
|
+
false
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
# Reopen the log stream output, write log events to a file.
|
64
|
+
#
|
65
|
+
# @param target [IO, String] IO stream or file path.
|
66
|
+
def reopen(target)
|
67
|
+
@reopen = target
|
68
|
+
case target
|
69
|
+
when IO
|
70
|
+
STDOUT.reopen(target)
|
71
|
+
STDOUT.sync = true
|
72
|
+
STDERR.reopen(STDOUT)
|
73
|
+
when String
|
74
|
+
if File.writable?(target) || !File.exist?(target) && File.writable?(File.dirname(target))
|
75
|
+
STDOUT.reopen(target, "a")
|
76
|
+
STDOUT.sync = true
|
77
|
+
STDERR.reopen(STDOUT)
|
78
|
+
else
|
79
|
+
error("log file is not writable", {
|
80
|
+
:log_file => target
|
81
|
+
})
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
# Setup signal traps for the log stream.
|
87
|
+
# Signals:
|
88
|
+
# TRAP: toggle debug logging.
|
89
|
+
# USR2: reopen the log file.
|
90
|
+
def setup_signal_traps
|
91
|
+
if Signal.list.include?("TRAP")
|
92
|
+
Signal.trap("TRAP") do
|
93
|
+
@level = case @level
|
94
|
+
when :debug
|
95
|
+
@previous_level || :info
|
96
|
+
else
|
97
|
+
@previous_level = @level
|
98
|
+
:debug
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
if Signal.list.include?("USR2")
|
103
|
+
Signal.trap("USR2") do
|
104
|
+
if @reopen
|
105
|
+
reopen(@reopen)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
private
|
112
|
+
|
113
|
+
# Create a JSON log event.
|
114
|
+
#
|
115
|
+
# @param level [Symbol] log event level.
|
116
|
+
# @param message [String] log event message.
|
117
|
+
# @param data [Hash] log event data.
|
118
|
+
# @return [String] JSON log event.
|
119
|
+
def create_log_event(level, message, data=nil)
|
120
|
+
event = {}
|
121
|
+
event[:timestamp] = Time.now.strftime("%Y-%m-%dT%H:%M:%S.%6N%z")
|
122
|
+
event[:level] = level
|
123
|
+
event[:message] = message
|
124
|
+
if data.is_a?(Hash)
|
125
|
+
event.merge!(data)
|
126
|
+
end
|
127
|
+
MultiJson.dump(event)
|
128
|
+
end
|
129
|
+
|
130
|
+
# Schedule a log event write, pushing the JSON log event into
|
131
|
+
# the stream.
|
132
|
+
#
|
133
|
+
# @param event [String] JSON log event.
|
134
|
+
def schedule_write(event)
|
135
|
+
EM.schedule do
|
136
|
+
@stream << event
|
137
|
+
unless @stream_callbacks.empty?
|
138
|
+
@stream_callbacks.shift.call(@stream.shift)
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
# Write a JSON log event to STDOUT, which may be redirected to a
|
144
|
+
# log file. This method will take no action if the storage
|
145
|
+
# device has no space remaining.
|
146
|
+
def safe_write(event)
|
147
|
+
begin
|
148
|
+
puts event
|
149
|
+
rescue Errno::ENOSPC
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
# Register a log stream callback (a write operation).
|
154
|
+
#
|
155
|
+
# @param [Proc] callback to register, it will eventually be
|
156
|
+
# called and passed a JSON log event as a parameter.
|
157
|
+
def register_callback(&callback)
|
158
|
+
EM.schedule do
|
159
|
+
if @stream.empty?
|
160
|
+
@stream_callbacks << callback
|
161
|
+
else
|
162
|
+
callback.call(@stream.shift)
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
# Setup reactor log event writer. On shutdown, remaining log
|
168
|
+
# events will be written/flushed.
|
169
|
+
def setup_writer
|
170
|
+
writer = Proc.new do |log_event|
|
171
|
+
safe_write(log_event)
|
172
|
+
EM.next_tick do
|
173
|
+
register_callback(&writer)
|
174
|
+
end
|
175
|
+
end
|
176
|
+
register_callback(&writer)
|
177
|
+
EM.add_shutdown_hook do
|
178
|
+
@stream.size.times do
|
179
|
+
safe_write(@stream.shift)
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "sensu-logger"
|
5
|
+
spec.version = "0.0.1"
|
6
|
+
spec.authors = ["Sean Porter"]
|
7
|
+
spec.email = ["portertech@gmail.com"]
|
8
|
+
spec.summary = "The Sensu logger library"
|
9
|
+
spec.description = "The Sensu logger library"
|
10
|
+
spec.homepage = "https://github.com/sensu/sensu-logger"
|
11
|
+
spec.license = "MIT"
|
12
|
+
|
13
|
+
spec.files = `git ls-files -z`.split("\x0")
|
14
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
15
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
16
|
+
spec.require_paths = ["lib"]
|
17
|
+
|
18
|
+
spec.add_dependency("sensu-em")
|
19
|
+
spec.add_dependency("multi_json")
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec"
|
24
|
+
spec.add_development_dependency "codeclimate-test-reporter"
|
25
|
+
end
|
data/spec/helpers.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require "rspec"
|
2
|
+
require "eventmachine"
|
3
|
+
|
4
|
+
unless RUBY_VERSION < "1.9" || RUBY_PLATFORM =~ /java/
|
5
|
+
require "codeclimate-test-reporter"
|
6
|
+
CodeClimate::TestReporter.start
|
7
|
+
end
|
8
|
+
|
9
|
+
module Helpers
|
10
|
+
def timer(delay, &callback)
|
11
|
+
periodic_timer = EM::PeriodicTimer.new(delay) do
|
12
|
+
callback.call
|
13
|
+
periodic_timer.cancel
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def async_wrapper(&callback)
|
18
|
+
EM.run do
|
19
|
+
timer(10) do
|
20
|
+
raise "test timed out"
|
21
|
+
end
|
22
|
+
callback.call
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def async_done
|
27
|
+
EM.stop_event_loop
|
28
|
+
end
|
29
|
+
end
|
data/spec/logger_spec.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "helpers")
|
2
|
+
require "sensu/logger"
|
3
|
+
|
4
|
+
describe "Sensu::Logger" do
|
5
|
+
include Helpers
|
6
|
+
|
7
|
+
it "can provide the logger API" do
|
8
|
+
Sensu::Logger.should respond_to(:setup, :get)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "can set up a log stream" do
|
12
|
+
logger = Sensu::Logger.setup
|
13
|
+
logger.info("some info", {:foo => "bar"}).should be_true
|
14
|
+
logger.level = :warn
|
15
|
+
logger.info("some info", {:foo => "bar"}).should be_false
|
16
|
+
end
|
17
|
+
|
18
|
+
it "can retrive the current log stream" do
|
19
|
+
logger = Sensu::Logger.setup
|
20
|
+
Sensu::Logger.get.should eq(logger)
|
21
|
+
Sensu::Logger.get.should eq(logger)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "can setup a log stream if one doesn't exist" do
|
25
|
+
logger = Sensu::Logger.get
|
26
|
+
logger.info("some info", {:foo => "bar"}).should be_true
|
27
|
+
end
|
28
|
+
|
29
|
+
it "can setup a log stream with a log level and file" do
|
30
|
+
stdout = STDOUT.dup
|
31
|
+
file = Tempfile.new("sensu-logger")
|
32
|
+
logger = Sensu::Logger.setup(:log_level => :warn, :log_file => file.path)
|
33
|
+
logger.info("some info", {:foo => "bar"}).should be_false
|
34
|
+
logger.warn("a warning", {:foo => "bar"}).should be_true
|
35
|
+
file_contents = IO.read(file.path)
|
36
|
+
file_contents.should match(/a warning/)
|
37
|
+
logger.reopen(stdout)
|
38
|
+
logger.warn("a warning", {:foo => "bar"}).should be_true
|
39
|
+
end
|
40
|
+
|
41
|
+
it "can setup a log stream with options if one doesn't exist" do
|
42
|
+
logger = Sensu::Logger.get(:log_level => :warn)
|
43
|
+
logger.info("some info", {:foo => "bar"}).should be_false
|
44
|
+
logger.warn("a warning", {:foo => "bar"}).should be_true
|
45
|
+
end
|
46
|
+
end
|
data/spec/stream_spec.rb
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "helpers")
|
2
|
+
require "sensu/logger/stream"
|
3
|
+
require "tempfile"
|
4
|
+
|
5
|
+
describe "Sensu::Logger::Stream" do
|
6
|
+
include Helpers
|
7
|
+
|
8
|
+
before do
|
9
|
+
@stream = Sensu::Logger::Stream.new
|
10
|
+
end
|
11
|
+
|
12
|
+
it "can log events with different levels" do
|
13
|
+
@stream.debug("some debug info", {:foo => "bar"}).should be_false
|
14
|
+
@stream.info("some info", {:foo => "bar"}).should be_true
|
15
|
+
@stream.warn("a warning", {:foo => "bar"}).should be_true
|
16
|
+
@stream.error("an error", {:foo => "bar"}).should be_true
|
17
|
+
@stream.fatal("something exploded", {:foo => "bar"}).should be_true
|
18
|
+
@stream.level = :debug
|
19
|
+
@stream.debug("some debug info", {:foo => "bar"}).should be_true
|
20
|
+
@stream.info("some info", {:foo => "bar"}).should be_true
|
21
|
+
@stream.level = :warn
|
22
|
+
@stream.info("some info", {:foo => "bar"}).should be_false
|
23
|
+
@stream.warn("a warning", {:foo => "bar"}).should be_true
|
24
|
+
end
|
25
|
+
|
26
|
+
it "can reopen STDERR/STDOUT and redirect them to a log file" do
|
27
|
+
stdout = STDOUT.dup
|
28
|
+
file = Tempfile.new("sensu-logger")
|
29
|
+
@stream.reopen(file.path)
|
30
|
+
@stream.info("some info", {:foo => "bar"}).should be_true
|
31
|
+
@stream.reopen(stdout)
|
32
|
+
file_contents = IO.read(file.path)
|
33
|
+
file_contents.should match(/timestamp/)
|
34
|
+
file_contents.should match(/"message":"some info"/)
|
35
|
+
file_contents.should match(/"foo":"bar"/)
|
36
|
+
@stream.reopen("/untouchable.log")
|
37
|
+
@stream.info("some info", {:foo => "bar"}).should be_true
|
38
|
+
end
|
39
|
+
|
40
|
+
it "can setup signal traps to toggle debug logging and reopen the log file" do
|
41
|
+
@stream.setup_signal_traps
|
42
|
+
@stream.debug("some debug info", {:foo => "bar"}).should be_false
|
43
|
+
@stream.info("some info", {:foo => "bar"}).should be_true
|
44
|
+
Process.kill("TRAP", Process.pid)
|
45
|
+
sleep 0.5
|
46
|
+
@stream.debug("some debug info", {:foo => "bar"}).should be_true
|
47
|
+
@stream.info("some info", {:foo => "bar"}).should be_true
|
48
|
+
Process.kill("TRAP", Process.pid)
|
49
|
+
sleep 0.5
|
50
|
+
@stream.debug("some debug info", {:foo => "bar"}).should be_false
|
51
|
+
@stream.info("some info", {:foo => "bar"}).should be_true
|
52
|
+
@stream.level = :warn
|
53
|
+
@stream.info("some info", {:foo => "bar"}).should be_false
|
54
|
+
Process.kill("TRAP", Process.pid)
|
55
|
+
sleep 0.5
|
56
|
+
@stream.debug("some debug info", {:foo => "bar"}).should be_true
|
57
|
+
@stream.info("some info", {:foo => "bar"}).should be_true
|
58
|
+
Process.kill("TRAP", Process.pid)
|
59
|
+
sleep 0.5
|
60
|
+
@stream.debug("some debug info", {:foo => "bar"}).should be_false
|
61
|
+
@stream.info("some info", {:foo => "bar"}).should be_false
|
62
|
+
@stream.warn("a warning", {:foo => "bar"}).should be_true
|
63
|
+
@stream.reopen(STDOUT)
|
64
|
+
Process.kill("USR2", Process.pid)
|
65
|
+
sleep 0.5
|
66
|
+
@stream.error("an error", {:foo => "bar"}).should be_true
|
67
|
+
end
|
68
|
+
|
69
|
+
it "can operate as expected within the eventmachine reactor" do
|
70
|
+
async_wrapper do
|
71
|
+
stdout = STDOUT.dup
|
72
|
+
file = Tempfile.new("sensu-logger")
|
73
|
+
@stream.reopen(file.path)
|
74
|
+
@stream.debug("some debug info", {:foo => "bar"}).should be_false
|
75
|
+
@stream.info("some info", {:foo => "bar"}).should be_true
|
76
|
+
@stream.warn("a warning", {:foo => "bar"}).should be_true
|
77
|
+
@stream.error("an error", {:foo => "bar"}).should be_true
|
78
|
+
timer(1) do
|
79
|
+
@stream.reopen(stdout)
|
80
|
+
expected = [
|
81
|
+
{:level => "info", :message => "some info", :foo => "bar"},
|
82
|
+
{:level => "warn", :message => "a warning", :foo => "bar"},
|
83
|
+
{:level => "error", :message => "an error", :foo => "bar"}
|
84
|
+
]
|
85
|
+
file_contents = IO.read(file.path)
|
86
|
+
parsed_contents = file_contents.lines.map do |line|
|
87
|
+
parsed_line = MultiJson.load(line, :symbolize_keys => true)
|
88
|
+
parsed_line.delete(:timestamp)
|
89
|
+
parsed_line
|
90
|
+
end
|
91
|
+
parsed_contents.should eq(expected)
|
92
|
+
async_done
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
it "can write remaining log events to a log file when the eventmachine reactor stops" do
|
98
|
+
stdout = STDOUT.dup
|
99
|
+
file = Tempfile.new("sensu-logger")
|
100
|
+
async_wrapper do
|
101
|
+
@stream.reopen(file.path)
|
102
|
+
1000.times do
|
103
|
+
@stream.info("some info", {:foo => "bar"}).should be_true
|
104
|
+
end
|
105
|
+
EM.stop
|
106
|
+
end
|
107
|
+
@stream.reopen(stdout)
|
108
|
+
IO.read(file.path).split("\n").size.should eq(1000)
|
109
|
+
end
|
110
|
+
end
|
metadata
ADDED
@@ -0,0 +1,144 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sensu-logger
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sean Porter
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-05-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: sensu-em
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: multi_json
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.6'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.6'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: codeclimate-test-reporter
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: The Sensu logger library
|
98
|
+
email:
|
99
|
+
- portertech@gmail.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".gitignore"
|
105
|
+
- ".travis.yml"
|
106
|
+
- Gemfile
|
107
|
+
- LICENSE.txt
|
108
|
+
- README.md
|
109
|
+
- Rakefile
|
110
|
+
- lib/sensu/logger.rb
|
111
|
+
- lib/sensu/logger/constants.rb
|
112
|
+
- lib/sensu/logger/stream.rb
|
113
|
+
- sensu-logger.gemspec
|
114
|
+
- spec/helpers.rb
|
115
|
+
- spec/logger_spec.rb
|
116
|
+
- spec/stream_spec.rb
|
117
|
+
homepage: https://github.com/sensu/sensu-logger
|
118
|
+
licenses:
|
119
|
+
- MIT
|
120
|
+
metadata: {}
|
121
|
+
post_install_message:
|
122
|
+
rdoc_options: []
|
123
|
+
require_paths:
|
124
|
+
- lib
|
125
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
126
|
+
requirements:
|
127
|
+
- - ">="
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: '0'
|
130
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
131
|
+
requirements:
|
132
|
+
- - ">="
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: '0'
|
135
|
+
requirements: []
|
136
|
+
rubyforge_project:
|
137
|
+
rubygems_version: 2.2.0
|
138
|
+
signing_key:
|
139
|
+
specification_version: 4
|
140
|
+
summary: The Sensu logger library
|
141
|
+
test_files:
|
142
|
+
- spec/helpers.rb
|
143
|
+
- spec/logger_spec.rb
|
144
|
+
- spec/stream_spec.rb
|