biola_logs 0.1.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6c88ba89e5b0b199c4a3aefb09177eaae64625e8
4
- data.tar.gz: 21aedaa234cc64351544c6beee922066d2f0dd31
3
+ metadata.gz: c26cee0e0e3494d6294520b3e4e28d6129c7fd80
4
+ data.tar.gz: f1ca6c6a8fbb86bb1ac02e9d2bdcc7d53963a1a5
5
5
  SHA512:
6
- metadata.gz: 78d53ecc58bb570425e606fa806968c08efaf4f385f7a9be89b40f46750c7047c9f8f2f9477dfeddfdc32a0ff6ebb747c5fbb435c1cb42f6a086e6484b417cbf
7
- data.tar.gz: eafc64f9f9541a096a3eecff8000c8b12a6c7dbb7de8ae741bbb3ac44afd2dcaeaf5be374dcd5bb5a2b3653c740fc7aef0cbdae89e9a8433e094886d57c6b80e
6
+ metadata.gz: 9fecd0263f8464aad5742b2c4ca21bfd9fdfbbdc5b5f8940f4cf86bd9ae8226674a2156bba09528460a2d8184e5eb5aa4f476e29a15f089b040b817c435a0797
7
+ data.tar.gz: ccb871e2cc83e6db1b7e3166da87bddceb02e2afa70cae1dcd900bf25b692eca70c038557970502f2056bd461877647167534a2e96ff232482a0889448f4ba7a
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  Biola Logs
2
2
  ==========
3
3
 
4
- A simple gem to standardize log formatting across all our Rails apps
4
+ A simple gem to standardize log formatting across all our Rails apps using [lograge](https://github.com/roidrage/lograge).
5
5
 
6
6
  Usage
7
7
  -----
@@ -12,7 +12,31 @@ Add the following to your `Gemfile`
12
12
  gem 'biola_logs'
13
13
  ```
14
14
 
15
- And you're done.
15
+ Biola Logs doesn't include PID and timestamp, so assuming you want those you'll need to add the following to your environment file(s) (eg. /config/environments/production.rb)
16
+
17
+ ```ruby
18
+ # Use default logging formatter so that PID and timestamp are not suppressed.
19
+ config.log_formatter = ::Logger::Formatter.new
20
+ ```
21
+
22
+ To log `session_id`, `request_id` (or uuid), and `host_name` you need to add the following custom variables to payload in your controller. The `Headers` generator will pull these custom variables out and add them to the hash passed to lograge's `custom_options` config method.
23
+
24
+ ```ruby
25
+ # app/controllers/application_controller.rb
26
+ class ApplicationController < ActionController::Base
27
+ def append_info_to_payload(payload)
28
+ super
29
+ payload[:session_id] = request.session_options[:id]
30
+ payload[:uuid] = request.uuid
31
+ payload[:host] = request.host
32
+ end
33
+ end
34
+ ```
35
+
36
+ Generators
37
+ ----------
38
+
39
+ Generators inherit from the `Base` class and should override the `to_hash` method. `Generators.handler` merges the returned hash from each generator to populate `config.lograge.custom_options` in railtie.rb.
16
40
 
17
41
  License
18
42
  -------
data/lib/biola_logs.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'lograge'
2
2
  require 'biola_logs/generators'
3
3
  require 'biola_logs/generators/base'
4
+ require 'biola_logs/generators/headers'
4
5
  require 'biola_logs/generators/params'
5
6
  require 'biola_logs/railtie'
6
7
 
@@ -1,10 +1,15 @@
1
1
  module BiolaLogs
2
2
  module Generators
3
3
  def self.all
4
+ # Class method to get all classes in the BiolaLogs::Generators module
5
+ # returns an Array, skipping BiolaLogs::Generators::Base
6
+ # example: [BiolaLogs::Generators::Params, BiolaLogs::Generators::Headers]
4
7
  self.constants.map(&self.method(:const_get)).grep(Class) - [Base]
5
8
  end
6
9
 
7
10
  def self.handler
11
+ # Class method that returns a hash of key/value pairs for `config.lograge.custom_options`
12
+ # Calls to_hash() on all generators and merges the results into a single hash
8
13
  Proc.new do |event|
9
14
  self.all.each_with_object({}) do |klass, hash|
10
15
  hash.merge! klass.new(event).to_hash
@@ -0,0 +1,37 @@
1
+ module BiolaLogs
2
+ module Generators
3
+ class Headers < Base
4
+
5
+ def to_hash
6
+ if method_supported?
7
+ h = {}
8
+ h[:session_id] = session_id if session_id
9
+ h[:host_name] = host if host
10
+ h[:request_id] = uuid if uuid
11
+ h
12
+ else
13
+ {}
14
+ end
15
+ end
16
+
17
+ private
18
+
19
+ def session_id
20
+ event.payload[:session_id] #requires adding :session_id to payload
21
+ end
22
+
23
+ def uuid
24
+ event.payload[:uuid] #requires adding :uuid to payload
25
+ end
26
+
27
+ def host
28
+ event.payload[:host] #requires adding :host to payload
29
+ end
30
+
31
+ def method_supported?
32
+ # SUPPORTED_HTTP_METHODS.include?(event.payload[:method])
33
+ true
34
+ end
35
+ end
36
+ end
37
+ end
@@ -1,3 +1,3 @@
1
1
  module BiolaLogs
2
- VERSION = '0.1.0'
2
+ VERSION = '0.2.1'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: biola_logs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Crownoble
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-11 00:00:00.000000000 Z
11
+ date: 2016-05-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lograge
@@ -35,6 +35,7 @@ files:
35
35
  - lib/biola_logs.rb
36
36
  - lib/biola_logs/generators.rb
37
37
  - lib/biola_logs/generators/base.rb
38
+ - lib/biola_logs/generators/headers.rb
38
39
  - lib/biola_logs/generators/params.rb
39
40
  - lib/biola_logs/railtie.rb
40
41
  - lib/biola_logs/version.rb