redis_logstash 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZWU0MWI2ZmU2MzFhNmMyODkyY2MzYTdhZDZiMWU5NTYyOGNkZjI4Ng==
4
+ OTkwNmY5MjRlNDNlZWEzM2RhNWNhNTNmYTk0ZDhhYTcyMzU4NDAxOQ==
5
5
  data.tar.gz: !binary |-
6
- YmE2YmExMTdkMzJlZWI5M2NlNzQ2ZjAzZTg2YWEzNWVhODk4Y2FlMQ==
6
+ ZDkwZjZmZWMyMTczNWFkYjY4YmZjZTkxZGFiN2M2ZTBmMzQzNzM5MA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MjdkYzFkNzFkYjkzNDY1YTIyMTg5ZDc3NTA0YWNmNzhhYjI4NzEzMjUyNDZh
10
- NmQ4OGI4YmRkZDFiMThjYWIxNjMyOTM0ZDdjNTMxOTg0Y2MyNTY1ZTNlZDk5
11
- ZDdmMDA2ODU1NDQwMTM4YThhMDkwZDU3ZTEyZTUzNmFmNjI1MDg=
9
+ NjExNzY5ZmY5YTExM2RkMjRjZmI1NmMxNmI3MmI2NWRiYjU5OWRjZDI0OTcy
10
+ NDY4MzBmZTAwZmUwMThiZGRjYTBkMWQ5MTdlODdjYjRiNzE1NGI0YmU2MDk3
11
+ MzAxOTZkNWQyZTkwZTAxM2RjYjJiM2IwZjcyM2VhYzJiOGNiMWU=
12
12
  data.tar.gz: !binary |-
13
- YjM5YmRkYTNmYzFiMTAwNzEwMzNkOWQ5N2QzMTY4MTE3ZThhMWVjZGExZWMz
14
- MDI0MjQ2NzE1MGUyNTIyMDZhOGVhZmFmN2NjYjkzMzZiZTEyMzM5MzE1Yzc4
15
- NGI0ZTIwZDc3YmYwYTNkMzZhZGU5ZmUyMWQ2NzJiYTZlYjY3MWM=
13
+ MGI2Y2IyOTU3NzhiYTQ0OTgzMmI0ODE0NTZiNjZkYzBhY2E5ZjMzZTAxNGI0
14
+ NDdiNjFjMTU4ZmQxYTQyNTcwN2M2ODIwMDM4N2Q0NDVlODA2YzIzYTM4Njc0
15
+ ZDkwOTJkNGZkMGRhMGE0ODQxYjc0MzVkYzE4NjFmZTU5NzBiYjQ=
@@ -4,4 +4,8 @@ development:
4
4
  port: 6379
5
5
  password: ''
6
6
  key: 'logstash'
7
- type: 'rails-custom-logs'
7
+ type: 'rails-custom-logs'
8
+ logs:
9
+ truncate:
10
+ enabled: true
11
+ length: 10
@@ -1,3 +1,5 @@
1
+ require 'benchmark'
2
+
1
3
  module RedisLogstash
2
4
  module ActionControllerExt
3
5
 
@@ -5,7 +7,6 @@ module RedisLogstash
5
7
 
6
8
  original_params = get_original_params
7
9
  original_flash = get_original_flash
8
- original_headers = request.headers.to_s
9
10
 
10
11
  yield
11
12
 
@@ -16,15 +17,15 @@ module RedisLogstash
16
17
  email: try_current_user_email,
17
18
  params: original_params,
18
19
  flash: original_flash,
19
- headers: original_headers,
20
20
  response_code: response.status,
21
21
  response_message: response.message
22
22
  }
23
23
  RedisLogstash::Logger.write(custom_logs)
24
24
  rescue
25
- Rails.logger.info "Custom Logs not saved: #{custom_logs.to_json}"
25
+ Rails.logger.info "[CUSTOM LOGS NOT SAVED]: #{custom_logs.to_json}"
26
26
  end
27
27
 
28
+
28
29
  end
29
30
 
30
31
  def try_current_user_email
@@ -2,8 +2,54 @@ module RedisLogstash
2
2
  class Logger
3
3
  class << self
4
4
 
5
+ @@options = nil
6
+
5
7
  def write(hash)
6
- Socket.write(hash)
8
+ Socket.write(filter(hash))
9
+ end
10
+
11
+ def filter(hash)
12
+
13
+ if options[:truncate][:enabled]
14
+ hash[:params] = truncate_hash(hash[:params], options[:truncate][:length])
15
+ hash[:flash] = truncate_hash(hash[:flash], options[:truncate][:length])
16
+ end
17
+
18
+ hash[:params] = "#{hash[:params]}"
19
+ hash[:flash] = "#{hash[:flash]}"
20
+
21
+ hash
22
+
23
+ end
24
+
25
+ def options
26
+ @@options ||= ParseConfig.get[:logs]
27
+ end
28
+
29
+ def truncate_hash(hash, length = 15)
30
+ new_hash = {}
31
+
32
+ hash.to_hash.each_pair do |key, value|
33
+ if value.blank?
34
+ new_hash[key] = ''
35
+ elsif value.instance_of? String
36
+ new_hash[key] = value.truncate(length)
37
+ elsif value.instance_of? Hash
38
+ new_hash[key] = truncate_hash(value)
39
+ else
40
+ new_hash[key] = '[R]'
41
+ end
42
+ end
43
+
44
+ new_hash
45
+ end
46
+
47
+ def gzip(source, level=Zlib::DEFAULT_COMPRESSION, strategy=Zlib::DEFAULT_STRATEGY)
48
+ output = StringIO.new("w")
49
+ gz = Zlib::GzipWriter.new(output, level, strategy)
50
+ gz.write(source)
51
+ gz.close
52
+ output.string
7
53
  end
8
54
 
9
55
  end
@@ -30,10 +30,7 @@ module RedisLogstash
30
30
 
31
31
  def push(json)
32
32
  begin
33
-
34
- puts "#{{type: options[:type], message: json.to_json}.to_json}"
35
-
36
- unless redis.rpush(redis_key, {type: options[:type], message: json.to_json}.to_json)
33
+ unless redis.rpush(redis_key, Logger.gzip({type: options[:type], logs: json.to_json}.to_json))
37
34
  raise "could not send event to redis"
38
35
  end
39
36
  rescue ::Redis::InheritedError
@@ -1,3 +1,3 @@
1
1
  module RedisLogstash
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -1,4 +1,7 @@
1
1
  require 'redis'
2
+ require 'zlib'
3
+ require 'stringio'
4
+ require 'json'
2
5
 
3
6
  require "redis_logstash/version"
4
7
  require 'redis_logstash/logger'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redis_logstash
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marek Piechocki