logplexer 0.2.1 → 1.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 768e52baccfd7314fe57214c8a9f919410a22dc5
4
- data.tar.gz: 6c48a6944d90e86d816d90f140bd593b5194636a
3
+ metadata.gz: bcc3206cf4af62b9dd0d52cd06b452bbc0ca550d
4
+ data.tar.gz: aef3f63f7b25ad59d5295a6605a8cdf2f7efe3b7
5
5
  SHA512:
6
- metadata.gz: e5c738748eedfaaa3730a283366adab333aa86c2bd2aaae31ff2b4dc85a02dc8bfb0d2fb5ddfa5a4a8f56916a40d498d274ac90d92b96ddc96c37eab59ae300b
7
- data.tar.gz: 91ef8277db934f6c6b9848d7c1c766e9594f34247824169b3ff6955be1466e87efc5443cdb40ba35abd3aa47d5d81fbded94ffb1a2ee9416bfb3524a2d0a91b1
6
+ metadata.gz: f416893ba08525785f5b347e71ab435668249c7e1edd4629027cb88399684487b393427f85c9834d210a250116d05583b5f68d85ef3b0b49d381ec5b48fbfd3a
7
+ data.tar.gz: 8ad20db7c3fea382781da6b4c73754dab3b701eb550b86c9e7ee953d0464a048ee65c58f9b8ca40f2d30d1521500a6b8392b1a684babcd3ffcc59091207cfee0
data/README.md CHANGED
@@ -47,7 +47,7 @@ Inputs can be any type, `Exception`, `String`, `Hash`, etc.
47
47
  If you are in development and would like to log to a logfile, just specify a logfile in the opts argument like so:
48
48
 
49
49
  ```ruby
50
- > Logplexer.info( "Oh hai!", { logfile: '/Users/ryanc/Desktop/log.txt'} )
50
+ > Logplexer.info( "Oh hai!", logfile: '/Users/ryanc/Desktop/log.txt' )
51
51
  => true
52
52
  ```
53
53
 
@@ -57,6 +57,14 @@ cat ~/Desktop/log.txt
57
57
  I, [2015-06-20T15:49:16.040351 #23538] INFO -- : Oh hai!
58
58
  ```
59
59
 
60
+ If you're using Rails, you can also specify the logger to be the Rails logger. In fact you can specify any class as the logger
61
+ so long as the instance responds to all the message types: `debug`, `info`, `warn`, `error`, and `fatal` which all instances of
62
+ `Logger` will.
63
+
64
+ ```ruby
65
+ > Logplexer.error( "Log to Rails not STDOUT", logger: Rails.logger )
66
+ ```
67
+
60
68
  If you would like to see the whole backtrace, just set `verbose` to true like so:
61
69
 
62
70
  ```ruby
@@ -64,7 +72,7 @@ def method1
64
72
  begin
65
73
  raise "Holy errors Batman"
66
74
  rescue => e
67
- Logplexer.error( e, { verbose: true} )
75
+ Logplexer.error( e, verbose: true )
68
76
  end
69
77
  end
70
78
 
@@ -86,38 +94,34 @@ E, [2015-06-21T16:04:59.248024 #25737] ERROR -- : > /Users/ryanc/Workspace/test_
86
94
  E, [2015-06-21T16:04:59.248041 #25737] ERROR -- : > /Users/ryanc/Workspace/test_logplexer/config/initializers/logplexer.rb:17:in `method3'
87
95
  ```
88
96
 
89
- Or if you are in developmet and would like to have all instances of Logplexer be verbose, just set the environment variable `LOG_VERBOSE` to "true" like so:
90
-
91
- ENV["LOG_VERBOSE"] = "true"
92
-
93
- and everything that isn't specifically marked as `verbose: false` will print the backtrace. Keep in mind that verbose only works when the input is an Exception type.
94
-
95
-
96
- Likewise, if you are in development or test and would like to quiet all logs ( i.e. don't report any Logplexer errors ), just set `LOG_QUIET` to 'true':
97
-
98
- ENV['LOG_QUIET'] = "true"
99
-
100
97
  ## Configuration
101
98
 
102
- If your `RAILS_ENV` is set to `development` or `test`, Logplexer will set an environment variable called `LOG_TO_HB` as "false" if it is anything else, i.e. `production` or `staging`, `LOG_TO_HB` will be set to "true".
99
+ In most cases specifying logfile, logger, etc at the time of the logger call is fine, but I know there are many who need to fine tune their Logplexing capabilities. Logplexer exposes an array of configuration options that you can add to your `config/initializers/logplexer.rb` file.
103
100
 
104
- Overriding this behavior is as easy as adding an initializer with the line:
101
+ A basic example of a logplexer initializer:
105
102
 
106
- ENV['LOG_TO_HB'] = "true"
107
-
108
- or
109
-
110
- ENV['LOG_TO_HB'] = "false"
111
-
112
- ### Overriding log level
103
+ ```ruby
104
+ Logplexer.configure do |config|
105
+ # config.logfile = "my_sexy_log.log" # STDOUT by default, but if you set logger, this will be ignored.
106
+ config.logger = Rails.logger # Logger.new(STDOUT) by default
107
+ config.verbose = Rails.env == "development" # logs the backtrace as well
108
+ # quiet = false # if true, nothing will log (helpful for tests)
109
+ config.honeybadger = false # This tells Logplexer whether or not to log to Honeybadger
110
+ config.min_log_level = :warn # :error by default. Can be ( :debug, :info, :warn, :error, or :fatal )
111
+ end
112
+ ```
113
113
 
114
- By default Logplexer will (as of version 0.2.0) log to Honeybadger only those errors with the log level of `error` or `fatal`. If you would like to adjust this, for example to log errors that are at or above `warn` for instance, just put this line in your: `config/initializers/logplexer.rb`:
114
+ The default initializer is as follows:
115
115
 
116
- ENV['LOG_MIN_HB'] = 'warn' # could also be debug, info, error or fatal
116
+ ```ruby
117
+ Logplexer.configure do |config|
118
+ config.honeybadger = !(Rails.env == 'development' or Rails.env == 'test')
119
+ end
120
+ ```
117
121
 
118
122
  ## Development
119
123
 
120
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
124
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rspec spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
121
125
 
122
126
  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).
123
127
 
data/lib/logplexer.rb CHANGED
@@ -2,33 +2,50 @@ require "logplexer/version"
2
2
  require "honeybadger"
3
3
  require 'logplexer/railtie' if defined?(Rails)
4
4
  require 'logger'
5
- module Logplexer
5
+ require 'logplexer/configuration'
6
+ class LogplexerError < StandardError
7
+ end
6
8
 
9
+ module Logplexer
7
10
  extend self
11
+ attr_writer :config
12
+ def config
13
+ @config ||= Configuration.new
14
+ end
8
15
 
16
+ def configure(&blk)
17
+ yield( config )
18
+ end
9
19
  # Dyamically create all the class log methods for Rails logger
10
20
  %W(debug info warn error fatal).each do |log_type|
11
21
  class_eval <<-RUBY
12
- def #{log_type}(exception, opts = {})
22
+ def #{log_type}(exception, **opts)
13
23
  log( exception, "#{log_type}", opts )
14
24
  end
15
25
  RUBY
16
26
  end
17
27
 
18
- def log( exception, log_level, opts = {})
28
+ def log( exception, log_level, **opts)
19
29
  # We wrap the Honeybadger notify call so that in development,
20
30
  # we actually see the errors. Then we can unwrap the REST errors
21
31
  # if need be
32
+
22
33
  return if exception.nil?
23
- return if ENV['LOG_QUIET'] == 'true'
34
+ return if Logplexer.config.quiet?
35
+
36
+ # If the user specifies a logfile AND a logger in the call, the logger will win out
37
+ logfile = opts.delete( :logfile ) || Logplexer.config.logfile
38
+ logger = opts.delete( :logger ) || Logplexer.config.logger
39
+ unless is_logger?(logger)
40
+ raise LogplexerError, "If specified, logger must be able to respond to :debug, :info, :warn, :error, and :fatal"
41
+ end
24
42
 
25
- logfile = opts.delete( :logfile )
26
- logger = Logger.new( logfile || STDOUT )
43
+ # Override the verbosity if config.verbose is unset
44
+ verbose = opts.delete( :verbose )
45
+ verbose = verbose.nil? ? Logplexer.config.verbose? : verbose
46
+
47
+ if Logplexer.config.honeybadger? && above_min_log_level?( log_level )
27
48
 
28
- # Override the verbosity if LOG_VERBOSE is unset
29
- verbose = ENV["LOG_VERBOSE"] == "true" ? true : opts.delete( :verbose )
30
- if ENV['LOG_TO_HB'] == "true" && above_min_log_level?( log_level )
31
- #TODO: Maybe extend this to include other kinds of notifiers.
32
49
  if exception.is_a? String
33
50
  exception = { error_class: "Exception",
34
51
  error_message: exception }
@@ -56,8 +73,13 @@ module Logplexer
56
73
  end
57
74
  end
58
75
 
76
+ def is_logger?(logger)
77
+ eval( %w(debug info warn error fatal).map do |meth|
78
+ "logger.respond_to?(:#{meth})"
79
+ end.join( ' && ' ) )
80
+ end
59
81
  def above_min_log_level?( p )
60
- min = ENV["LOG_MIN_HB"] || 'error'
82
+ min = Logplexer.config.min_log_level || :error
61
83
  return priority( p ) >= priority( min )
62
84
  end
63
85
 
@@ -0,0 +1,30 @@
1
+ require 'logger'
2
+
3
+ module Logplexer
4
+ class Configuration
5
+ attr_accessor :logger, :verbose, :quiet, :honeybadger, :min_log_level
6
+ attr_reader :logfile
7
+ def initialize
8
+ @logfile = STDOUT
9
+ @logger = Logger.new(STDOUT)
10
+ @verbose = false
11
+ @quiet = false
12
+ @honeybadger = false
13
+ @min_log_level = :error
14
+ end
15
+
16
+ def logfile=( val )
17
+ @logfile = val
18
+ @logger = Logger.new( val )
19
+ @logfile
20
+ end
21
+
22
+ %w(honeybadger quiet verbose).each do |question|
23
+ class_eval <<-RUBY
24
+ def #{question}?
25
+ #{question}
26
+ end
27
+ RUBY
28
+ end
29
+ end
30
+ end
@@ -1,10 +1,8 @@
1
1
  module Logplexer
2
2
  class Railtie < Rails::Railtie
3
3
  initializer "logplexer.configure_rails_initialization" do
4
- if Rails.env == 'development' or Rails.env == 'test'
5
- ENV['LOG_TO_HB'] = 'false'
6
- else
7
- ENV['LOG_TO_HB'] = 'true'
4
+ Logplexer.configure do |config|
5
+ config.honeybadger = !(Rails.env == 'development' or Rails.env == 'test')
8
6
  end
9
7
  end
10
8
  end
@@ -1,3 +1,3 @@
1
1
  module Logplexer
2
- VERSION = "0.2.1"
2
+ VERSION = "1.0.0"
3
3
  end
Binary file
Binary file
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logplexer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Canty
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-06-29 00:00:00.000000000 Z
11
+ date: 2015-11-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -125,9 +125,12 @@ files:
125
125
  - bin/console
126
126
  - bin/setup
127
127
  - lib/logplexer.rb
128
+ - lib/logplexer/configuration.rb
128
129
  - lib/logplexer/railtie.rb
129
130
  - lib/logplexer/version.rb
130
131
  - logplexer-0.1.0.gem
132
+ - logplexer-0.2.1.gem
133
+ - logplexer-0.3.0.gem
131
134
  - logplexer.gemspec
132
135
  homepage: ''
133
136
  licenses: