lib/jsus.rb in jsus-0.3.3 vs lib/jsus.rb in jsus-0.3.4

- old
+ new

@@ -20,10 +20,11 @@ autoload :Container, 'jsus/container' autoload :Packager, 'jsus/packager' autoload :Pool, 'jsus/pool' autoload :Util, 'jsus/util' autoload :Middleware, 'jsus/middleware' + autoload :Compressor, 'jsus/compressor' # In verbose mode jsus shows a lot of warnings like missing dependencies. # Default: false # # @return [Boolean] jsus verbosity mode @@ -35,10 +36,11 @@ # @see .verbose? # @param [Boolean] verbose verbose verbosity mode # @api public def self.verbose=(verbose) @verbose = verbose + logger.level = verbose ? Logger::DEBUG : Logger::ERROR end # @return [String] Jsus version # @api public def self.version @@ -61,6 +63,29 @@ # @see .look_for_cycles? # @param [Boolean] def self.look_for_cycles=(value) @look_for_cycles = value end + + # Jsus logger used for all the output. By default uses Logger::ERROR level + # severity and screen as output device. + # + # @return [Jsus::Util::Logger] + def self.logger + Thread.current[:jsus_logger] ||= Jsus::Util::Logger.new(STDOUT).tap do |logger| + logger.level = Logger::ERROR + logger.formatter = lambda {|severity, time, progname, msg| + "[#{time.strftime("%Y-%m-%d %H:%M:%S")}] [JSUS:#{severity}] #{msg}\n" + } + end + end # self.logger + + # Reassign jsus logger whenever needed (E.g. use rails logger) + # + # @param value Logger responding to #info, #warn, #debug, #error, #fatal, + # and #buffer + # @note In case you use non-jsus logger, you might want to extend it with + # Jsus::Util::Logger::Buffering module. + def self.logger=(value) + Thread.current[:jsus_logger] = value + end # self.logger= end