lib/logdna.rb in logdna-0.0.4 vs lib/logdna.rb in logdna-0.0.5
- old
+ new
@@ -33,29 +33,42 @@
return false if @open
@conn = HTTP.persistent LogDNA::INGESTER_DOMAIN
@open = true
end
+ def environment
+ @default_app
+ end
+
+ def environment=(env)
+ @default_app = env
+ end
+
private
def fill_opts_with_defaults(opts)
# defaults from ruby standard library logger documentation
opts[:logdev] ||= STDOUT
opts[:shift_age] ||= 7
opts[:shift_size] ||= 1_048_576
+ opts[:environment] ||= nil # alias for :default_app
+ opts[:default_app] ||= opts[:environment]
+ opts[:buffer_max_size] ||= 10
+ opts[:buffer_timeout] ||= 10
opts
end
def set_ivars(api_key, hostname, opts)
raise ArgumentError 'api_key must be a string' unless api_key.is_a?(String)
@api_key = api_key
@host = hostname.to_s
@mac = opts[:mac].to_s
@ip = opts[:ip].to_s
+ @default_app = opts[:default_app] || 'none'
@buffer = []
- @buffer_max = opts[:buffer_max_size] || 10
- @freq = opts[:buffer_timeout] || 10
+ @buffer_max = opts[:buffer_max_size]
+ @freq = opts[:buffer_timeout]
@open = true
end
def post
res = @conn.headers(apikey: @api_key, 'Content-Type' => 'application/json')
@@ -63,11 +76,12 @@
json: { e: 'ls', ls: @buffer })
@buffer = []
res.flush
end
- def push_to_buffer(message, level = nil, source = 'none')
- line = { line: message, app: source, timestamp: Time.now.to_i }
+ def push_to_buffer(message, level = nil, source = nil)
+ app = source || @default_app
+ line = { line: message, app: app, timestamp: Time.now.to_i }
line[:level] = LEVELS[level] if level
start_timer if @buffer.empty?
@buffer << line
return if @buffer.size < @buffer_max
@timer.exit