Sha256: d02a50971bd889d1afed3a4b0b70efc367919c245c53ceec62244b9fd035e05e
Contents?: true
Size: 1.19 KB
Versions: 1
Compression:
Stored size: 1.19 KB
Contents
require 'logger' require 'json' module Zeusd module DaemonLogging def log_file cwd.join('log', 'zeusd.log') end def track(occurred, method, details = nil) logger.info do "\e[35m[Track] [#{occurred.to_s.upcase}] .#{method}()\e[0m" + (details ? " " + JSON.pretty_generate(details) : "") end end def logger @logger ||= Logger.new(log_file.to_path).tap do |l| l.formatter = proc do |severity, datetime, progname, msg| "\e[36m[#{datetime.strftime('%Y-%m-%d %H:%M:%S')}]\e[0m" + " #{msg}\n" end end end def self.included(base) tracked_methods = [:start!, :stop!, :restart!, :start_child_process!] base.instance_eval do tracked_methods.each do |method_name| original_method = instance_method(method_name) track = instance_method(:track) define_method(method_name) do |*args, &block| track.bind(self).call(:before, method_name, :args => args) original_method.bind(self).call(*args, &block).tap do |x| track.bind(self).call(:after, method_name, :return => x) end end end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
zeusd-0.2.5 | lib/zeusd/daemon_logging.rb |