logplexer 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7965fd70bfc4fc76a913352521bfd3235c67bcc7
4
+ data.tar.gz: 90844311c41a23989bea399cddff63e1dd483edd
5
+ SHA512:
6
+ metadata.gz: cf87c80eb8c33bf3944e9f319cf6d35449055e3be42cf801ce05aa90a240b00ddf396aafa2a6562a25803ef6f7b08e43a0e4ec01c508d8c47e170eeed2514f37
7
+ data.tar.gz: af63443d65c27e9b9db5f89b7888f2df574efe1f5224cb835871f3a6d402a60bda4e76e11eb9b18a73fc0ef29807c04df37edba3fcc32647293af55151c7ee98
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
4
+ before_install: gem install bundler -v 1.10.3
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in logplexer.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Ryan Canty
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,115 @@
1
+ # Logplexer - Multiplex all the logs
2
+
3
+ Logplexer allows you to multiplex where your logs go depending on the environment: either standard out, log file or Honeybadger. This can be configured at initialize-time or runtime.
4
+
5
+ By default in a Rails app, it is set to log to standard out in `development` and `test` and log to Honeybadger in any other environment. As log as you have Honeybadger set up in your application this gem will work.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'logplexer', github: "Fullscreen/logplexer"
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ ## Usage
20
+
21
+ Logplexer is a wrapper for `Honeybadger.notify` or Ruby's `Logger` class with all the methods for the typical `Logger` class.
22
+
23
+ If you are in `development`, you can write:
24
+
25
+ ```ruby
26
+ > Logplexer.info( Exception.new("Oh hai!") )
27
+ I, [2015-06-20T15:25:02.182916 #23463] INFO -- : Oh hai!
28
+ => nil
29
+ ```
30
+
31
+ Or in `production`:
32
+
33
+ ```ruby
34
+ > Logplexer.info( Exception.new("Oh hai!") )
35
+ => "684f15d9-c8f6-4ad8-885d-3ee50f612305"
36
+ ```
37
+
38
+ Which will call `Honeybadger.notify()`
39
+
40
+ Inputs can be any type, `Exception`, `String`, `Hash`, etc.
41
+
42
+ If you are in development and would like to log to a logfile, just specify a logfile in the opts argument like so:
43
+
44
+ ```ruby
45
+ > Logplexer.info( "Oh hai!", { logfile: '/Users/ryanc/Desktop/log.txt'} )
46
+ => true
47
+ ```
48
+
49
+ ```bash
50
+ cat ~/Desktop/log.txt
51
+ # Logfile created on 2015-06-20 15:49:16 -0700 by logger.rb/47272
52
+ I, [2015-06-20T15:49:16.040351 #23538] INFO -- : Oh hai!
53
+ ```
54
+
55
+ If you would like to see the whole backtrace, just set `verbose` to true like so:
56
+
57
+ ```ruby
58
+ def method1
59
+ begin
60
+ raise "Holy errors Batman"
61
+ rescue => e
62
+ Logplexer.error( e, { verbose: true} )
63
+ end
64
+ end
65
+
66
+ def method2
67
+ method1
68
+ end
69
+
70
+ def method3
71
+ method2
72
+ end
73
+
74
+ method3
75
+ ```
76
+
77
+ ```
78
+ E, [2015-06-21T16:04:59.247900 #25737] ERROR -- : Holy errors Batman
79
+ E, [2015-06-21T16:04:59.248003 #25737] ERROR -- : > /Users/ryanc/Workspace/test_logplexer/config/initializers/logplexer.rb:6:in `method1'
80
+ E, [2015-06-21T16:04:59.248024 #25737] ERROR -- : > /Users/ryanc/Workspace/test_logplexer/config/initializers/logplexer.rb:13:in `method2'
81
+ E, [2015-06-21T16:04:59.248041 #25737] ERROR -- : > /Users/ryanc/Workspace/test_logplexer/config/initializers/logplexer.rb:17:in `method3'
82
+ ```
83
+
84
+ 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:
85
+
86
+ ENV["LOG_VERBOSE"] = "true"
87
+
88
+ 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.
89
+
90
+ ## Configuration
91
+
92
+ 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".
93
+
94
+ Overriding this behavior is as easy as adding an initializer with the line:
95
+
96
+ ENV['LOG_TO_HB'] = "true"
97
+
98
+ or
99
+
100
+ ENV['LOG_TO_HB'] = "false"
101
+
102
+ ## Development
103
+
104
+ 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.
105
+
106
+ 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).
107
+
108
+ ## Contributing
109
+
110
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/logplexer.
111
+
112
+
113
+ ## License
114
+
115
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "logplexer"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,11 @@
1
+ module Logplexer
2
+ class Railtie < Rails::Railtie
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'
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ module Logplexer
2
+ VERSION = "0.1.0"
3
+ end
data/lib/logplexer.rb ADDED
@@ -0,0 +1,58 @@
1
+ require "logplexer/version"
2
+ require "honeybadger"
3
+ require 'logplexer/railtie' if defined?(Rails)
4
+ require 'logger'
5
+ module Logplexer
6
+
7
+ extend self
8
+
9
+ # Dyamically create all the class log methods for Rails logger
10
+ %W(debug info warn error fatal).each do |log_type|
11
+ class_eval <<-RUBY
12
+ def #{log_type}(exception, opts = {})
13
+ log( exception, "#{log_type}", opts )
14
+ end
15
+ RUBY
16
+ end
17
+
18
+ def log( exception, log_type, opts = {})
19
+ # We wrap the Honeybadger notify call so that in development,
20
+ # we actually see the errors. Then we can unwrap the REST errors
21
+ # if need be
22
+ return if exception.nil?
23
+
24
+ logfile = opts.delete( :logfile )
25
+ logger = Logger.new( logfile || STDOUT )
26
+
27
+ # Override the verbosity if LOG_VERBOSE is unset
28
+ verbose = ENV["LOG_VERBOSE"] == "true" ? true : opts.delete( :verbose )
29
+
30
+ if ENV['LOG_TO_HB'] == "true"
31
+ #TODO: Maybe extend this to include other kinds of notifiers.
32
+ if exception.is_a? String
33
+ exception = { error_class: "Exception",
34
+ error_message: exception }
35
+ end
36
+ Honeybadger.notify( exception, opts )
37
+ else
38
+ # Make sure that the exception is an actual exception and
39
+ # not just a hash since Honeybadger accepts both
40
+ if exception.is_a? Exception
41
+ logger.send( log_type, exception.message )
42
+ if verbose
43
+ exception.backtrace.each do |entry|
44
+ logger.send( log_type, "> #{entry}" )
45
+ end
46
+ end
47
+
48
+ elsif exception.is_a? String
49
+ # Log just the string if thats what the user wants
50
+ logger.send( log_type, exception )
51
+
52
+ else
53
+ # Default kind of log for an object or whatevs
54
+ logger.send( log_type, exception.inspect )
55
+ end
56
+ end
57
+ end
58
+ end
data/logplexer.gemspec ADDED
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'logplexer/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "logplexer"
8
+ spec.version = Logplexer::VERSION
9
+ spec.authors = ["Ryan Canty"]
10
+ spec.email = ["jrcanty@gmail.com"]
11
+
12
+ spec.summary = %q{ Multiplex all the logs }
13
+ spec.description = %q{ Multiplexes logs to different places depending on environment }
14
+ spec.homepage = ""
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.10"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "rspec"
25
+ spec.add_development_dependency "webmock"
26
+ spec.add_development_dependency "vcr"
27
+
28
+ spec.add_runtime_dependency "honeybadger"
29
+ end
metadata ADDED
@@ -0,0 +1,141 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: logplexer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ryan Canty
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-06-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: webmock
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: vcr
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: honeybadger
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: " Multiplexes logs to different places depending on environment "
98
+ email:
99
+ - jrcanty@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rspec"
106
+ - ".travis.yml"
107
+ - Gemfile
108
+ - LICENSE.txt
109
+ - README.md
110
+ - Rakefile
111
+ - bin/console
112
+ - bin/setup
113
+ - lib/logplexer.rb
114
+ - lib/logplexer/railtie.rb
115
+ - lib/logplexer/version.rb
116
+ - logplexer.gemspec
117
+ homepage: ''
118
+ licenses:
119
+ - MIT
120
+ metadata: {}
121
+ post_install_message:
122
+ rdoc_options: []
123
+ require_paths:
124
+ - lib
125
+ required_ruby_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ required_rubygems_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ requirements: []
136
+ rubyforge_project:
137
+ rubygems_version: 2.4.3
138
+ signing_key:
139
+ specification_version: 4
140
+ summary: Multiplex all the logs
141
+ test_files: []