rf_logger 0.0.1 → 0.0.2
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/README.md +65 -0
- data/lib/rf_logger/sequel_logger.rb +7 -1
- data/lib/rf_logger/version.rb +1 -1
- data/lib/rf_logger.rb +0 -4
- data/rf_logger.gemspec +1 -1
- data/spec/lib/rf_logger/sequel_logger_spec.rb +4 -0
- data/spec/spec_helper.rb +0 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1d037fd349b2f9bae338bd453fe34222c6461496
|
4
|
+
data.tar.gz: 2fc84efd2d6ceb4b46b7b9bf11ddb85e56fb082a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 28ff40a004c18a7b311d1cc5c99b62bd2f7b9df7ce6a6120137e33d7d298a6d40c45ce5b92a028c30c03009102e3533a627b4c6fa368ad2e147f80b8c55f6250
|
7
|
+
data.tar.gz: f6caa2b848a73042f72d19423c20cc835aaccb1b9c0f3d07e187cc82514e520270ed51293c6e1434d46d97acdd15287b0c398bd835935f1071d372e81f5a7a00
|
data/README.md
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
RF Logger provides a consistent API to log events of different severity levels. Severities include:
|
2
|
+
```
|
3
|
+
:debug # dev-only, for exploring issues
|
4
|
+
:info # end users, to audit process
|
5
|
+
:warn # weird thing happened, but isn't really an issue
|
6
|
+
:error # someone fix the code
|
7
|
+
:fatal # system-wide errors
|
8
|
+
```
|
9
|
+
The API provides helper methods for each severity (i.e. `Logger.debug`). In addition to logging severity levels, the following fields are optional:
|
10
|
+
- actor (The user or caller of the event that you are logging)
|
11
|
+
- action (The event you are logging)
|
12
|
+
- target_type (We use this in cases where we want to tie a log record to a particular entity or object in the database, for example User)
|
13
|
+
- target_id (This is used in conjunction with target_type, as the unique identifier for the relevant entity)
|
14
|
+
- metadata (Additional information such as error details and backtraces or other messages, stored as a hash)
|
15
|
+
|
16
|
+
This gem includes RfLogger::SimpleLogger and RfLogger::Sequel logger as two options that adhere to this API. The fields above should be passed into helper methods as a hash.
|
17
|
+
|
18
|
+
##Configuration##
|
19
|
+
Configuration mostly sets up additional notifications beyond the actual logging.
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
RfLogger.configure do |c|
|
23
|
+
# environment attempts to determine this for Rails, Sinatra, Padrino, and Rory, but is otherwise
|
24
|
+
c.environment = 'production' required
|
25
|
+
# fields from above can be interpolated into the notification subject
|
26
|
+
c.notification_subject = "Oh no! An error of {{level}} severity just occurred."
|
27
|
+
c.set_notifier_list do |n|
|
28
|
+
c.add_notifier Notification::DefinedElsewhere, :levels => [:error], :except => ['test', 'development']
|
29
|
+
c.add_notifier Notification::OhNo, :levels => [:fatal, :error], :only => ['production']
|
30
|
+
c.add_notifer Notifcation:VeryVerbose
|
31
|
+
end
|
32
|
+
end
|
33
|
+
```
|
34
|
+
|
35
|
+
As you seen above, you can specify different notifications for different levels or environments whend you log an event.
|
36
|
+
|
37
|
+
##Notification##
|
38
|
+
While you have to implement notifiers yourself, the API is fairly simple. The class must respond to .send_notification. The argument passed in is an object that includes a #subject (which can be defined in the configuration (see above), and #details, which is the metadata in YAML format. Future versions of this may allow for other transformations of the log data.
|
39
|
+
|
40
|
+
Example:
|
41
|
+
```ruby
|
42
|
+
require 'tinder'
|
43
|
+
module Notification
|
44
|
+
class Campfire
|
45
|
+
class << self
|
46
|
+
def send_error_notification log_info
|
47
|
+
message = log_info.subject + "\n" + log_info.details
|
48
|
+
post_message message
|
49
|
+
end
|
50
|
+
|
51
|
+
def post_message message
|
52
|
+
campfire = Tinder::Campfire.new(config['user'], :token => config['api_token'])
|
53
|
+
room = campfire.find_room_by_id(config['room_id'])
|
54
|
+
room.paste message
|
55
|
+
end
|
56
|
+
|
57
|
+
def config
|
58
|
+
@config ||= YAML.load_file(File.join(Rails.root, 'config/campfire.yml'))
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
```
|
64
|
+
|
65
|
+
|
@@ -1,8 +1,14 @@
|
|
1
|
+
require 'json'
|
1
2
|
module RfLogger
|
2
3
|
class SequelLogger < Sequel::Model
|
3
4
|
class << self
|
5
|
+
def inherited(subclass)
|
6
|
+
subclass.set_dataset underscore(demodulize(subclass.name.pluralize)).to_sym
|
7
|
+
super
|
8
|
+
end
|
9
|
+
|
4
10
|
RfLogger::LEVELS.each do |level|
|
5
|
-
|
11
|
+
define_method level.to_sym do |entry|
|
6
12
|
log = add level, entry
|
7
13
|
|
8
14
|
notification_log = LogForNotification.new(entry.merge(:level => level))
|
data/lib/rf_logger/version.rb
CHANGED
data/lib/rf_logger.rb
CHANGED
@@ -10,10 +10,6 @@ require 'rf_logger/notifications/error_notification_environment_constraints'
|
|
10
10
|
require 'rf_logger/simple_logger'
|
11
11
|
require 'rf_logger/log_for_notification'
|
12
12
|
|
13
|
-
if defined?(Sequel)
|
14
|
-
require 'json'
|
15
|
-
require 'rf_logger/sequel_logger'
|
16
|
-
end
|
17
13
|
|
18
14
|
module RfLogger
|
19
15
|
class UndefinedSetting < StandardError; end
|
data/rf_logger.gemspec
CHANGED
@@ -5,7 +5,7 @@ require 'rf_logger/version'
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = 'rf_logger'
|
8
|
-
s.version = '0.0.
|
8
|
+
s.version = '0.0.2'
|
9
9
|
s.date = '2014-02-20'
|
10
10
|
s.summary = "A logger that adheres to Renewable Funding logging conventions"
|
11
11
|
s.description = "A logger that allows specification of severity, applicable entity/records, metadata, and optional notifications"
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rf_logger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dave Miller
|
@@ -121,6 +121,7 @@ files:
|
|
121
121
|
- .gitignore
|
122
122
|
- .rspec
|
123
123
|
- Gemfile
|
124
|
+
- README.md
|
124
125
|
- Rakefile
|
125
126
|
- lib/rf_logger.rb
|
126
127
|
- lib/rf_logger/configuration.rb
|
@@ -171,4 +172,3 @@ test_files:
|
|
171
172
|
- spec/lib/rf_logger/sequel_logger_spec.rb
|
172
173
|
- spec/lib/rf_logger/simple_logger_spec.rb
|
173
174
|
- spec/spec_helper.rb
|
174
|
-
has_rdoc:
|