Module: Eprint

Included in:
DrbDb, DrbForm, DrbImages, DrbListModel, DrbRelationBuilder, ManqodServer, MySQL, SQL, Users
Defined in:
lib/Eprint.rb

Overview

this file is part of manqod manqod is distributed under the CDDL licence the author of manqod is Dobai-Pataky Balint([email protected])

Constant Summary collapse

TERM_COLOUR =
{
	Logger::Severity::DEBUG => 33,
	Logger::Severity::INFO => 32,
	Logger::Severity::WARN => 35,
	Logger::Severity::ERROR => 31,
	Logger::Severity::FATAL => 31,
	Logger::Severity::UNKNOWN => 36
}

Instance Method Summary collapse

Instance Method Details

#ecode(subject) ⇒ Object



43
44
45
# File 'lib/Eprint.rb', line 43

def ecode(subject)
	eprint(subject,Logger::Severity::UNKNOWN)
end

#edebug(subject) ⇒ Object



24
25
26
# File 'lib/Eprint.rb', line 24

def edebug(subject)
	eprint(subject,Logger::Severity::DEBUG)
end

#eerror(subject) ⇒ Object



36
37
38
# File 'lib/Eprint.rb', line 36

def eerror(subject)
	eprint(subject,Logger::Severity::ERROR)
end

#eeval(command, context = self) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
87
# 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) ⇒ Object



64
65
66
67
68
69
70
71
72
73
# 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) ⇒ Object



39
40
41
# File 'lib/Eprint.rb', line 39

def efatal(subject)
	eprint(subject,Logger::Severity::FATAL)
end

#einfo(subject) ⇒ Object



28
29
30
# File 'lib/Eprint.rb', line 28

def einfo(subject)
	eprint(subject,Logger::Severity::INFO)
end

#eprint(subject, level = Logger::Severity::UNKNOWN) ⇒ Object



14
15
16
17
18
19
20
21
22
# 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) ⇒ Object



32
33
34
# File 'lib/Eprint.rb', line 32

def ewarn(subject)
	eprint(subject,Logger::Severity::WARN)
end

#getBindingObject



89
90
91
# File 'lib/Eprint.rb', line 89

def getBinding
	binding
end

#report_mail(subject, variables) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# 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