lograge-sql-one-line 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 60c17b20ae0276e2f43d047ae740a9fae5b3c243
4
+ data.tar.gz: f9e0808cf0d2d06d5341d0394a94f9fb2a3b3880
5
+ SHA512:
6
+ metadata.gz: 8f565022cb1743e616c06f957cac5d6e7d23b392c8296aa14015dce445d90aa9a36de057d076da313fd4b9f5e1db92695d4703fa512aa16bf8ca8a2ff832ef78
7
+ data.tar.gz: 16bb96667c005b4225df04a5bfbc252da481cb890d898353b0def19e61afe6bcdd0d8e9517ecedbcf7e2b76eb6cb6f94f09e64e02ea61568be139e1f4faeabc5
@@ -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
@@ -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
@@ -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
+
@@ -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
@@ -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
@@ -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.inspect }
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.4'
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-one-line'
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', '< 5.2'
24
+
25
+ spec.add_development_dependency 'bundler', '~> 1.0'
26
+ spec.add_development_dependency 'rake', '~> 10.0'
27
+ spec.add_development_dependency 'rspec', '~> 3.0'
28
+ end
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lograge-sql-one-line
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.4
5
+ platform: ruby
6
+ authors:
7
+ - Mattia Giuffrida
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-01-25 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
+ - - "<"
35
+ - !ruby/object:Gem::Version
36
+ version: '5.2'
37
+ type: :runtime
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: '4'
44
+ - - "<"
45
+ - !ruby/object:Gem::Version
46
+ version: '5.2'
47
+ - !ruby/object:Gem::Dependency
48
+ name: bundler
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '1.0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '1.0'
61
+ - !ruby/object:Gem::Dependency
62
+ name: rake
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '10.0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '10.0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: rspec
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '3.0'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '3.0'
89
+ description: An extension for Lograge to log SQL queries
90
+ email:
91
+ - giuffrida.mattia@gmail.com
92
+ executables: []
93
+ extensions: []
94
+ extra_rdoc_files: []
95
+ files:
96
+ - ".gitignore"
97
+ - ".rspec"
98
+ - ".travis.yml"
99
+ - Gemfile
100
+ - README.md
101
+ - Rakefile
102
+ - bin/console
103
+ - bin/setup
104
+ - lib/lograge/sql.rb
105
+ - lib/lograge/sql/extension.rb
106
+ - lib/lograge/sql/version.rb
107
+ - lograge-sql.gemspec
108
+ homepage: https://github.com/iMacTia/lograge-sql
109
+ licenses:
110
+ - MIT
111
+ metadata: {}
112
+ post_install_message:
113
+ rdoc_options: []
114
+ require_paths:
115
+ - lib
116
+ required_ruby_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ required_rubygems_version: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ requirements: []
127
+ rubyforge_project:
128
+ rubygems_version: 2.6.10
129
+ signing_key:
130
+ specification_version: 4
131
+ summary: An extension for Lograge to log SQL queries
132
+ test_files: []