semlogger 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.2
1
+ 0.0.3
@@ -7,7 +7,7 @@ class Semlogger::Rack < Rails::Rack::Logger
7
7
  def call_app env
8
8
  request = ActionDispatch::Request.new env
9
9
  path = request.filtered_path
10
- Rails.logger.info [:connection, request.ip, Thread.current.object_id, request.request_method, path]
10
+ Rails.logger.info Semlogger.custom :connection, request.ip, Thread.current.object_id, request.request_method, path
11
11
  @app.call env
12
12
  ensure
13
13
  ActiveSupport::LogSubscriber.flush_all!
@@ -7,7 +7,7 @@ class Semlogger::Writer < Semlogger::Output
7
7
  end
8
8
 
9
9
  def add severity, time, progname, data, tags, message
10
- @logdev.write [severity, time, progname, data, tags, message].to_json+"\n"
10
+ @logdev.write [severity, time.xmlschema(9), progname, data, tags, message].to_json+"\n"
11
11
  end
12
12
  end
13
13
 
@@ -24,8 +24,7 @@ class Semlogger::Printer < Semlogger::Output
24
24
  r = "Exception: #{message[2]} (#{message[1]}"
25
25
  r << "\n\t" << message[3].join( "\n\t") if message[3]
26
26
  r
27
- when :str, :const then message[1]
28
- when :obj then message[1].inspect
27
+ when :String, :const then message[1]
29
28
  else message.inspect
30
29
  end
31
30
  reqid = data[:reqid]
data/lib/semlogger.rb CHANGED
@@ -1,10 +1,62 @@
1
1
  require 'json'
2
2
 
3
+ class Object
4
+ def to_semlogger
5
+ [self.class.name.to_sym, self.respond_to?( :serializable_hash) ? self.serializable_hash : self ]
6
+ end
7
+ end
8
+
9
+ class Exception
10
+ def to_semlogger
11
+ [:exception] + super
12
+ end
13
+ end
14
+
15
+ class String
16
+ def to_semlogger
17
+ [:String, self]
18
+ end
19
+ end
20
+
21
+ %w[Numeric FalseClass TrueClass NilClass].each do |cl|
22
+ Object.const_get( cl).class_eval do
23
+ def to_semlogger
24
+ [:const, self]
25
+ end
26
+ end
27
+ end
28
+
3
29
  class Semlogger < ::Logger
30
+ class CustomType
31
+ def initialize name, *obj
32
+ @name, @obj = name.to_s.to_sym, obj
33
+ end
34
+
35
+ def to_semlogger
36
+ [@name] + @obj
37
+ end
38
+ end
39
+
40
+ attr_accessor :logdev, :level, :progname
41
+ class <<self
42
+ attr_accessor :progname
43
+
44
+ def custom *a
45
+ CustomType.new *a
46
+ end
47
+ end
48
+
49
+ def custom *a
50
+ CustomType.new *a
51
+ end
52
+
53
+ @@progname = nil
54
+
4
55
  def initialize logdev = nil, *a, &e
5
56
  case logdev
6
57
  when String, nil then logdev = ::Semlogger::Writer.new logdev
7
58
  end
59
+ @progname = a[0] || @@progname
8
60
  @level, @data, @tags, @logdev = DEBUG, {}, [], logdev
9
61
  end
10
62
 
@@ -34,11 +86,10 @@ class Semlogger < ::Logger
34
86
  end
35
87
 
36
88
  def format_msg msg
89
+ msg = msg.to_semlogger
37
90
  case msg
38
- when Numeric, true, false, nil then [:const, msg]
39
- when String then [:str, msg]
40
- when Exception then [:exception, msg.class.name, msg.message.to_s, msg.backtrace]
41
- else [:obj, msg]
91
+ when Array then msg
92
+ else [msg.class.name.to_sym, msg.inspect]
42
93
  end
43
94
  end
44
95
 
@@ -60,6 +111,7 @@ class Semlogger < ::Logger
60
111
  end
61
112
 
62
113
  def data data, &e
114
+ return @data unless e
63
115
  @data.update data
64
116
  keys = data.keys
65
117
  yield
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 2
9
- version: 0.0.2
8
+ - 3
9
+ version: 0.0.3
10
10
  platform: ruby
11
11
  authors:
12
12
  - Denis Knauf
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2012-05-20 00:00:00 +02:00
17
+ date: 2012-05-21 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency