plogger 0.6.0 → 0.7.0
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 +4 -4
- data/.gitignore +4 -2
- data/.rspec +1 -0
- data/.travis.yml +1 -1
- data/Gemfile +4 -2
- data/README.md +21 -41
- data/bin/console +1 -1
- data/lib/plogger/version.rb +3 -0
- data/lib/{Plogger.rb → plogger.rb} +0 -0
- data/{Plogger.gemspec → plogger.gemspec} +4 -4
- metadata +5 -9
- data/lib/Plogger/config.rb +0 -9
- data/lib/Plogger/formatter.rb +0 -24
- data/lib/Plogger/handler.rb +0 -70
- data/lib/Plogger/id_generator.rb +0 -11
- 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: a24e99ff9521bc048ab680b75e40167c7e16fbff
|
4
|
+
data.tar.gz: a6c6248a29d724b6c3eb3a72ea025c541c590e06
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 169c36b1bb0cab81074afbef97a44748b4e0d13ec1cc80a3c8b7d1e25c6bf332c3448da2b9988f554d4d3747c70ea42b5dbad104ec4e63751fc440c3b91e882b
|
7
|
+
data.tar.gz: 9b0f62923040fadb5cf4868b2e0d49d30bbbab20a10c846bf2c62ab074a7cef0b5c34229276cc4833d312fd0f941c1e520ebbccfafa3bab0ee4a2402ff761a7b
|
data/.gitignore
CHANGED
data/.rspec
CHANGED
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,59 +1,39 @@
|
|
1
1
|
# Plogger
|
2
2
|
|
3
|
-
|
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.
|
4
4
|
|
5
|
-
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
6
|
|
7
|
-
##
|
7
|
+
## Installation
|
8
8
|
|
9
|
-
Add
|
10
|
-
|
11
|
-
## Configuring
|
9
|
+
Add this line to your application's Gemfile:
|
12
10
|
|
13
11
|
```ruby
|
14
|
-
|
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
|
12
|
+
gem 'plogger'
|
22
13
|
```
|
23
14
|
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install plogger
|
22
|
+
|
24
23
|
## Usage
|
25
24
|
|
26
|
-
|
25
|
+
TODO: Write usage instructions here
|
27
26
|
|
28
|
-
|
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
|
-
```
|
27
|
+
## Development
|
39
28
|
|
40
|
-
|
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.
|
41
30
|
|
42
|
-
|
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).
|
43
32
|
|
44
|
-
|
33
|
+
## Contributing
|
45
34
|
|
46
|
-
|
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 | {} |
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/plogger.
|
53
36
|
|
54
|
-
|
37
|
+
## License
|
55
38
|
|
56
|
-
|
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
|
-
```
|
39
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/bin/console
CHANGED
File without changes
|
@@ -1,13 +1,13 @@
|
|
1
|
-
|
2
|
-
lib = File.expand_path(
|
1
|
+
|
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 = ["danielmerrill6@gmail.com"]
|
11
11
|
|
12
12
|
spec.summary = "Phoenix Logging Interface."
|
13
13
|
spec.description = "Provides a standard way to generate logs in the application."
|
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.7.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
|
+
- danielmerrill6@gmail.com
|
72
72
|
executables: []
|
73
73
|
extensions: []
|
74
74
|
extra_rdoc_files: []
|
@@ -78,17 +78,13 @@ files:
|
|
78
78
|
- ".travis.yml"
|
79
79
|
- Gemfile
|
80
80
|
- LICENSE.txt
|
81
|
-
- Plogger.gemspec
|
82
81
|
- README.md
|
83
82
|
- Rakefile
|
84
83
|
- bin/console
|
85
84
|
- bin/setup
|
86
|
-
- lib/
|
87
|
-
- lib/
|
88
|
-
-
|
89
|
-
- lib/Plogger/handler.rb
|
90
|
-
- lib/Plogger/id_generator.rb
|
91
|
-
- lib/Plogger/version.rb
|
85
|
+
- lib/plogger.rb
|
86
|
+
- lib/plogger/version.rb
|
87
|
+
- plogger.gemspec
|
92
88
|
homepage: https://github.com/Papinotas-Desarrollo/Plogger
|
93
89
|
licenses:
|
94
90
|
- MIT
|
data/lib/Plogger/config.rb
DELETED
data/lib/Plogger/formatter.rb
DELETED
@@ -1,24 +0,0 @@
|
|
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
|
data/lib/Plogger/handler.rb
DELETED
@@ -1,70 +0,0 @@
|
|
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
|
data/lib/Plogger/id_generator.rb
DELETED
data/lib/Plogger/version.rb
DELETED