minodes-sinatra-logger 0.2.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f96224693b423f1410eebfe611aceba9495d7830
4
+ data.tar.gz: cfdc724ad9a2b6d4824327c4c1fe8f53fe8bb985
5
+ SHA512:
6
+ metadata.gz: 6706476a5dadd4e37d1fbd2bbcd7fe5c539de616ada0b6ac95a2ae418002165567eff500ca172169f43e9e2aff2aa78c9ae33cece8fb62f24862375641faccfb
7
+ data.tar.gz: 257a09432d01ff98d1e2b310ba86df73196f3b9e5eb87797529c746d626a0664b4c19640ef24c714be274607ec8145d5d52b361f2dbe87c6f800641a58898885
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/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in minodes-sinatra-logger.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Yehya Abouelnaga
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,84 @@
1
+ # Sinatra Logger
2
+
3
+ For those who dealt with Sinatra Logging, and tried to configure it correctly (i.e. have Access logs, Error logs, and the normal `logger` functionality), they know how messy that is. Sinatra logging configuration is painful. To get a better understanding, refer to:
4
+ * http://recipes.sinatrarb.com/p/middleware/rack_commonlogger (Just logs the access logs)
5
+ * https://spin.atomicobject.com/2013/11/12/production-logging-sinatra/ (This goes further to add Errors to the logs as well. However, this breaks with modular Sinatra applications)
6
+ * http://stackoverflow.com/questions/5995854/logging-in-sinatra (Or, just outdated answers)
7
+ * https://github.com/kematzy/sinatra-logger (Or, outdated libraries)
8
+
9
+ If you come from a Rails background, you are probably used to the simplicity of:
10
+ ```
11
+ logger.info "some info"
12
+ logger.debug "some debugging"
13
+ ...
14
+ ```
15
+
16
+ We offer a slightly "better looking" option using our library.
17
+
18
+ ### Dependency
19
+ This library is an interface for `SemanticLogger` library (found here: https://github.com/rocketjob/semantic_logger). It just does the wiring for your `Sinatra` app, and gets you up and running with a simple line of code.
20
+
21
+ Please, check the `SemanticLogger` (http://rocketjob.github.io/semantic_logger/) to get a glimpse of their pretty neat logging solution.
22
+
23
+ ### Installation
24
+
25
+ Add this line to your application's Gemfile:
26
+
27
+ ```ruby
28
+ gem 'minodes-sinatra-logger'
29
+ ```
30
+
31
+ And then execute:
32
+
33
+ $ bundle
34
+
35
+ Or install it yourself as:
36
+
37
+ $ gem install minodes-sinatra-logger
38
+
39
+ ### Usage
40
+
41
+ We assume that you use either: `Sinatra::Base` or `Sinatra::Application`.
42
+ #### One-layer Applications
43
+ ```
44
+ class MyApp < Sinatra::Base
45
+ logger filename: "log/#{settings.environment}.log", level: :trace
46
+
47
+ # ... remaining code ...
48
+ end
49
+ ```
50
+
51
+ #### Multi-layered Applications (Modular Applications)
52
+ ```
53
+ class App1 < Sinatra::Application
54
+ # ... some App1 routes/code ...
55
+ end
56
+
57
+ class App2 < Sinatra::Application
58
+ # ... some App1 routes/code ...
59
+ end
60
+
61
+ class ContainerApp < Sinatra::Application
62
+ logger filename: "log/#{settings.environment}.log", level: :trace
63
+
64
+ use App1
65
+ use App2
66
+
67
+ # ... remaining code ...
68
+ end
69
+ ```
70
+
71
+ **NOTE**: You need to only use `logger filename: "", level: :trace` only once (precisely in the container app).
72
+
73
+ ### Development
74
+
75
+ This gem is still in its beta phase. If you spot any errors, or propose some improvements, contact us: github [at] minodes [dot] com
76
+
77
+ ## Contributing
78
+
79
+ Bug reports and pull requests are welcome on GitHub at https://github.com/minodes/sinatra-logger. We would love to see your suggestions, fixes or improvements.
80
+
81
+
82
+ ## License
83
+
84
+ 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,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "minodes/sinatra/logger"
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,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,45 @@
1
+ require "minodes/sinatra/logger/version"
2
+ require "sinatra"
3
+ require "rack"
4
+ require 'rack/body_proxy'
5
+ require 'rack/utils'
6
+ require "semantic_logger"
7
+ require "logger"
8
+
9
+ module Minodes
10
+ module Sinatra
11
+ class ErrorLogger
12
+ def puts(msg)
13
+ SemanticLogger["Error"].error msg
14
+ end
15
+ end
16
+
17
+ module Logger
18
+ ::Sinatra::Base.class_eval do
19
+ def self.logger(config)
20
+ if config[:filename].nil?
21
+ raise "Minodes::Sinatra::Logger -- File name is not specified. Please, set `file_name` in the configuration block!"
22
+ end
23
+
24
+ config[:level] ||= :trace
25
+
26
+ ::SemanticLogger.default_level = config[:level]
27
+ ::SemanticLogger.appenders.each { |a| ::SemanticLogger.remove_appender(a) }
28
+ ::SemanticLogger.add_appender(file_name: config[:filename], formatter: :color)
29
+
30
+ set :logging, true
31
+ use ::Rack::CommonLogger, ::SemanticLogger["Access"]
32
+
33
+ ::Sinatra::Base.before do
34
+ ::SemanticLogger.default_level = config[:level]
35
+ ::SemanticLogger.appenders.each { |a| ::SemanticLogger.remove_appender(a) }
36
+ ::SemanticLogger.add_appender(file_name: config[:filename], formatter: :color)
37
+
38
+ env["rack.errors"] = ::Minodes::Sinatra::ErrorLogger.new
39
+ env["rack.logger"] = ::SemanticLogger[self.class.name]
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,7 @@
1
+ module Minodes
2
+ module Sinatra
3
+ module Logger
4
+ VERSION = "0.2.1"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,35 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'minodes/sinatra/logger/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "minodes-sinatra-logger"
8
+ spec.version = Minodes::Sinatra::Logger::VERSION
9
+ spec.authors = ["Yehya Abouelnaga"]
10
+ spec.email = ["yehya.abouelnaga@minodes.com"]
11
+
12
+ spec.summary = %q{A gem that wires `SemanticLogger` to Sinatra painlessly}
13
+ spec.description = %q{Sinatra Logging is a pain. This gem helps with wiring Access logs, Error logs, and plain debugging logs (i.e. logger.info, logger.warn, ... etc).}
14
+ spec.homepage = "https://github.com/minodes/sinatra-logger"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ # if spec.respond_to?(:metadata)
20
+ # spec.metadata['allowed_push_host'] = "http://rubygems.com"
21
+ # else
22
+ # raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
+ # end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_dependency "semantic_logger"
31
+ spec.add_dependency "sinatra"
32
+
33
+ spec.add_development_dependency "bundler", "~> 1.12"
34
+ spec.add_development_dependency "rake", "~> 10.0"
35
+ end
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: minodes-sinatra-logger
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.1
5
+ platform: ruby
6
+ authors:
7
+ - Yehya Abouelnaga
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-07-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: semantic_logger
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: sinatra
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.12'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.12'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ description: Sinatra Logging is a pain. This gem helps with wiring Access logs, Error
70
+ logs, and plain debugging logs (i.e. logger.info, logger.warn, ... etc).
71
+ email:
72
+ - yehya.abouelnaga@minodes.com
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - bin/console
83
+ - bin/setup
84
+ - lib/minodes/sinatra/logger.rb
85
+ - lib/minodes/sinatra/logger/version.rb
86
+ - minodes-sinatra-logger.gemspec
87
+ homepage: https://github.com/minodes/sinatra-logger
88
+ licenses:
89
+ - MIT
90
+ metadata: {}
91
+ post_install_message:
92
+ rdoc_options: []
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ requirements: []
106
+ rubyforge_project:
107
+ rubygems_version: 2.5.1
108
+ signing_key:
109
+ specification_version: 4
110
+ summary: A gem that wires `SemanticLogger` to Sinatra painlessly
111
+ test_files: []