lograge-sql 0.1.3

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: d5b7ec9c21300dec6bb5e2a5b3040ef2dbad8ae6
4
+ data.tar.gz: abf2df2d1c420b522252ed4bf0ad422f7bb3bcc9
5
+ SHA512:
6
+ metadata.gz: 5c544e223a47c4074489a1c66b81bd2f5e4a25cf7db02d742d3c219f160b066e22f18f4452f0feb976a961328c30b25b6e4ee35c9ab7bc4741d4b076f282490a
7
+ data.tar.gz: 361dca1b5ea3d2f55f0a425865e41438afda8a66dba5fe7b415212d4fa22bd039a494fa900ae58e7fb06d3f67f2ba4b13496c9a3ffa14757d3cf0f90b4ad6dd5
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ .idea
11
+ *.gem
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
4
+ before_install: gem install bundler -v 1.11.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in lograge-sql.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,28 @@
1
+ # Lograge::Sql
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/lograge-sql.svg)](https://badge.fury.io/rb/lograge-sql) [<img src="https://travis-ci.org/iMacTia/lograge-sql.svg?branch=master" alt="version" />](https://travis-ci.org/iMacTia/lograge-sql)
4
+
5
+ Lograge::Sql is an extension to the famous [Lograge](https://github.com/roidrage/lograge) gem, which adds SQL queries to the Lograge Event and disable default ActiveRecord logging.
6
+ This is extremely useful if you're using Lograge together with the ELK stack.
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'lograge-sql'
14
+ ```
15
+
16
+ ## Usage
17
+
18
+ In order to enable SQL logging in your application, you'll simply need to add this on top of your lograge initializer:
19
+
20
+ ```ruby
21
+ # config/initializers/lograge
22
+ require 'lograge/sql/extension'
23
+ ```
24
+
25
+ ## Contributing
26
+
27
+ Bug reports and pull requests are welcome on GitHub at https://github.com/iMacTia/lograge-sql.
28
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'lograge/sql'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,7 @@
1
+ require 'lograge/sql/version'
2
+
3
+ module Lograge
4
+ module Sql
5
+
6
+ end
7
+ end
@@ -0,0 +1,36 @@
1
+ module Lograge
2
+ module Sql
3
+ module Extension
4
+ def extract_request(event, payload)
5
+ super.merge!(extract_sql_queries)
6
+ end
7
+
8
+ def extract_sql_queries
9
+ sql_queries = Thread.current[:lograge_sql_queries]
10
+ return {} unless sql_queries
11
+
12
+ Thread.current[:lograge_sql_queries] = nil
13
+ { sql_queries: %('#{sql_queries.join("\n")}') }
14
+ end
15
+ end
16
+ end
17
+ end
18
+
19
+ module Lograge
20
+ class ActiveRecordLogSubscriber < ActiveSupport::LogSubscriber
21
+ def sql(event)
22
+ ActiveRecord::LogSubscriber.runtime += event.duration
23
+ return if event.payload[:name] == 'SCHEMA'
24
+ Thread.current[:lograge_sql_queries] ||= []
25
+ Thread.current[:lograge_sql_queries] << ("#{event.payload[:name]} (#{event.duration.to_f.round(2)}) #{event.payload[:sql]}")
26
+ end
27
+ end
28
+ end
29
+
30
+ Lograge::RequestLogSubscriber.prepend Lograge::Sql::Extension
31
+
32
+ ActiveSupport::LogSubscriber.log_subscribers.each do |subscriber|
33
+ Lograge.unsubscribe(:active_record, subscriber) if subscriber.is_a?(ActiveRecord::LogSubscriber)
34
+ end
35
+
36
+ Lograge::ActiveRecordLogSubscriber.attach_to :active_record
@@ -0,0 +1,5 @@
1
+ module Lograge
2
+ module Sql
3
+ VERSION = '0.1.3'
4
+ end
5
+ end
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'lograge/sql/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'lograge-sql'
8
+ spec.version = Lograge::Sql::VERSION
9
+ spec.authors = ['Mattia Giuffrida']
10
+ spec.email = ['giuffrida.mattia@gmail.com']
11
+
12
+ spec.summary = %q{An extension for Lograge to log SQL queries}
13
+ spec.description = %q{An extension for Lograge to log SQL queries}
14
+ spec.homepage = 'https://github.com/iMacTia/lograge-sql'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = 'exe'
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ['lib']
21
+
22
+ spec.add_runtime_dependency 'lograge', '~> 0.4'
23
+ spec.add_runtime_dependency 'activerecord', '~> 4'
24
+
25
+ spec.add_development_dependency 'bundler', '~> 1.11'
26
+ spec.add_development_dependency 'rake', '~> 10.0'
27
+ spec.add_development_dependency 'rspec', '~> 3.0'
28
+ end
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lograge-sql
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.3
5
+ platform: ruby
6
+ authors:
7
+ - Mattia Giuffrida
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-05-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: lograge
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.4'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.4'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activerecord
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '4'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '4'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.11'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.11'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ description: An extension for Lograge to log SQL queries
84
+ email:
85
+ - giuffrida.mattia@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".travis.yml"
93
+ - Gemfile
94
+ - README.md
95
+ - Rakefile
96
+ - bin/console
97
+ - bin/setup
98
+ - lib/lograge/sql.rb
99
+ - lib/lograge/sql/extension.rb
100
+ - lib/lograge/sql/version.rb
101
+ - lograge-sql.gemspec
102
+ homepage: https://github.com/iMacTia/lograge-sql
103
+ licenses:
104
+ - MIT
105
+ metadata: {}
106
+ post_install_message:
107
+ rdoc_options: []
108
+ require_paths:
109
+ - lib
110
+ required_ruby_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ requirements: []
121
+ rubyforge_project:
122
+ rubygems_version: 2.6.11
123
+ signing_key:
124
+ specification_version: 4
125
+ summary: An extension for Lograge to log SQL queries
126
+ test_files: []