log4r-gelf 0.8.0 → 0.8.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -30,36 +30,60 @@ module Log4r
30
30
  private
31
31
 
32
32
  def canonical_log(logevent)
33
-
33
+
34
+ opts = {}
34
35
  level = LEVELS_MAP[Log4r::LNAMES[logevent.level]]
35
36
  level = GELF::Levels::DEBUG unless level
36
-
37
+ opts[:level] = level
38
+ opts["_logger"] = logevent.fullname
39
+
37
40
  if logevent.data.respond_to?(:backtrace)
38
41
  trace = logevent.data.backtrace
39
42
  if trace
40
- full_msg = trace.join("\n")
41
- file = trace[0].split(":")[0]
42
- line = trace[0].split(":")[1]
43
+ opts[:full_message] = trace.join("\n")
44
+ opts[:file] = trace[0].split(":")[0]
45
+ opts[:line] = trace[0].split(":")[1]
43
46
  end
44
47
  end
45
48
 
46
49
  if logevent.tracer
47
50
  trace = logevent.tracer.join("\n")
48
- full_msg = "#{full_msg}\nLog tracer:\n#{trace}"
49
- file = logevent.tracer[0].split(":")[0]
50
- line = logevent.tracer[0].split(":")[1]
51
+ opts[:full_message] = "#{opts[:full_message]}\nLog tracer:\n#{trace}"
52
+ opts[:file] = logevent.tracer[0].split(":")[0]
53
+ opts[:line] = logevent.tracer[0].split(":")[1]
54
+ end
55
+
56
+ gdc = Log4r::GDC.get
57
+ if gdc && gdc != $0
58
+ begin
59
+ opts["_global_context"] = gdc.inspect
60
+ rescue
61
+ end
62
+ end
63
+
64
+ if Log4r::NDC.get_depth > 0
65
+ Log4r::NDC.clone_stack.each_with_index do |x, i|
66
+ begin
67
+ opts["_nested_context_#{i}"] = x.inspect
68
+ rescue
69
+ end
70
+ end
51
71
  end
52
72
 
73
+ mdc = Log4r::MDC.get_context
74
+ if mdc && mdc.size > 0
75
+ mdc.each do |k, v|
76
+ begin
77
+ opts["_mapped_context_#{k}"] = v.inspect
78
+ rescue
79
+ end
80
+ end
81
+ end
82
+
53
83
  synch do
54
- msg = format(logevent)
84
+ opts[:short_message] = format(logevent)
55
85
 
56
- @notifier.notify!(
57
- :short_message => msg,
58
- :full_message => full_msg,
59
- :level => level,
60
- :file => file,
61
- :line => line
62
- )
86
+ @notifier.notify!(opts)
63
87
  end
64
88
  rescue => err
65
89
  puts "Graylog2 logger. Could not send message: " + err.message
@@ -1,5 +1,5 @@
1
1
  module Log4r
2
2
  module Gelf
3
- VERSION = "0.8.0"
3
+ VERSION = "0.8.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: log4r-gelf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.8.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: