logiku 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,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ba08b7dc2d0f67611d145921981348c334749443
4
+ data.tar.gz: ce4954d51c4200368f2f2da5e74d89f19c997abe
5
+ SHA512:
6
+ metadata.gz: 9e3f0c4cfe38d297333319d42752641f63b3caf6395e30e39639fe7aa163174c4961d1657f879dbdedfb9cc5016f5c2bd48d7ffe02380a0183bccdb240b923d1
7
+ data.tar.gz: 08fb9fc820ebdfb8240822af378cdc74802124fbf96121b91d3ab84f11eda7c0503d0166ae9160681da92d523ff1643d8b26301cf46beae29d98fc896dcdef98
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /spec/examples.txt
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ # master
2
+
3
+ # 0.0.1
4
+
5
+ * First public versioned release.
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in logiku.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 thilonel
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,71 @@
1
+ # Logiku
2
+ [![Build Status](https://travis-ci.org/BookingSync/Logiku.svg?branch=master)](https://travis-ci.org/BookingSync/Logiku)
3
+
4
+ ## Set up
5
+
6
+ This gem is to be used along with Lograge, so to install add these to your Gemfile:
7
+
8
+ ```ruby
9
+ gem "lograge"
10
+ gem "logiku"
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ I recommend having the same log output for test and production environment, so apply the following settings in `config/environments/test.rb` and `production.rb`:
18
+
19
+ ```ruby
20
+ config.lograge.enabled = true
21
+ config.lograge.formatter = Logiku::Formatters::KeyValue.new
22
+ config.logger = ActiveSupport::Logger.new(config.paths["log"].first)
23
+ config.logger.formatter = Logiku::Normalizers::ActiveSupport.new(Logiku::Formatters::KeyValue.new)
24
+ config.middleware.delete ActionDispatch::DebugExceptions
25
+ config.action_mailer.logger = nil
26
+ config.log_level = :info
27
+ ```
28
+
29
+ And finally let's customize `lograge` a bit, by adding `lograge.rb` to the `initializers`:
30
+
31
+ ```ruby
32
+ Rails.application.configure do
33
+ config.lograge.custom_options = lambda do |event|
34
+ additions = { time: event.time }
35
+
36
+ filtered_params = event.payload[:params].except("controller", "action", "format", "protocol")
37
+ additions[:params] = filtered_params.to_json if filtered_params.present?
38
+
39
+ additions
40
+ end
41
+
42
+ config.lograge.before_format = lambda do |data, payload|
43
+ data.except(:format, :controller, :action)
44
+ end
45
+ end
46
+ ```
47
+
48
+ ## Usage
49
+
50
+ For example if you wish to log `deliver.action_mailer` events, you can do it like this:
51
+ ```ruby
52
+ ActiveSupport::Notifications.subscribe "deliver.action_mailer" do |*args|
53
+ event = ActiveSupport::Notifications::Event.new *args
54
+
55
+ data = {
56
+ event: event.name,
57
+ subject: event.payload[:subject],
58
+ to: event.payload[:to].first
59
+ }
60
+
61
+ Rails.logger.info data
62
+ end
63
+ ```
64
+
65
+ What happens here, is that we pass a `Hash` to `Rails.logger.info`. `Logiku::Normalizers::ActiveSupport` will merge that with `severity, time, progname`, call the formatter passed to it: `Logiku::Formatters::KeyValue.new#call` and this will result in a line like this:
66
+ `"severity"="INFO" "time"="2016-12-02T13:17:37.253203Z" "event"="deliver.action_mailer" "subject"="New HomeAway invoice booking" "to"="email_3@domain.com"`
67
+
68
+ ## License
69
+
70
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
71
+
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 "logiku"
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,26 @@
1
+ module Logiku::Formatters
2
+ class KeyValue
3
+ def call(data)
4
+ "#{data.map { |k, v| format k, v }.join(" ")}\n"
5
+ end
6
+
7
+ private
8
+
9
+ def format(k, v)
10
+ %Q{"#{k}"="#{format_value v}"}
11
+ end
12
+
13
+ def format_value(v)
14
+ case v
15
+ when String
16
+ v.gsub(/["\n]/, { '"' => '\"', "\n" => " " })
17
+ when Hash, Array
18
+ v.inspect.gsub('"') { %q|\"| }
19
+ when Time
20
+ v.utc.iso8601(6)
21
+ else
22
+ v.inspect
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,3 @@
1
+ module Logiku::Formatters
2
+ autoload :KeyValue, "logiku/formatters/key_value"
3
+ end
@@ -0,0 +1,27 @@
1
+ module Logiku::Normalizers
2
+ class ActiveSupport
3
+ def initialize(formatter)
4
+ @formatter = formatter
5
+ end
6
+
7
+ def call(severity, timestamp, progname, message)
8
+ if message.kind_of? String
9
+ message
10
+ else
11
+ data = {
12
+ severity: severity,
13
+ time: timestamp,
14
+ progname: progname
15
+ }
16
+
17
+ data.merge! message if message.kind_of? Hash
18
+
19
+ formatter.call(data.reject { |_, value| value.nil? })
20
+ end
21
+ end
22
+
23
+ private
24
+
25
+ attr_reader :formatter
26
+ end
27
+ end
@@ -0,0 +1,3 @@
1
+ module Logiku::Normalizers
2
+ autoload :ActiveSupport, "logiku/normalizers/active_support"
3
+ end
@@ -0,0 +1,3 @@
1
+ module Logiku
2
+ VERSION = "0.0.1"
3
+ end
data/lib/logiku.rb ADDED
@@ -0,0 +1,6 @@
1
+ require "logiku/version"
2
+
3
+ module Logiku
4
+ autoload :Formatters, "logiku/formatters"
5
+ autoload :Normalizers, "logiku/normalizers"
6
+ end
data/logiku.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'logiku/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "logiku"
8
+ spec.version = Logiku::VERSION
9
+ spec.authors = ["thilonel"]
10
+ spec.email = ["naitodai@gmail.com"]
11
+
12
+ spec.summary = "A log formatter gem."
13
+ spec.description = "At BookingSync, we use this to achieve a lean and consistent log output."
14
+ spec.homepage = "https://github.com/BookingSync/Logiku"
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_development_dependency "bundler", "~> 1"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "rspec", "~> 3.5"
25
+ end
data/travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3
metadata ADDED
@@ -0,0 +1,104 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: logiku
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - thilonel
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-12-02 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'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.5'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.5'
55
+ description: At BookingSync, we use this to achieve a lean and consistent log output.
56
+ email:
57
+ - naitodai@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - CHANGELOG.md
65
+ - Gemfile
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - bin/console
70
+ - bin/setup
71
+ - lib/logiku.rb
72
+ - lib/logiku/formatters.rb
73
+ - lib/logiku/formatters/key_value.rb
74
+ - lib/logiku/normalizers.rb
75
+ - lib/logiku/normalizers/active_support.rb
76
+ - lib/logiku/version.rb
77
+ - logiku.gemspec
78
+ - travis.yml
79
+ homepage: https://github.com/BookingSync/Logiku
80
+ licenses:
81
+ - MIT
82
+ metadata: {}
83
+ post_install_message:
84
+ rdoc_options: []
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ requirements: []
98
+ rubyforge_project:
99
+ rubygems_version: 2.6.6
100
+ signing_key:
101
+ specification_version: 4
102
+ summary: A log formatter gem.
103
+ test_files: []
104
+ has_rdoc: