lib/logdna.rb in logdna-1.0.8 vs lib/logdna.rb in logdna-1.0.9

- old
+ new

@@ -4,14 +4,15 @@ require_relative 'logdna/client.rb' require_relative 'logdna/resources.rb' module Logdna class Ruby < ::Logger Logger::TRACE = 5 - attr_accessor :level, :app, :env + attr_accessor :level, :app, :env, :meta @level = nil @app = nil @env = nil + @meta = nil def initialize(key, opts={}) @@client = Logdna::Client.new(key, opts) sleep 0.01 @@ -21,60 +22,60 @@ return end end def log(msg=nil, opts={}) - if @level || @app || @env - @@client.change(@level, @app, @env) - @level = nil - @app = nil - @env = nil - end - loggerExist? + optionChanged? @response = @@client.tobuffer(msg, opts) 'Saved' end def trace(msg=nil, opts={}) opts[:level] = "TRACE" loggerExist? + optionChanged? @response = @@client.tobuffer(msg, opts) 'Saved' end def debug(msg=nil, opts={}) opts[:level] = "DEBUG" loggerExist? + optionChanged? @response = @@client.tobuffer(msg, opts) 'Saved' end def info(msg=nil, opts={}) opts[:level] = "INFO" loggerExist? + optionChanged? @response = @@client.tobuffer(msg, opts) 'Saved' end def warn(msg=nil, opts={}) opts[:level] = "WARN" loggerExist? + optionChanged? @response = @@client.tobuffer(msg, opts) 'Saved' end def error(msg=nil, opts={}) opts[:level] = "ERROR" loggerExist? + optionChanged? @response = @@client.tobuffer(msg, opts) 'Saved' end def fatal(msg=nil, opts={}) opts[:level] = "FATAL" loggerExist? + optionChanged? @response = @@client.tobuffer(msg, opts) 'Saved' end def trace? @@ -123,27 +124,48 @@ return 'FATAL' == @@client.getLevel end logLevel('FATAL') end + def clear + loggerExist? + @@client.clear() + @level = nil + @app = nil + @env = nil + @meta = nil + return true + end + def loggerExist? if @@client.nil? puts "Logger Not Initialized Yet" close end end + def optionChanged? + if @level || @app || @env || @meta + @@client.change(@level, @app, @env, @meta) + @level = nil + @app = nil + @env = nil + @meta = nil + end + end + def logLevel(comparedTo) if @level.is_a? Numeric @level = Resources::LOG_LEVELS[@level] end return comparedTo == @level.upcase end def <<(msg=nil, opts={}) opts[:level] = "" loggerExist? + optionChanged? @response = @@client.tobuffer(msg, opts) 'Saved' end def add(*arg) @@ -152,9 +174,10 @@ end def unknown(msg=nil, opts={}) opts[:level] = "UNKNOWN" loggerExist? + optionChanged? @response = @@client.tobuffer(msg, opts) 'Saved' end def datetime_format(*arg)