rf_logger 0.0.1 → 0.0.2

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: 8c1e586db46317c23c8457b60a8825bb8047b2e5
4
- data.tar.gz: 8f88a4b572038809f6db57189c8f37d00107d6ff
3
+ metadata.gz: 1d037fd349b2f9bae338bd453fe34222c6461496
4
+ data.tar.gz: 2fc84efd2d6ceb4b46b7b9bf11ddb85e56fb082a
5
5
  SHA512:
6
- metadata.gz: 8abd4fa0827da81cc264ddcfcd717b06c894e95ddb403e9989c93e88f519e7b458a6691d465426848086884f02f5c542ea1f5c2db8a9d357012980cf4027a43f
7
- data.tar.gz: ce8e7a3778a79b2a4948fed6ad1169a0a46a2218feefad405f150c3080760cecc66d37b331283f513175b245fe3c5bf1c6bfde81c6bbdcbe7884d025c7d8986a
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
- define_method level.to_sym do |entry|
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))
@@ -1,3 +1,3 @@
1
1
  module RfLogger
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
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.1'
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"
@@ -1,3 +1,7 @@
1
+ require 'sequel'
2
+ DB = Sequel.mock
3
+ require File.expand_path( File.dirname( __FILE__ ) + '/../../../lib/rf_logger/sequel_logger' )
4
+
1
5
  describe RfLogger::SequelLogger do
2
6
  before :each do
3
7
  Time.stub(:now => 'NOW')
data/spec/spec_helper.rb CHANGED
@@ -5,9 +5,6 @@ SimpleCov.start
5
5
  # in spec/support/ and its subdirectories.
6
6
  Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
7
7
 
8
- require 'sequel'
9
- DB = Sequel.mock
10
-
11
8
  require './lib/rf_logger'
12
9
 
13
10
  RSpec.configure do |config|
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.1
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: