module Eprint

this file is part of manqod manqod is distributed under the CDDL licence the author of manqod is Dobai-Pataky Balint(dpblnt@gmail.com)

Constants

TERM_COLOUR

Public Instance Methods

ecode(subject) click to toggle source
# File lib/Eprint.rb, line 43
def ecode(subject)
        eprint(subject,Logger::Severity::UNKNOWN)
end
edebug(subject) click to toggle source
# File lib/Eprint.rb, line 24
def edebug(subject)
        eprint(subject,Logger::Severity::DEBUG)
end
eerror(subject) click to toggle source
# File lib/Eprint.rb, line 36
def eerror(subject)
        eprint(subject,Logger::Severity::ERROR)
end
eeval(command,context=self) click to toggle source
# File lib/Eprint.rb, line 75
def eeval(command,context=self)
ret=nil
begin
                if context and b=context.getBinding then
                        ret=eval(command, b)
                        else
                        ret=eval(command)
                end
        rescue SyntaxError, NameError => err
       eexception(err,:command=>command,:context=>context)
end
ret
end
eexception(ex,*args) click to toggle source
# File lib/Eprint.rb, line 64
def eexception(ex,*args)
        eerror("error: #{ex}\n#{ex.backtrace.join("\n")}")
        report_mail(ex,{
                'error'=>ex.inspect,
                'backtrace'=>ex.backtrace.join("\n"),
                'class' => self.class,
                'self'=>self.inspect,
                'arguments' => args.inspect
                })
end
efatal(subject) click to toggle source
# File lib/Eprint.rb, line 39
def efatal(subject)
        eprint(subject,Logger::Severity::FATAL)
end
einfo(subject) click to toggle source
# File lib/Eprint.rb, line 28
def einfo(subject)
        eprint(subject,Logger::Severity::INFO)
end
eprint(subject,level=Logger::Severity::UNKNOWN) click to toggle source
# File lib/Eprint.rb, line 14
def eprint(subject,level=Logger::Severity::UNKNOWN)
        begin
               ManqodLogger.instance.log(level,"\e[1;37m#{self}\e[0m:\e[#{TERM_COLOUR[level]}m#{subject}\e[0m")
       rescue => err
               print("#{err}\n")
               ManqodLogger.instance.set_level("ERROR")
               retry
       end
end
ewarn(subject) click to toggle source
# File lib/Eprint.rb, line 32
def ewarn(subject)
        eprint(subject,Logger::Severity::WARN)
end
getBinding() click to toggle source
# File lib/Eprint.rb, line 89
def getBinding
        binding
end
report_mail(subject, variables) click to toggle source
# File lib/Eprint.rb, line 47
def report_mail(subject, variables)
        return unless ManqodLogger.instance.report_address
        fork{
        begin
        msg="From: manqod@#{Socket.gethostbyname(Socket.gethostname).first}\nTo: #{ManqodLogger.instance.report_address}\nSubject: #{subject}\n"
        variables.each_pair{|k,v| msg="#{msg}\n#{k}: #{v}\n--------------------"}

                Net::SMTP.start('localhost'){ |smtp|
                        smtp.send_message(msg, "manqod_server", ManqodLogger.instance.report_address)
                        einfo("report sent: #{subject} to {ManqodLogger.instance.report_address}")
                }
        rescue => err
                eerror("can't send error report via SMTP")
        end
        }
end