-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from yssk22/request/fluentd-sink
add fluentd sink ~ Ryan Spore and Tony Hansmann
- Loading branch information
Showing
5 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
require "steno/sink/base" | ||
require "steno/sink/io" | ||
require "steno/sink/syslog" | ||
require "steno/sink/fluentd" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
require 'fluent-logger' | ||
# | ||
# Steno sink implementation for Fluentd | ||
# | ||
# See fluentd at http://fluentd.org/ | ||
# and fluent-logger at https://github.com/fluent/fluent-logger-ruby | ||
# | ||
class Steno::Sink::Fluentd < Steno::Sink::Base | ||
|
||
# @param [Hash] opts Key :tag_prefix tag prefix of fluent logs (default: steno) | ||
# Key :host fluentd host (default: 127.0.0.1) | ||
# Key :port fluentd port (deafult: 24224) | ||
# Key :buffer_limit buffer limit of fluent-logger | ||
def initialize(opts = {}) | ||
super | ||
|
||
@fluentd = Fluent::Logger::FluentLogger.new(opts[:tag_prefix] || "steno", | ||
:host => opts[:host] || "127.0.0.1", | ||
:port => opts[:port] || 24224, | ||
:buffer_limit => opts[:buffer_limit] || Fluent::Logger::FluentLogger::BUFFER_LIMIT) | ||
@io_lock = Mutex.new | ||
end | ||
|
||
def add_record(record) | ||
@fluentd.post(record.source, record) | ||
end | ||
|
||
def flush | ||
nil | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
require "spec_helper" | ||
|
||
describe Steno::Sink::IO do | ||
let(:level) do | ||
Steno::Logger.lookup_level(:info) | ||
end | ||
|
||
let(:record) do | ||
Steno::Record.new("source", level, "message") | ||
end | ||
|
||
describe "#initialize" do | ||
it "should initialize FluentLogger with the default option" do | ||
Fluent::Logger::FluentLogger.should_receive(:new).with("steno", { | ||
:host => "127.0.0.1", | ||
:port => 24224, | ||
:buffer_limit => Fluent::Logger::FluentLogger::BUFFER_LIMIT, | ||
}).and_return() | ||
sink = Steno::Sink::Fluentd.new() | ||
end | ||
|
||
it "should initialize FliuentLogger with override options" do | ||
Fluent::Logger::FluentLogger.should_receive(:new).with("vcap", { | ||
:host => "localhost", | ||
:port => 8080, | ||
:buffer_limit => 1024, | ||
}).and_return() | ||
sink = Steno::Sink::Fluentd.new({ | ||
:tag_prefix => "vcap", | ||
:host => "localhost", | ||
:port => 8080, | ||
:buffer_limit => 1024 | ||
}) | ||
end | ||
end | ||
|
||
describe "#add_record" do | ||
it "should post an record with the correct tag" do | ||
fluentd = mock("fluentd") | ||
Fluent::Logger::FluentLogger.should_receive(:new).and_return(fluentd) | ||
fluentd.should_receive(:post).with("source", record) | ||
sink = Steno::Sink::Fluentd.new() | ||
sink.add_record(record) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters