Sha256: 660601e8b40bc136051645eea108af8de96d6e081d113e8de6a6242d4970bb9e
Contents?: true
Size: 1.19 KB
Versions: 1
Compression:
Stored size: 1.19 KB
Contents
module Fasten class << self attr_accessor :logger end module LogSupport %w[debug info error].each do |method| define_method "log_#{method}" do |msg| return unless Fasten.logger.respond_to?(method) caller_name = name if respond_to? :name caller_name ||= Kernel.binding.of_caller(1).eval('self').class Fasten.logger.send(method, caller_name) { msg } end end def log_ini(object, message = nil) object.ini ||= Time.new log_info "Init #{object.class} #{object} #{message}" end def log_fin(object, message = nil) object.fin ||= Time.new diff = object.fin - object.ini log_info "Done #{object.class} #{object} #{message} in #{diff}" end def redirect_std(path) @saved_stdout = $stdout.clone @saved_stderr = $stderr.clone FileUtils.mkdir_p File.dirname(path) log = File.new path, 'a' $stdout.reopen log $stderr.reopen log end def restore_std $stdout.reopen(@saved_stdout) $stderr.reopen(@saved_stderr) end end end Fasten.logger ||= begin Logger.new(STDOUT, level: Logger::INFO, progname: $PROGRAM_NAME) rescue StandardError nil end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
fasten-0.2.0 | lib/fasten/log_support.rb |