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 +8 -8
- data/lib/generators/templates/redis_logstash.yml +5 -1
- data/lib/redis_logstash/action_controller_ext.rb +4 -3
- data/lib/redis_logstash/logger.rb +47 -1
- data/lib/redis_logstash/socket.rb +1 -4
- data/lib/redis_logstash/version.rb +1 -1
- data/lib/redis_logstash.rb +3 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
OTkwNmY5MjRlNDNlZWEzM2RhNWNhNTNmYTk0ZDhhYTcyMzU4NDAxOQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZDkwZjZmZWMyMTczNWFkYjY4YmZjZTkxZGFiN2M2ZTBmMzQzNzM5MA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NjExNzY5ZmY5YTExM2RkMjRjZmI1NmMxNmI3MmI2NWRiYjU5OWRjZDI0OTcy
|
10
|
+
NDY4MzBmZTAwZmUwMThiZGRjYTBkMWQ5MTdlODdjYjRiNzE1NGI0YmU2MDk3
|
11
|
+
MzAxOTZkNWQyZTkwZTAxM2RjYjJiM2IwZjcyM2VhYzJiOGNiMWU=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MGI2Y2IyOTU3NzhiYTQ0OTgzMmI0ODE0NTZiNjZkYzBhY2E5ZjMzZTAxNGI0
|
14
|
+
NDdiNjFjMTU4ZmQxYTQyNTcwN2M2ODIwMDM4N2Q0NDVlODA2YzIzYTM4Njc0
|
15
|
+
ZDkwOTJkNGZkMGRhMGE0ODQxYjc0MzVkYzE4NjFmZTU5NzBiYjQ=
|
@@ -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 "
|
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
|
data/lib/redis_logstash.rb
CHANGED