plogger 0.7.0 → 0.8.0

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: a24e99ff9521bc048ab680b75e40167c7e16fbff
4
- data.tar.gz: a6c6248a29d724b6c3eb3a72ea025c541c590e06
3
+ metadata.gz: fc41038c272be6e564f2bc10134e8d2eaf2003b9
4
+ data.tar.gz: 63c6b363aef8983d227fe68c70a2b007152d2e88
5
5
  SHA512:
6
- metadata.gz: 169c36b1bb0cab81074afbef97a44748b4e0d13ec1cc80a3c8b7d1e25c6bf332c3448da2b9988f554d4d3747c70ea42b5dbad104ec4e63751fc440c3b91e882b
7
- data.tar.gz: 9b0f62923040fadb5cf4868b2e0d49d30bbbab20a10c846bf2c62ab074a7cef0b5c34229276cc4833d312fd0f941c1e520ebbccfafa3bab0ee4a2402ff761a7b
6
+ metadata.gz: 159632fb6b98fe904c4a29dfc53b74f749096cdccbeeca222d955ec9c580d908e1a30d46ef2afeb37605b975b190d08bc01ceb00ba9260b5e1b9048c55c9ccc6
7
+ data.tar.gz: d536f5088365d1ae780c7f145f644e6470b9825e41958734c93a08a05c3ea438d8081a261da4909035d040afb02f327c1c48f072b17fb8604bd67dd0a461e0f4
data/.gitignore CHANGED
@@ -1,12 +1,10 @@
1
1
  /.bundle/
2
2
  /.yardoc
3
+ /Gemfile.lock
3
4
  /_yardoc/
4
5
  /coverage/
5
6
  /doc/
6
7
  /pkg/
7
8
  /spec/reports/
8
9
  /tmp/
9
-
10
- # rspec failure tracking
11
- .rspec_status
12
- plogger-*.gem
10
+ plogger-*.gem
data/.rspec CHANGED
@@ -1,3 +1,2 @@
1
1
  --format documentation
2
2
  --color
3
- --require spec_helper
data/.travis.yml CHANGED
@@ -2,4 +2,4 @@ sudo: false
2
2
  language: ruby
3
3
  rvm:
4
4
  - 2.3.0
5
- before_install: gem install bundler -v 1.16.1
5
+ before_install: gem install bundler -v 1.13.6
data/Gemfile CHANGED
@@ -1,6 +1,4 @@
1
- source "https://rubygems.org"
1
+ source 'https://rubygems.org'
2
2
 
3
- git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
-
5
- # Specify your gem's dependencies in plogger.gemspec
3
+ # Specify your gem's dependencies in Plogger.gemspec
6
4
  gemspec
@@ -1,13 +1,13 @@
1
-
2
- lib = File.expand_path("../lib", __FILE__)
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require "plogger/version"
4
+ require 'plogger/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "plogger"
8
8
  spec.version = Plogger::VERSION
9
9
  spec.authors = ["Daniel Merrill"]
10
- spec.email = ["danielmerrill6@gmail.com"]
10
+ spec.email = ["daniel@papinotas.com"]
11
11
 
12
12
  spec.summary = "Phoenix Logging Interface."
13
13
  spec.description = "Provides a standard way to generate logs in the application."
data/README.md CHANGED
@@ -1,39 +1,59 @@
1
1
  # Plogger
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/plogger`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ ## Introduction
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
5
+ Plogger stands for Papinotas Logger or Phoenix Logger (our current project, which raised the need for this gem). Plogger is a simple logging gem which receives a little more information than `Rails.Logger`, and can also send an exception to third party APIs (currently only Raven is supported). Plogger outputs the log in a parser friendly format, ready for other software such as Logstash to process it.
6
6
 
7
- ## Installation
7
+ ## Instalation
8
8
 
9
- Add this line to your application's Gemfile:
9
+ Add `gem 'plogger'` to your gemfile.
10
+
11
+ ## Configuring
10
12
 
11
13
  ```ruby
12
- gem 'plogger'
14
+ # environments/[Environment].rb
15
+ Rails.application.configure do
16
+ Plogger.configure do |config|
17
+ config.logger = ActiveSupport::Logger.new(STDOUT) # Or whatever logger you want to configure
18
+ config.module = 'MainModule' # Optional
19
+ config.raven_dsn = 'http://public:secret@example.com/project-id' # Optional
20
+ end
21
+ end
13
22
  ```
14
23
 
15
- And then execute:
16
-
17
- $ bundle
18
-
19
- Or install it yourself as:
20
-
21
- $ gem install plogger
22
-
23
24
  ## Usage
24
25
 
25
- TODO: Write usage instructions here
26
+ The usage is similar to how you use the Rails Logger, but you can also log exceptions.
26
27
 
27
- ## Development
28
+ ```ruby
29
+ begin
30
+ 1/0
31
+ rescue e
32
+ trace = Plogger.exception(e, category: 'Bundle Creation')
33
+ # => trace = "130AH93MWS2"
34
+ return render "Too bad, an exception was raised. Read the full error at #{trace}"
35
+ end
36
+ trace_2 = Plogger.info("Processing ready", category: 'Bundle Creation')
37
+ render "Your process finished successfully, check the logs at #{trace_2}"
38
+ ```
28
39
 
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
40
+ Plogger has the following methods: `exception`, `error`, `warning`, `info`, `debug`. It will use the logger you supplied in the config to output them, so make sure you have enabled the log level you are trying to use.
30
41
 
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
42
+ ## Params
32
43
 
33
- ## Contributing
44
+ Each of these methods can receive the following keyword params:
34
45
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/plogger.
46
+ | Param | Explanation | Default |
47
+ | ------------- |---------------|-----------|
48
+ | category | Use it to categorize the thing you are logging, so you can later group related logs in Kibana or something |''|
49
+ | type | Use it to manifest if the current log is generated by a system action or a user action | 'system' |
50
+ | user_id | Use it to track the user that is generating the log | ''
51
+ | account_id | In Phoenix we use accounts (a user can have many accounts). You can track that too | '' |
52
+ | extra_info | A hash with additional tags you can print in the log | {} |
36
53
 
37
- ## License
54
+ Example call:
38
55
 
39
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
56
+ ```ruby
57
+ Plogger.info("Processing ready", type: 'user', category: "Bundle Creation", user_id: 1, extra_info: {happy: "yes"})
58
+ # Will output 'Processing ready -- trace=194fjx43gp type='user' category='Bundle Creation' user_id=1 happy='yes'
59
+ ```
data/bin/console CHANGED
@@ -11,4 +11,4 @@ require "plogger"
11
11
  # Pry.start
12
12
 
13
13
  require "irb"
14
- IRB.start(__FILE__)
14
+ IRB.start
File without changes
@@ -0,0 +1,9 @@
1
+ module Plogger
2
+ class Config
3
+ attr_accessor :raven_dsn, :logger, :module
4
+
5
+ def initialize(logger)
6
+ @logger = logger
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,24 @@
1
+ module Plogger
2
+ class Formatter
3
+ def self.format(message, trace, type: 'system', user_id: nil, account_id: nil, category: '', extra_info: {})
4
+ result = "#{message} -- trace='#{trace}'"
5
+ args = {type: type, category: category, user_id: user_id, account_id: account_id}
6
+ args.each do |key, value|
7
+ result = add_param_to_message(result, key, value) unless value.nil?
8
+ end
9
+
10
+ extra_info.keys.each do |key|
11
+ result = add_param_to_message(result, key, extra_info[key])
12
+ end
13
+ result
14
+ end
15
+
16
+ def self.add_param_to_message(message, key, value)
17
+ result = message
18
+ is_string = value.class == String
19
+ result += " #{key}=#{is_string ? "'" : ''}#{value}#{is_string ? "'" : ''}"
20
+ result
21
+ end
22
+
23
+ end
24
+ end
@@ -0,0 +1,70 @@
1
+ require 'plogger/id_generator'
2
+ require 'plogger/formatter'
3
+
4
+ module Plogger
5
+ class Handler
6
+ def initialize(config)
7
+ @logger = config.logger
8
+ @module = config.module
9
+ @raven_dsn = config.raven_dsn
10
+ end
11
+
12
+ def handle_exception(exception, type: '', category: '', user_id: nil, account_id: nil, extra_info: {})
13
+ unless @raven_dsn == nil || @raven_dsn.blank?
14
+ Raven.user_context(id: user_id)
15
+ Raven.tags_context(account_id: account_id)
16
+ Raven.capture_exception(exception)
17
+ end
18
+ handle_error(exception.message, category: category, user_id: user_id, account_id: account_id,
19
+ extra_info: extra_info, type: type)
20
+ end
21
+
22
+ def handle_error(message, type: '', category: '', user_id: '', account_id: '', extra_info: {})
23
+ result = generate_id_and_message(message, category: category, user_id: user_id,
24
+ account_id: account_id, type: type,
25
+ extra_info: generate_extra_info(extra_info))
26
+ @logger.error(result[:message])
27
+ result[:trace]
28
+ end
29
+
30
+ def handle_warning(message, type: '', category: '', user_id: '', account_id: '', extra_info: {})
31
+ result = generate_id_and_message(message, category: category, user_id: user_id,
32
+ account_id: account_id, type: type,
33
+ extra_info: generate_extra_info(extra_info))
34
+ @logger.warn(result[:message])
35
+ result[:trace]
36
+ end
37
+
38
+ def handle_info(message, type: '', category: '', user_id: '', account_id: '', extra_info: {})
39
+ result = generate_id_and_message(message, category: category, user_id: user_id,
40
+ account_id: account_id, type: type,
41
+ extra_info: generate_extra_info(extra_info))
42
+ @logger.info(result[:message])
43
+ result[:trace]
44
+ end
45
+
46
+ def handle_debug(message, type: '', category: '', user_id: '', account_id: '', extra_info: {})
47
+ result = generate_id_and_message(message, category: category, user_id: user_id,
48
+ account_id: account_id, type: type,
49
+ extra_info: generate_extra_info(extra_info))
50
+ @logger.debug(result[:message])
51
+ result[:trace]
52
+ end
53
+
54
+ private
55
+
56
+ def generate_id_and_message(message, type: '', category: '', user_id: '', account_id: '', extra_info: {})
57
+ trace = Plogger::IdGenerator.generate
58
+ formatted_message = Plogger::Formatter.format(message, trace, user_id: user_id,
59
+ account_id: account_id,
60
+ category: category,
61
+ type: type,
62
+ extra_info: extra_info)
63
+ {trace: trace, message: formatted_message}
64
+ end
65
+
66
+ def generate_extra_info extra_info
67
+ extra_info.merge({module: @module})
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,11 @@
1
+ module Plogger
2
+ class IdGenerator
3
+ def self.generate
4
+ [('a'..'z'), ('A'..'Z'), (0..9)].map(&:to_a).flatten.shuffle[0, id_length].join
5
+ end
6
+
7
+ def self.id_length
8
+ 10
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ module Plogger
2
+ VERSION = "0.8.0"
3
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: plogger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Merrill
@@ -68,7 +68,7 @@ dependencies:
68
68
  version: 2.7.1
69
69
  description: Provides a standard way to generate logs in the application.
70
70
  email:
71
- - danielmerrill6@gmail.com
71
+ - daniel@papinotas.com
72
72
  executables: []
73
73
  extensions: []
74
74
  extra_rdoc_files: []
@@ -78,13 +78,17 @@ files:
78
78
  - ".travis.yml"
79
79
  - Gemfile
80
80
  - LICENSE.txt
81
+ - Plogger.gemspec
81
82
  - README.md
82
83
  - Rakefile
83
84
  - bin/console
84
85
  - bin/setup
85
- - lib/plogger.rb
86
- - lib/plogger/version.rb
87
- - plogger.gemspec
86
+ - lib/Plogger.rb
87
+ - lib/Plogger/config.rb
88
+ - lib/Plogger/formatter.rb
89
+ - lib/Plogger/handler.rb
90
+ - lib/Plogger/id_generator.rb
91
+ - lib/Plogger/version.rb
88
92
  homepage: https://github.com/Papinotas-Desarrollo/Plogger
89
93
  licenses:
90
94
  - MIT
@@ -1,3 +0,0 @@
1
- module Plogger
2
- VERSION = "0.7.0"
3
- end