Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adds news parameters to the initialize method on Le::Host::HTTP for loca... #38

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/le.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ def self.new(token, options={})
opt_ssl = options[:ssl] || false
opt_tag = options[:tag] || false
opt_log_level = options[:log_level] || Logger::DEBUG
opt_local_shift_age = options[:local_shift_age] || 0
opt_local_shift_size = options[:local_shift_size] || 1048576

opt_datahub_enabled = options[:datahub_enabled] || false
opt_datahub_endpoint = options[:datahub_endpoint] || ['', 10000]
Expand All @@ -26,15 +28,15 @@ def self.new(token, options={})
self.checkParams(token, opt_datahub_enabled, opt_udp_port)


host = Le::Host.new(token, opt_local, opt_debug, opt_ssl, opt_datahub_endpoint, opt_host_id, opt_custom_host, opt_udp_port)
host = Le::Host.new(token, opt_local, opt_debug, opt_ssl, opt_datahub_endpoint, opt_host_id, opt_custom_host, opt_udp_port, opt_local_shift_age, opt_local_shift_size)

if defined?(ActiveSupport::TaggedLogging) && opt_tag
logger = ActiveSupport::TaggedLogging.new(Logger.new(host))
elsif defined?(ActiveSupport::Logger)
logger = ActiveSupport::Logger.new(host)
logger.formatter = host.formatter if host.respond_to?(:formatter)
else
logger = Logger.new(host)
logger = Logger.new(host, opt_local_shift_age,opt_local_shift_size)
logger.formatter = host.formatter if host.respond_to?(:formatter)
end

Expand Down
4 changes: 2 additions & 2 deletions lib/le/host.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ module Le
module Host

#! def self.new(token, local, debug, ssl, datahub_enabled, datahub_ip, datahub_port, host_id, host_name_enabled, host_name)
def self.new(token, local, debug, ssl, datahub_endpoint, host_id, custom_host, udp_port)
def self.new(token, local, debug, ssl, datahub_endpoint, host_id, custom_host, udp_port, local_shift_age, local_shift_size)

Le::Host::HTTP.new(token, local, debug, ssl, datahub_endpoint, host_id, custom_host, udp_port)
Le::Host::HTTP.new(token, local, debug, ssl, datahub_endpoint, host_id, custom_host, udp_port, local_shift_age, local_shift_size)
end

module InstanceMethods
Expand Down
4 changes: 2 additions & 2 deletions lib/le/host/http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class HTTP
attr_accessor :token, :queue, :started, :thread, :conn, :local, :debug, :ssl, :datahub_enabled, :datahub_ip, :datahub_port, :datahub_endpoint, :host_id, :host_name_enabled, :host_name, :custom_host, :udp_port


def initialize(token, local, debug, ssl, datahub_endpoint, host_id, custom_host, udp_port)
def initialize(token, local, debug, ssl, datahub_endpoint, host_id, custom_host, udp_port, local_shift_age, local_shift_size)
if local
device = if local.class <= TrueClass
if defined?(Rails)
Expand All @@ -32,7 +32,7 @@ def initialize(token, local, debug, ssl, datahub_endpoint, host_id, custom_host,
else
local
end
@logger_console = Logger.new(device)
@logger_console = Logger.new(device, local_shift_age, local_shift_size)
end

@local = !!local
Expand Down
4 changes: 3 additions & 1 deletion test/host_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
let(:datahub_endpoint) { ["", 10000] }
let(:host_id) { ""}
let(:custom_host) { [false, ""]}
let(:local_shift_age) { 0 }
let(:local_shift_size) { 100000 }

#let(:host) { Le::Host.new(token, local, debug, ssl) }
let(:host) { Le::Host.new(token, local, debug, ssl, datahub_endpoint, host_id, custom_host, udp_port)}
let(:host) { Le::Host.new(token, local, debug, ssl, datahub_endpoint, host_id, custom_host, udp_port, local_shift_age, local_shift_size)}
specify { host.must_be_instance_of Le::Host::HTTP }

end
4 changes: 3 additions & 1 deletion test/http_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@
let(:debug) { false }
let(:ssl) { false }
let(:udp) { nil }
let(:local_shift_age) { 0 }
let(:local_shift_size) { 1000000 }

let(:datahub_endpoint) { ["", 10000]}
let(:host_id) {""}
let(:custom_host) {[false, ""]}


# let(:host) { Le::Host::HTTP.new(token, local, debug, ssl) }
let(:host) { Le::Host::HTTP.new(token, local, debug, ssl, datahub_endpoint, host_id, custom_host, udp) }
let(:host) { Le::Host::HTTP.new(token, local, debug, ssl, datahub_endpoint, host_id, custom_host, udp, local_shift_age, local_shift_size) }

let(:logger_console) { host.instance_variable_get(:@logger_console) }
let(:logger_console_dev) { logger_console.instance_variable_get(:@logdev).dev }
Expand Down
22 changes: 21 additions & 1 deletion test/le_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@

let(:token) { '11111111-2222-3333-aaaa-bbbbbbbbbbbb' }
let(:local) { false }
let(:logger) { Le.new(token, local: local) }
let(:local_shift_age) { nil }
let(:local_shift_size) { nil }

let(:logger) { Le.new(token, local: local, local_shift_age: local_shift_age, local_shift_size: local_shift_size) }
let(:logdev) { logger.instance_variable_get(:@logdev).dev }
let(:logger_console) { logdev.instance_variable_get(:@logger_console) }
let(:logger_console_dev) { logger_console.instance_variable_get(:@logdev).dev }
let(:logdev_shift_age) { logger_console.instance_variable_get(:@logdev).instance_variable_get(:@shift_age) }
let(:logdev_shift_size) { logger_console.instance_variable_get(:@logdev).instance_variable_get(:@shift_size) }


describe "when non-Rails environment" do
Expand Down Expand Up @@ -70,6 +75,21 @@

end

describe "and :local_shift_age and :local_shift_size " do
let(:local_test_log) { Pathname.new(File.dirname(__FILE__)).join('fixtures','log','local_log.log') }
let(:log_file) { local_test_log.to_s }
let(:local) { log_file }
let(:local_shift_age) { 1 }
let(:local_shift_size) { 100000 }

describe "local options" do

specify { logdev_shift_age.must_equal 1 }
specify { logdev_shift_size.must_equal 100000 }
end

end

end

describe "when Rails environment" do
Expand Down