Class: Logger
- Inherits:
-
Object
- Object
- Logger
- Defined in:
- lib/releaseable/extensions.rb
Overview
Logger extensions
Constant Summary collapse
- INPUTS =
{:default => 'c568432d-8f50-4b12-9322-5f6ffda7883b', :opts => 'b9a22025-b148-4dfe-8355-ce5dba40b6a2', :json => '62a8ef41-fd80-460f-a6f7-e45f232dd1d8', :aux => '207f124e-9de6-434f-b100-af1ac3585089', }
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
Class Method Summary collapse
-
.sound_alarm(beeps = 3) ⇒ Object
Alarm sound to get my attention.
Instance Method Summary collapse
-
#configure(config = {}, &formatter) ⇒ Object
Extended configuration for Logger.
-
#fatal(*args) ⇒ Object
Extended handler for fatal errors.
- #old_fatal ⇒ Object
-
#sound_alarm(beeps = @config[:beeps]) ⇒ Object
Alarm sound on Logger instance.
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
30 31 32 |
# File 'lib/releaseable/extensions.rb', line 30 def config @config end |
Class Method Details
.sound_alarm(beeps = 3) ⇒ Object
Alarm sound to get my attention
33 34 35 36 37 38 |
# File 'lib/releaseable/extensions.rb', line 33 def self.sound_alarm beeps = 3 beeps.times do java.awt.Toolkit.getDefaultToolkit.beep sleep 0.5 end end |
Instance Method Details
#configure(config = {}, &formatter) ⇒ Object
Extended configuration for Logger
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/releaseable/extensions.rb', line 68 def configure config={}, &formatter @config = (config[:log] || config).dup @config[:beeps] ||= 0 @config[:time_format] ||= @config[:time] || '%M:%S.%N' unless @config[:ignore] # fatal errors @config[:progname] = config[:progname] || '' @config[:tag] = config[:tag] || config[:name] || config[:connection] && config[:env] ? "#{config[:env]}#{config[:connection][:client_id]}" : "Tag#{rand(10000)}" input = case @config[:input] when Symbol INPUTS[@config[:input]] when nil INPUTS[:opts] else @config[:input] end domain ||= @config[:domain] || 'https://logs.loggly.com' @config[:fatal] ||= Logglier.new "#{domain}/inputs/#{input}", :read_timeout => 3, :open_timeout => 3, :threaded => true, :format => :json end self.level = @config[:level] || Logger::INFO self.formatter = formatter || proc do |level, time, prog, msg| "#{time.strftime(@config[:time_format])} #{msg}\n" end end |
#fatal(*args) ⇒ Object
Extended handler for fatal errors
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/releaseable/extensions.rb', line 48 def fatal *args if @config && @config[:fatal] entry = args.first case entry when Exception @config[:fatal].fatal :tag => @config[:tag], :error => entry.class, :msg => entry., :backtrace => entry.backtrace.join(', ') else @config[:fatal].info :tag => @config[:tag], :msg => "#{args.join(', ')}" old_fatal *args end else old_fatal *args end end |
#old_fatal ⇒ Object
45 |
# File 'lib/releaseable/extensions.rb', line 45 alias old_fatal fatal |
#sound_alarm(beeps = @config[:beeps]) ⇒ Object
Alarm sound on Logger instance
41 42 43 |
# File 'lib/releaseable/extensions.rb', line 41 def sound_alarm beeps = @config[:beeps] self.class.sound_alarm beeps end |