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
- DOMAIN
- LEVEL
Public Instance Methods
ecode(subject,debug_domain="main")
click to toggle source
# File lib/Common/Eprint.rb, line 125 def ecode(subject,debug_domain="main") eprint(subject,debug_domain,"code") end
edebug(subject,debug_domain="main",level="debug",allow_log=false)
click to toggle source
# File lib/Common/Eprint.rb, line 101 def edebug(subject,debug_domain="main",level="debug",allow_log=false) case level when "normal" then enormal(subject,debug_domain) when "warning" then ewarn(subject,debug_domain) when "info" then einfo(subject,debug_domain) when "error" then eerror(subject,debug_domain) else eprint(subject,debug_domain,"debug") end end
eerror(subject,debug_domain="main")
click to toggle source
# File lib/Common/Eprint.rb, line 119 def eerror(subject,debug_domain="main") eprint(subject,debug_domain,"error") end
einfo(subject,debug_domain="main")
click to toggle source
# File lib/Common/Eprint.rb, line 111 def einfo(subject,debug_domain="main") eprint(subject,debug_domain,"info") end
enormal(subject,debug_domain="main")
click to toggle source
# File lib/Common/Eprint.rb, line 122 def enormal(subject,debug_domain="main") eprint(subject,debug_domain,"normal") end
eprint(subject,debug_domain="main",level="normal")
click to toggle source
# File lib/Common/Eprint.rb, line 46 def eprint(subject,debug_domain="main",level="normal") #allow_log should be called only from the tell_exception's log statement to avoid recursivity colour=case level when "error" then 31 when "blue" then 34 when "info" then 32 when "debug" then 33 when "warning" then 35 when "code" then 36 when "white" then 37 when "normal" then 39 end t=Time.now.strftime("%H:%M:%S") if DOMAIN.has_key?(debug_domain) if LEVEL[level] <= LEVEL[DOMAIN[debug_domain]] print "#{t} #{debug_domain}:\e[#{colour}m#{level}\e[0m:\e[1;37m#{self}\e[#{colour}m #{subject}\e[0m\n" end end end
ewarn(subject,debug_domain="main")
click to toggle source
# File lib/Common/Eprint.rb, line 115 def ewarn(subject,debug_domain="main") eprint(subject,debug_domain,"warning") end
gtk_set_edebug()
click to toggle source
# File lib/Common/Eprint.rb, line 72 def gtk_set_edebug dw=Gtk::Dialog.new("Debug",nil,Gtk::Dialog::MODAL,[Gtk::Stock::APPLY,1]) #dw.realize;dw.window.set_functions(Gdk::Window::WMFunction::ALL | Gdk::Window::WMFunction::CLOSE) dw.vbox.pack_start(Gtk::ScrolledWindow.new.add_with_viewport(t=Gtk::Table.new(1,1)).set_size_request(300,600),true,true,0) #set up the combo model model=Gtk::ListStore.new(String,Integer) LEVEL.sort{|a,b|a[1]<=>b[1]}.each{|i| iter=model.append iter[0]=RUBY_VERSION.index("1.8") ? LEVEL.index(i[1]) : LEVEL.key(i[1]) iter[1]=LEVEL[iter[0]] } #set up the debug domain widgets i=0 DOMAIN.sort.each{|key| c=Gtk::ComboBox.new.set_model(model) c.set_name(key[0]) c.signal_connect('changed'){|me| DOMAIN[me.name]=me.active_iter[0] set_conf(0,0,me.name,me.active_iter[0]) } model.each {|model, path, iter| c.set_active(path.indices[0]) if iter[1]==LEVEL[key[1]] } t.attach(Gtk::Label.new(key[0]).set_alignment(0,0.5),0,1,i,i+1,Gtk::EXPAND|Gtk::FILL,Gtk::EXPAND|Gtk::FILL,1,1) t.attach(c,1,2,i,i+1,Gtk::EXPAND|Gtk::FILL,Gtk::EXPAND|Gtk::FILL,1,1) i=i+1 } dw.show_all.run dw.destroy end
set_edebug(debug_domain,level)
click to toggle source
# File lib/Common/Eprint.rb, line 67 def set_edebug(debug_domain,level) DOMAIN[debug_domain]=level self end
tell_exception(subject,details=nil,debug_domain="main",level="normal",allow_log=true,canretry=false,secondary_text=nil)
click to toggle source
# File lib/Common/Eprint.rb, line 129 def tell_exception(subject,details=nil,debug_domain="main",level="normal",allow_log=true,canretry=false,secondary_text=nil) edebug("#{subject}\n#{secondary_text}\n#{details}",debug_domain,level,allow_log) begin ret=nil dialog=Gtk::MessageDialog.new(nil,Gtk::Dialog::Flags::MODAL, case level when "error" then Gtk::MessageDialog::ERROR when "warning" then Gtk::MessageDialog::WARNING when "normal","info" then Gtk::MessageDialog::INFO else Gtk::MessageDialog::OTHER end, if canretry Gtk::MessageDialog::ButtonsType::YES_NO else Gtk::MessageDialog::ButtonsType::CLOSE end, subject) if secondary_text dialog.set_secondary_text(secondary_text) else dialog.set_secondary_text("please report it!") if level == 'error' end dialog.vbox.pack_start(expander=Gtk::Expander.new("details",true).add(Gtk::ScrolledWindow.new.set_size_request(600,300).set_policy(Gtk::POLICY_AUTOMATIC,Gtk::POLICY_AUTOMATIC).add(Gtk::TextView.new(Gtk::TextBuffer.new.set_text(details))))) unless details.nil? dialog.vbox.pack_end(Gtk::Label.new("retry?")) if canretry if level == 'error' dialog.action_area.pack_start(send=Gtk::Button.new("report").set_image(Gtk::Image.new(Gtk::Stock::HELP,Gtk::IconSize::MENU))) send.signal_connect("clicked"){|me,ev| begin ManqodRPC.instance.manqod_server.report_mail(subject, :details =>details.inspect, :more_details=>secondary_text.inspect, :class_name => self.class.name, :self => self.inspect ) rescue => err retry if warn("Reporting failed",err.backtrace.join("\n"),"server","error",false,false,err.to_s) end dialog.action_area.remove(me) } end dialog.show_all ret=dialog.run dialog.destroy ret == Gtk::Dialog::ResponseType::YES rescue end end
Also aliased as: warn
warn(subject,details=nil,debug_domain="main",level="normal",allow_log=true,canretry=false,secondary_text=nil)
Alias for: tell_exception