logfoo 0.0.9 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8c5eb9f2b571c4163b6877c14134fcbd0a30608b
4
- data.tar.gz: bac45eec0c78cd8802217a0a0ccc734ef0199f5f
3
+ metadata.gz: 3f635ccd0588d2b30983b1dcf0c5037d62da8239
4
+ data.tar.gz: d44dcf8fe0b1c0128f987836c10595c206c6b0d8
5
5
  SHA512:
6
- metadata.gz: 8c66be1494b10897ac1d3d5bf90c061aa24c9863a7189619cf4acd722c2f4e961a2ef2822653c8d1428e9aa27d8c281635ece8bba9df84189fd1c403f09c670f
7
- data.tar.gz: fdaa2e7761e43749acf3923fabe28eb2a11e24fbf06b6d38039325d71fedc093326f50dcfbedb220200dfedcda1d5378df55a5e55fb5d28155c8a9f20594e392
6
+ metadata.gz: 42cc09fff3d3eeb0d1f354da3311c3a31d2fbb6f9a80a778aec2b94aefec3ffd8a6bddf5364636f3ab60790b78062be5590f811c2da65f35e8bc19a00c8f5bf1
7
+ data.tar.gz: c4b91ae535f8df589a8fb461bee61ab30578e3aa07094dd23150af208edf2920422ee25d9eb316c8c345c7382312b94dfc15b25a830f690155b5bbc176e7a786
data/lib/logfoo/app.rb CHANGED
@@ -46,14 +46,16 @@ module Logfoo
46
46
  begin
47
47
  loop do
48
48
  entry = @queue.pop
49
- if entry == :shutdown
49
+ case entry
50
+ when :shutdown
50
51
  break
51
- end
52
- if entry == :boom
52
+ when :boom
53
53
  raise IGNORE_ME_ERROR
54
+ when ExceptionEntry
55
+ App._handle_exception(entry)
56
+ else
57
+ App._append(entry)
54
58
  end
55
- App._append(entry)
56
- App._handle_exception(entry) if entry.is_a?(ExceptionEntry)
57
59
  end
58
60
  rescue Exception => ex
59
61
  entry = ExceptionEntry.build(self.class, ex)
@@ -2,6 +2,11 @@ module Logfoo
2
2
  class IoAppender
3
3
  def initialize(io = nil, formatter = nil)
4
4
  @io = io || STDOUT
5
+
6
+ if @io.respond_to?(:sync=)
7
+ @io.sync = true
8
+ end
9
+
5
10
  is_tty = @io.respond_to?(:tty?) && @io.tty?
6
11
  @formatter = formatter || (is_tty ? SimpleFormatter.new : LogfmtFormatter.new)
7
12
  end
@@ -1,7 +1,7 @@
1
1
  module Logfoo
2
2
  class Context
3
3
 
4
- attr_reader :level
4
+ attr_reader :level, :scope
5
5
 
6
6
  def initialize(app, scope, context = nil)
7
7
  @app = app
data/lib/logfoo/entry.rb CHANGED
@@ -34,11 +34,12 @@ module Logfoo
34
34
  time: time || Time.now,
35
35
  msg: exception.message,
36
36
  scope: scope,
37
- err: exception.class.to_s,
37
+ exception: exception.class.to_s,
38
38
  }.merge!(
39
39
  payload || {}
40
40
  ).merge!(
41
- thread: thread
41
+ thread: thread,
42
+ backtrace: exception.backtrace,
42
43
  )
43
44
  end
44
45
  end
@@ -1,24 +1,12 @@
1
1
  module Logfoo
2
2
 
3
3
  class StderrExceptionHanlder
4
- BACKTRACE_LINE = "\t%s\n".freeze
5
- EXCEPTION_LINE = "%s: %s\n".freeze
6
-
7
4
  def initialize(appender = nil)
8
5
  @appender = appender || IoAppender.new(STDERR)
9
6
  end
10
7
 
11
8
  def call(entry)
12
- @appender.write format(entry)
13
- end
14
-
15
- def format(entry)
16
- values = []
17
- values << (EXCEPTION_LINE % [entry.exception.class, entry.exception.message])
18
- if entry.exception.backtrace.is_a?(Array)
19
- values << entry.exception.backtrace.map{|l| BACKTRACE_LINE % l }.join
20
- end
21
- values.join
9
+ @appender.call entry
22
10
  end
23
11
  end
24
12
 
@@ -25,17 +25,21 @@ module Logfoo
25
25
  def format_hash(attrs)
26
26
  attrs.inject([]) do |ac, (k,v)|
27
27
  if !IGNORED_KEYS.include?(k) && !(v == nil || v == "")
28
- new_value = sanitize(v)
28
+ new_value = sanitize(k, v)
29
29
  ac << "#{k}=#{new_value}"
30
30
  end
31
31
  ac
32
32
  end.join(" ")
33
33
  end
34
34
 
35
- def sanitize(v)
35
+ def sanitize(k, v)
36
36
  case v
37
37
  when ::Array
38
- may_quote v.map{|i| i.to_s}.join(",")
38
+ if k == :backtrace
39
+ "[" + v.map{|i| may_quote i.to_s}.join(",") + "]"
40
+ else
41
+ may_quote v.map{|i| i.to_s }.join(",")
42
+ end
39
43
  when ::Integer, ::Symbol
40
44
  v.to_s
41
45
  when ::Float
@@ -1,10 +1,32 @@
1
1
  module Logfoo
2
2
  class SimpleFormatter < LogfmtFormatter
3
3
 
4
- FORMAT = "[%5s]: %s -%s%s".freeze
4
+ FORMAT = "[%5s]: %s -%s%s".freeze
5
+ BACKTRACE_LINE = "\t%s\n".freeze
6
+ EXCEPTION_LINE = "%s: %s\n".freeze
5
7
 
6
8
  private
7
9
 
10
+ def format_entry(entry)
11
+ attrs = entry.to_h
12
+ attrs.delete(:backtrace)
13
+ str = []
14
+ str << "#{format_hash(entry.to_h)}\n"
15
+ if entry.is_a?(ExceptionEntry)
16
+ str << format_exception(entry)
17
+ end
18
+ str.join("")
19
+ end
20
+
21
+ def format_exception(entry)
22
+ values = []
23
+ values << (EXCEPTION_LINE % [entry.exception.class, entry.exception.message])
24
+ if entry.exception.backtrace.is_a?(Array)
25
+ values << entry.exception.backtrace.map{|l| BACKTRACE_LINE % l }.join
26
+ end
27
+ values.join
28
+ end
29
+
8
30
  def format_hash(attrs)
9
31
  level = attrs.delete(:level)
10
32
  message = attrs.delete(:msg)
@@ -0,0 +1,16 @@
1
+ module Logfoo
2
+ module Mixin
3
+ def self.included(base)
4
+ base.extend ClassMethods
5
+ base.log = Logfoo.get_logger(base.name)
6
+ end
7
+
8
+ module ClassMethods
9
+ attr_accessor :log
10
+ end
11
+
12
+ def log
13
+ self.class.log
14
+ end
15
+ end
16
+ end
@@ -1,3 +1,3 @@
1
1
  module Logfoo
2
- VERSION = '0.0.9'
2
+ VERSION = '0.0.10'
3
3
  end
data/lib/logfoo.rb CHANGED
@@ -19,6 +19,10 @@ module Logfoo
19
19
  def stop
20
20
  App.instance.stop
21
21
  end
22
+
23
+ def mixin(name: nil)
24
+ Logfoo::Mixin
25
+ end
22
26
  end
23
27
 
24
28
  %w{
@@ -29,6 +33,7 @@ end
29
33
  exception_handlers/stderr_exception_handler
30
34
  app
31
35
  context
36
+ mixin
32
37
  }.each do |f|
33
38
  require File.expand_path("../logfoo/#{f}", __FILE__)
34
39
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logfoo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitry Galinsky
@@ -107,6 +107,7 @@ files:
107
107
  - lib/logfoo/integrations/rack.rb
108
108
  - lib/logfoo/integrations/rack/err.rb
109
109
  - lib/logfoo/integrations/rack/log.rb
110
+ - lib/logfoo/mixin.rb
110
111
  - lib/logfoo/version.rb
111
112
  - logfoo.gemspec
112
113
  homepage: https://github.com/dmexe/logfoo