custom_logs 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ MmEyNTcxOWM2NmMxMmVlOGM3Y2U3ZDEwNWQwYWU5ODk0NmRjYzUyNg==
5
+ data.tar.gz: !binary |-
6
+ MDFkM2M3OTY5NzcwYmQ4OTBlZTZmNWJlMjQ0ZWUyOWFiNTUyNzJkMQ==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ ZGRmZTExMmUxZmQxYzIyNDM4ZWRjZDJkNmEwZmI0MmM4YTM1MGE5Y2FmMmJh
10
+ MjcxMDg4MTI3NGYyYzBlNjMxYzRhMDIxYWNlNWMxZTY5YWFjOWMyMzZmZThm
11
+ ODBmMDVlNzE5ZDVjYmI1YWRjMzZhYmY5MzIwOWViZGUyNzg0OTM=
12
+ data.tar.gz: !binary |-
13
+ ZDliZmQ2YTc5OGNjZGMyNmNhMGM2YTg1ODhhYjdkODZmOTJiYjQwZTQ0NzUx
14
+ NWFkYWJkNDQzYTFkZDc2OTA0ZjdmMTEzZGZlZjY1MDZlYzc5ZTZhYTdjZDQw
15
+ OGNmMjk4NTcxOTdjZDMxMTc2MjNjZWFhMTNhZmM2YmIxODc1MjI=
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .idea
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in custom_logs.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Marek Piechocki
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,33 @@
1
+ # CustomLogs
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'custom_logs'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Generate config file:
16
+
17
+ $ rails g custom_logs
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install custom_logs
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Contributing
28
+
29
+ 1. Fork it ( http://github.com/<my-github-username>/custom_logs/fork )
30
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
31
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
32
+ 4. Push to the branch (`git push origin my-new-feature`)
33
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'custom_logs/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "custom_logs"
8
+ spec.version = CustomLogs::VERSION
9
+ spec.authors = ["Marek Piechocki"]
10
+ spec.email = ["work@marek-piechocki.pl"]
11
+ spec.summary = "Add your logs to standard output"
12
+ spec.description = "Add your logs to standard output"
13
+ spec.homepage = "https://github.com/mapiech/custom_logs"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.5"
22
+ spec.add_development_dependency "rake"
23
+ end
@@ -0,0 +1,43 @@
1
+ module CustomLogs
2
+ module ActionControllerExt
3
+
4
+ def custom_logs
5
+
6
+ original_params = get_original_params
7
+ original_flash = get_original_flash
8
+
9
+ yield
10
+
11
+ begin
12
+ logs = {
13
+ controller: params[:controller],
14
+ action: params[:action],
15
+ email: try_current_user_email,
16
+ params: original_params
17
+ #flash: original_flash,
18
+ #response_code: response.status,
19
+ #response_message: response.message
20
+ }
21
+ CustomLogs::Logger.write(logs)
22
+ rescue
23
+ Rails.logger.info "[CUSTOM LOGS NOT SAVED]: #{logs.to_json}"
24
+ end
25
+
26
+
27
+ end
28
+
29
+ def try_current_user_email
30
+ current_user.email rescue ''
31
+ end
32
+
33
+ def get_original_params
34
+ path_params = request.path_parameters
35
+ request.params.clone.except(*path_params.keys)
36
+ end
37
+
38
+ def get_original_flash
39
+ request.flash.clone
40
+ end
41
+
42
+ end
43
+ end
@@ -0,0 +1,49 @@
1
+ module CustomLogs
2
+ class Logger
3
+ class << self
4
+
5
+ @@options = nil
6
+
7
+ def write(hash)
8
+ Socket.write(filter(hash))
9
+ end
10
+
11
+ def filter(hash)
12
+
13
+ # truncate long and not strings values
14
+ if options[:include_params]
15
+ hash[:params] = truncate_hash(hash[:params], options[:truncate_length], options[:truncate_value]).to_json
16
+ else
17
+ hash.delete(:params)
18
+ end
19
+
20
+ hash.to_json
21
+
22
+ end
23
+
24
+ def options
25
+ @@options ||= ParseConfig.get
26
+ end
27
+
28
+ def truncate_hash(hash, length, truncate_value)
29
+ new_hash = {}
30
+
31
+ hash.to_hash.each_pair do |key, value|
32
+ if value.blank?
33
+ new_hash[key] = ''
34
+ elsif value.instance_of? String
35
+ new_hash[key] = value.truncate(length)
36
+ elsif value.instance_of? Hash
37
+ new_hash[key] = truncate_hash(value, length, truncate_value)
38
+ else
39
+ new_hash[key] = truncate_value
40
+ end
41
+ end
42
+
43
+ new_hash
44
+ end
45
+
46
+ end
47
+ end
48
+ end
49
+
@@ -0,0 +1,16 @@
1
+ module CustomLogs
2
+ class ParseConfig
3
+
4
+ @@config = nil
5
+
6
+ class << self
7
+
8
+ def get
9
+ @@config ||= YAML.load_file('config/custom_logs.yml')[Rails.env].with_indifferent_access
10
+ end
11
+
12
+ end
13
+
14
+
15
+ end
16
+ end
@@ -0,0 +1,17 @@
1
+ module CustomLogs
2
+ class Socket
3
+
4
+ @@socket = nil
5
+
6
+ class << self
7
+ def get
8
+ @@socket ||= ::Logger.new(STDOUT)
9
+ end
10
+
11
+ def write(message)
12
+ get.unknown(message)
13
+ end
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,3 @@
1
+ module CustomLogs
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,9 @@
1
+ require "custom_logs/version"
2
+ require 'custom_logs/logger'
3
+ require 'custom_logs/socket'
4
+ require 'custom_logs/parse_config'
5
+ require 'custom_logs/action_controller_ext'
6
+
7
+
8
+ ActionController::Base.send :include, CustomLogs::ActionControllerExt
9
+ ActionController::Base.send :around_filter, :custom_logs
@@ -0,0 +1,10 @@
1
+ class CustomLogsGenerator < Rails::Generators::Base
2
+
3
+ source_root File.expand_path("../templates", __FILE__)
4
+
5
+ desc 'Creating config file for redis logstash'
6
+ def config
7
+ template "custom_logs.yml", 'config/custom_logs.yml'
8
+ end
9
+
10
+ end
@@ -0,0 +1,13 @@
1
+ defaults: &defaults
2
+ include_params: true
3
+ truncate_length: 25
4
+ truncate_value: '[R]'
5
+
6
+ development:
7
+ <<: *defaults
8
+
9
+ production:
10
+ <<: *defaults
11
+
12
+ test:
13
+ <<: *defaults
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: custom_logs
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Marek Piechocki
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
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: Add your logs to standard output
42
+ email:
43
+ - work@marek-piechocki.pl
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - .gitignore
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - custom_logs.gemspec
54
+ - lib/custom_logs.rb
55
+ - lib/custom_logs/action_controller_ext.rb
56
+ - lib/custom_logs/logger.rb
57
+ - lib/custom_logs/parse_config.rb
58
+ - lib/custom_logs/socket.rb
59
+ - lib/custom_logs/version.rb
60
+ - lib/generators/custom_logs_generator.rb
61
+ - lib/generators/templates/custom_logs.yml
62
+ homepage: https://github.com/mapiech/custom_logs
63
+ licenses:
64
+ - MIT
65
+ metadata: {}
66
+ post_install_message:
67
+ rdoc_options: []
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ! '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ! '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubyforge_project:
82
+ rubygems_version: 2.2.1
83
+ signing_key:
84
+ specification_version: 4
85
+ summary: Add your logs to standard output
86
+ test_files: []