bamm_log 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ MjYxNTE0ZjU1ZGEzYjg0MWJmOWU2MzI2YjJhYzkyNzgzNzdmZDA3YQ==
5
+ data.tar.gz: !binary |-
6
+ MDgyNWU5NDFiOTE2N2QxOGEwZjc5YTBkODQ1NmIwMDA5ZGE3OTg2MQ==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ NTAzMjU1NjE2NGVlYjc5YTk3Mjg4NDFiMjIyZmI4MWM3MmYwNmQ1NmQ0Nzk1
10
+ ZDA0N2ViOTQwZDk2NzA1NDRhOGQyMjA2ZWExYTM3YzY4N2JmMWExM2RlNzIy
11
+ NjJmOWQ2Nzk1ZTAyODdjOTc0ZGQ1ZWUxODgzZWUwYWQzMzBkNTg=
12
+ data.tar.gz: !binary |-
13
+ NDJmOTA4MjUwNmFiOTFkZjMzZjAwYjllNjEwMzE3OTgyOWVkZmMwY2UzOTU4
14
+ NTJlMjNkZGZlZjM1OGUyZDE3OTlkNTQyNDc0Mzc3YjUyMmQxMTZjM2YwMWYy
15
+ Y2JmMjkxY2RlNWI0MjhmNGNhMjkxMTlmYjVmNDFhZmY2ZDhlZGI=
data/LICENCE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 joaquimadraz
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,75 @@
1
+ # Bamm Log
2
+
3
+ Who doen't need to log what's going on in your Modular Sinatra App? Well.. I need.
4
+ By default sinatra logs this:
5
+
6
+
7
+ > <sub>127.0.0.1 - - [25/Aug/2014 17:23:11] "GET /page HTTP/1.1" 200 6736 2.5322</sub><br />
8
+ > <sub>127.0.0.1 - - [25/Aug/2014 17:24:33] "POST /create HTTP/1.1" 200 5833 0.0198</sub>
9
+
10
+
11
+ /create with which params?
12
+
13
+ > <sub>127.0.0.1 - - [25/Aug/2014 17:24:33] "POST /error HTTP/1.1" 500 5443 0.1238</sub>
14
+
15
+ This page returns 500 for what? You can check our apage error.log file or you can log everything in one file, like Rails!
16
+
17
+
18
+ After reading some implementations, I joined some ideas and created this gem.
19
+ It's not tested yet, so.. don't use it on production.
20
+
21
+
22
+ > <sub>[2014-08-25 16:03:43 +0000] Started GET "/page?page=1&per_page=99"</sub><br />
23
+ > <sub>[2014-08-25 16:03:43 +0000] Parameters: {"page"=>"1", "per_page"=>"99"}</sub>
24
+
25
+
26
+ > <sub>[2014-08-25 17:36:59 +0000] Started POST "/create"</sub><br />
27
+ > <sub>[2014-08-25 17:36:59 +0000] Parameters: {"page"=>{ "title" => "Nice and Clean" }}</sub>
28
+
29
+
30
+ > <sub>[2014-08-25 17:36:59 +0100] Started GET "/v0/page?page=1&per_page=99"</sub><br />
31
+ > <sub>[2014-08-25 17:36:59 +0100] Parameters: {"page"=>"1", "per_page"=>"99"}</sub><br />
32
+ > <sub>[2014-08-25 17:37:05 +0100] Bamm! RuntimeError: bamm error</sub><br />
33
+ > <sub>[2014-08-25 17:37:05 +0100] /app/routes/page.rb:4:in `block in <class:App>'</sub>
34
+
35
+ > <sub>extended backtrace...</sub>
36
+
37
+ ## Installation
38
+
39
+ Add this line to your application's Gemfile:
40
+
41
+ gem 'bamm_log'
42
+
43
+ And then execute:
44
+
45
+ $ bundle
46
+
47
+ Or install it yourself as:
48
+
49
+ $ gem install bamm_log
50
+
51
+ ## Usage
52
+
53
+ class RequisitionsService < Sinatra::Base
54
+
55
+ configure :staging do
56
+ include BammLog::Logger
57
+ end
58
+
59
+ # if you want to user logger in your application,
60
+ # being logged to the same "environment".log file
61
+ def logger
62
+ BammLog.logger
63
+ end
64
+
65
+ end
66
+
67
+ This will create a file with the name "environment".log (ex: staging.log) and log all the accesses and errors from you application.
68
+
69
+ ## Contributing
70
+
71
+ 1. Fork it ( http://github.com/joaquimadraz/bamm_log/fork )
72
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
73
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
74
+ 4. Push to the branch (`git push origin my-new-feature`)
75
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/hola.gemspec ADDED
@@ -0,0 +1,21 @@
1
+ # encoding: UTF-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'bamm_log/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "bamm_log"
8
+ spec.version = BammLog::VERSION
9
+ spec.authors = ["Joaquim Adráz"]
10
+ spec.email = ["joaquim.adraz@gmail.com"]
11
+ spec.summary = %q{Not so experimental Sinatra Logger}
12
+ spec.homepage = "https://github.com/joaquimadraz/bamm_log"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files`.split($/)
16
+ spec.executables = spec.files.grep(%r{^bin/bamm_log}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "pry"
21
+ end
@@ -0,0 +1,40 @@
1
+ module BammLog
2
+ class ExceptionMiddleware
3
+
4
+ def initialize(app, options={})
5
+ @app = app
6
+ end
7
+
8
+ def call(env)
9
+
10
+ begin
11
+ BammLog.logger.info "Started #{env['REQUEST_METHOD']} \"#{env['REQUEST_URI']}\""
12
+ BammLog.logger.info "Parameters: #{request_params(env).inspect}"
13
+ @app.call(env)
14
+ rescue Exception => e
15
+ log_exception env['sinatra.error']
16
+ @app.call(env)
17
+ end
18
+
19
+ end
20
+
21
+ private
22
+
23
+ def request_params(env)
24
+ if env['REQUEST_METHOD'] == 'POST'
25
+ env['rack.request.form_hash']
26
+ else
27
+ Rack::Utils.parse_nested_query(env['QUERY_STRING'])
28
+ end
29
+ end
30
+
31
+ def log_exception(e)
32
+ BammLog.logger.info "Bamm! #{e.class}: #{e.message}"
33
+
34
+ e.backtrace.each do |line|
35
+ BammLog.logger.info "#{line}"
36
+ end
37
+ end
38
+
39
+ end
40
+ end
@@ -0,0 +1,23 @@
1
+ module BammLog
2
+ module Formatter
3
+
4
+ def get_message(msg)
5
+ "#{String === msg ? msg : msg.inspect}"
6
+ end
7
+
8
+ def call_formatted(stamp, msg)
9
+ "[#{stamp.to_s(:log)}] #{msg}\n"
10
+ end
11
+
12
+ def included(klass)
13
+ ::Logger::Formatter.module_eval do
14
+ def call(severity, timestamp, progname, msg)
15
+ Formatter.call_formatted timestamp, Formatter.get_message(msg)
16
+ end
17
+ end
18
+ end
19
+
20
+ extend self
21
+
22
+ end
23
+ end
@@ -0,0 +1,3 @@
1
+ module BammLog
2
+ VERSION = "0.0.5"
3
+ end
data/lib/bamm_log.rb ADDED
@@ -0,0 +1,40 @@
1
+ require_relative 'bamm_log/exception_middleware'
2
+ require_relative 'bamm_log/formatter'
3
+ require_relative 'bamm_log/version'
4
+
5
+ module BammLog
6
+ module Logger
7
+
8
+ def self.included(klass)
9
+ @klass = klass
10
+
11
+ def self.instance
12
+ @instance ||= ::Logger.new(log_file).tap do |logger|
13
+ ::Logger.class_eval { alias :write :'<<' }
14
+ logger.level = ::Logger::INFO
15
+ end
16
+ end
17
+
18
+ def self.log_file
19
+ @log_file ||= File.new("#{@klass.root}/log/#{@klass.environment}.log", 'a+').tap do |log_file|
20
+ log_file.sync = true
21
+ end
22
+ end
23
+
24
+ klass.include(BammLog::Formatter)
25
+
26
+ klass.configure do
27
+ klass.enable :logging
28
+ klass.use Rack::CommonLogger, BammLog::Logger.instance
29
+ klass.use BammLog::ExceptionMiddleware
30
+ end
31
+ end
32
+
33
+ end
34
+
35
+ def logger
36
+ BammLog::Logger.instance
37
+ end
38
+
39
+ extend self
40
+ end
Binary file
Binary file
Binary file
Binary file
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bamm_log
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.5
5
+ platform: ruby
6
+ authors:
7
+ - Joaquim Adráz
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-08-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: pry
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ! '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ! '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description:
28
+ email:
29
+ - joaquim.adraz@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - LICENCE.txt
35
+ - README.md
36
+ - Rakefile
37
+ - hola.gemspec
38
+ - lib/bamm_log.rb
39
+ - lib/bamm_log/exception_middleware.rb
40
+ - lib/bamm_log/formatter.rb
41
+ - lib/bamm_log/version.rb
42
+ - pkg/bamm_log-0.0.1.gem
43
+ - pkg/bamm_log-0.0.2.gem
44
+ - pkg/bamm_log-0.0.3.gem
45
+ - pkg/bamm_log-0.0.4.gem
46
+ homepage: https://github.com/joaquimadraz/bamm_log
47
+ licenses:
48
+ - MIT
49
+ metadata: {}
50
+ post_install_message:
51
+ rdoc_options: []
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ! '>='
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ! '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ requirements: []
65
+ rubyforge_project:
66
+ rubygems_version: 2.2.0
67
+ signing_key:
68
+ specification_version: 4
69
+ summary: Not so experimental Sinatra Logger
70
+ test_files: []
71
+ has_rdoc: