log_magic 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 142e9bf7993790706efd5abd39ee6d982caf9d68
4
+ data.tar.gz: 47141e7128a5fb074b484d299536f304a043513e
5
+ SHA512:
6
+ metadata.gz: d8cc18c555aae5aa378b51f36a69f70bf250af9b832f707158dd6d3befb4ac75751823e5cd26ce1ec97974e8bcdd5ca64ae01250669b0fc646d2a6153936937f
7
+ data.tar.gz: 75344a1374e3f47403f12ff70ee4d4f2d18254428bb8690b95fcbcf0beb0d0da30ffdf5d5803d9fd615283da1aa7b3cd545a3ac16085c7e83f9161f2276946f7
data/bin/log_magic ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'log_magic'
4
+
5
+ puts ARGV[0]
6
+ log_magic = LogMagic.new(ARGV[0])
7
+ log_magic.initialize_listener
8
+ log_magic.start
data/bin/rebuild ADDED
@@ -0,0 +1,2 @@
1
+ gem build log_magic.gemspec
2
+ gem install log_magic-0.0.0.gem
@@ -0,0 +1,14 @@
1
+ class LogMagic::LogListener
2
+ def initialize(log_file_name)
3
+ @log_file_name = log_file_name
4
+ end
5
+
6
+ def listen
7
+ File.open(@log_file_name) do |log|
8
+ log.extend(File::Tail)
9
+ log.interval = 1
10
+ log.backward(1)
11
+ log.tail { |line| yield line }
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,22 @@
1
+ require 'json'
2
+
3
+ class LogMagic::SearchkickPrinter
4
+ include ::LogMagic::JSONUtils
5
+
6
+ def initialize(line)
7
+ @line = line
8
+ end
9
+
10
+ def extract_query_json
11
+ @line.match(/'.*'/)[0][1..-2]
12
+ end
13
+
14
+ def print
15
+ """
16
+ ElasticSearch query generated by Searchkick
17
+ <------------------------------------------
18
+ #{pretty_print_json(extract_query_json)}
19
+ ------------------------------------------>
20
+ """
21
+ end
22
+ end
@@ -0,0 +1,16 @@
1
+ class LogMagic::SearchkickRefiner
2
+ attr_accessor :lines
3
+
4
+ def initialize
5
+ @lines = []
6
+ end
7
+
8
+ def matches?
9
+ lines.last =~ /Search[^c]*curl/
10
+ end
11
+
12
+ def output
13
+ searchkick_printer = ::LogMagic::SearchkickPrinter.new(lines.last)
14
+ searchkick_printer.print
15
+ end
16
+ end
@@ -0,0 +1,9 @@
1
+ module LogMagic::JSONUtils
2
+ def pretty_print_json(json)
3
+ JSON.pretty_generate(parse_json(json))
4
+ end
5
+
6
+ def parse_json(json)
7
+ JSON.parse(json)
8
+ end
9
+ end
data/lib/log_magic.rb ADDED
@@ -0,0 +1,46 @@
1
+ require 'file-tail'
2
+
3
+ class LogMagic
4
+ def initialize(log_file_name)
5
+ @log_file_name = log_file_name
6
+ @refiners = []
7
+ add_searchkick_refiner
8
+ end
9
+
10
+ def initialize_listener
11
+ @log_listener = LogListener.new(@log_file_name)
12
+ end
13
+
14
+ def start
15
+ @log_listener.listen do |line|
16
+ add_line_to_refiners(line)
17
+ check_for_refiner_output do |output|
18
+ puts output
19
+ end
20
+ end
21
+ end
22
+
23
+ def add_line_to_refiners(line)
24
+ @refiners.each do |refiner|
25
+ refiner.lines << line
26
+ end
27
+ end
28
+
29
+ def check_for_refiner_output
30
+ @refiners.any? do |refiner|
31
+ if refiner.matches?
32
+ yield refiner.output
33
+ end
34
+ end
35
+ end
36
+
37
+ def add_searchkick_refiner
38
+ @refiners << SearchkickRefiner.new
39
+ end
40
+ end
41
+
42
+
43
+ require 'log_magic/utils/json_utils'
44
+ require 'log_magic/log_listener'
45
+ require 'log_magic/refiners/searchkick_refiner'
46
+ require 'log_magic/printers/searchkick_printer'
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: log_magic
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Manuel Korfmann
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-12-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: file-tail
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: byebug
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: "\n By analysing your development.log,\n log_magic gives you insights
42
+ about your services.\n "
43
+ email: manu@korfmann.info
44
+ executables:
45
+ - log_magic
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - bin/log_magic
50
+ - bin/rebuild
51
+ - lib/log_magic.rb
52
+ - lib/log_magic/log_listener.rb
53
+ - lib/log_magic/printers/searchkick_printer.rb
54
+ - lib/log_magic/refiners/searchkick_refiner.rb
55
+ - lib/log_magic/utils/json_utils.rb
56
+ homepage: http://rubygems.org/gems/log_magick
57
+ licenses:
58
+ - MIT
59
+ metadata: {}
60
+ post_install_message:
61
+ rdoc_options: []
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ requirements: []
75
+ rubyforge_project:
76
+ rubygems_version: 2.6.8
77
+ signing_key:
78
+ specification_version: 4
79
+ summary: LogMagic explains your logs
80
+ test_files: []