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 +4 -4
- data/.gitignore +2 -4
- data/.rspec +0 -1
- data/.travis.yml +1 -1
- data/Gemfile +2 -4
- data/{plogger.gemspec → Plogger.gemspec} +4 -4
- data/README.md +41 -21
- data/bin/console +1 -1
- data/lib/{plogger.rb → Plogger.rb} +0 -0
- data/lib/Plogger/config.rb +9 -0
- data/lib/Plogger/formatter.rb +24 -0
- data/lib/Plogger/handler.rb +70 -0
- data/lib/Plogger/id_generator.rb +11 -0
- data/lib/Plogger/version.rb +3 -0
- metadata +9 -5
- data/lib/plogger/version.rb +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fc41038c272be6e564f2bc10134e8d2eaf2003b9
|
4
|
+
data.tar.gz: 63c6b363aef8983d227fe68c70a2b007152d2e88
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 159632fb6b98fe904c4a29dfc53b74f749096cdccbeeca222d955ec9c580d908e1a30d46ef2afeb37605b975b190d08bc01ceb00ba9260b5e1b9048c55c9ccc6
|
7
|
+
data.tar.gz: d536f5088365d1ae780c7f145f644e6470b9825e41958734c93a08a05c3ea438d8081a261da4909035d040afb02f327c1c48f072b17fb8604bd67dd0a461e0f4
|
data/.gitignore
CHANGED
data/.rspec
CHANGED
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
@@ -1,13 +1,13 @@
|
|
1
|
-
|
2
|
-
lib = File.expand_path(
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require
|
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 = ["
|
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
|
-
|
3
|
+
## Introduction
|
4
4
|
|
5
|
-
|
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
|
-
##
|
7
|
+
## Instalation
|
8
8
|
|
9
|
-
Add
|
9
|
+
Add `gem 'plogger'` to your gemfile.
|
10
|
+
|
11
|
+
## Configuring
|
10
12
|
|
11
13
|
```ruby
|
12
|
-
|
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
|
-
|
26
|
+
The usage is similar to how you use the Rails Logger, but you can also log exceptions.
|
26
27
|
|
27
|
-
|
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
|
-
|
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
|
-
|
42
|
+
## Params
|
32
43
|
|
33
|
-
|
44
|
+
Each of these methods can receive the following keyword params:
|
34
45
|
|
35
|
-
|
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
|
-
|
54
|
+
Example call:
|
38
55
|
|
39
|
-
|
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
File without changes
|
@@ -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
|
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.
|
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
|
-
-
|
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/
|
86
|
-
- lib/
|
87
|
-
-
|
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
|
data/lib/plogger/version.rb
DELETED