sinatra-logger 0.1.1 → 0.2.6

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e1eb0c54730aa9b4e23c631855a98139a46b829c
4
+ data.tar.gz: 5cc8b7bf5124bf99af66ebfdd37f0f1f01ead274
5
+ SHA512:
6
+ metadata.gz: cebf2bd36ec73f7398d8fe0580287c0d3ec2e486c024d87b268c96c84054e7a19958cf403fb5159077c187178fdafcfe6a99500c29b4c2a1a42fd4d39aa13e38
7
+ data.tar.gz: a08d3aca8d45ef6b08940975d07115205f990fefe7135d18c5240c0cc6c668c2e723fe616d8066c82cf0728375645f34221b278710ba491b075457e12cca8f33
data/.gitignore CHANGED
@@ -1,23 +1,9 @@
1
- ## MAC OS
2
- .DS_Store
3
-
4
- ## TEXTMATE
5
- *.tmproj
6
- tmtags
7
-
8
- ## EMACS
9
- *~
10
- \#*
11
- .\#*
12
-
13
- ## VIM
14
- *.swp
15
-
16
- ## PROJECT::GENERAL
17
- coverage
18
- rdoc
19
- pkg
20
- doc
21
-
22
- ## PROJECT::SPECIFIC
23
- spec/fixtures/log/*.log
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
@@ -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.
@@ -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 CHANGED
@@ -1,90 +1,2 @@
1
- require 'rubygems'
2
- require 'rake'
3
-
4
- begin
5
- require 'jeweler'
6
- Jeweler::Tasks.new do |gem|
7
- gem.name = "sinatra-logger"
8
- gem.summary = %Q{Easy logging with Sinatra}
9
- gem.description = %Q{A Sinatra extension that makes logging easy}
10
- gem.email = "kematzy@gmail.com"
11
- gem.homepage = "http://github.com/kematzy/sinatra-logger"
12
- gem.authors = ["kematzy"]
13
- gem.add_dependency( "sinatra", ">= 1.0")
14
- gem.add_development_dependency( "rspec", ">= 1.3.0")
15
- gem.add_development_dependency( "sinatra-tests", ">= 0.1.6")
16
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
17
- end
18
- Jeweler::GemcutterTasks.new
19
- rescue LoadError
20
- puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
21
- end
22
-
23
- require 'spec/rake/spectask'
24
- Spec::Rake::SpecTask.new(:spec) do |spec|
25
- spec.libs << 'lib' << 'spec'
26
- spec.spec_opts = ["--color", "--format", "specdoc", "--require", "spec/spec_helper.rb"]
27
- spec.spec_files = FileList['spec/**/*_spec.rb']
28
- end
29
-
30
- Spec::Rake::SpecTask.new(:rcov) do |spec|
31
- spec.libs << 'lib' << 'spec'
32
- spec.spec_opts = ["--color", "--format", "specdoc", "--require", "spec/spec_helper.rb"]
33
- spec.pattern = 'spec/**/*_spec.rb'
34
- spec.rcov = true
35
- end
36
-
37
- namespace :spec do
38
-
39
- desc "Run all specifications quietly"
40
- Spec::Rake::SpecTask.new(:quiet) do |t|
41
- t.libs << "lib"
42
- t.spec_opts = ["--color", "--require", "spec/spec_helper.rb"]
43
- end
44
-
45
- desc "Run specific spec (SPEC=/path/2/file)"
46
- Spec::Rake::SpecTask.new(:select) do |t|
47
- t.libs << "lib"
48
- t.spec_files = [ENV["SPEC"]]
49
- t.spec_opts = ["--color", "--format", "specdoc", "--require", "spec/spec_helper.rb"]
50
- end
51
-
52
- end
53
-
54
- task :spec => :check_dependencies
55
-
1
+ require "bundler/gem_tasks"
56
2
  task :default => :spec
57
-
58
- require 'rake/rdoctask'
59
- Rake::RDocTask.new do |rdoc|
60
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
61
-
62
- rdoc.rdoc_dir = 'rdoc'
63
- rdoc.title = "sinatra-logger #{version}"
64
- rdoc.rdoc_files.include('README*')
65
- rdoc.rdoc_files.include('lib/**/*.rb')
66
- end
67
-
68
-
69
- desc 'Build the rdoc HTML Files'
70
- task :docs do
71
- version = File.exist?('VERSION') ? IO.read('VERSION').chomp : "[Unknown]"
72
-
73
- sh "sdoc -N --title 'Sinatra::Logger v#{version}' lib/ README.rdoc"
74
- end
75
-
76
- namespace :docs do
77
-
78
- desc 'Remove rdoc products'
79
- task :remove => [:clobber_rdoc]
80
-
81
- desc 'Force a rebuild of the RDOC files'
82
- task :rebuild => [:rerdoc]
83
-
84
- desc 'Build docs, and open in browser for viewing (specify BROWSER)'
85
- task :open => [:docs] do
86
- browser = ENV["BROWSER"] || "safari"
87
- sh "open -a #{browser} doc/index.html"
88
- end
89
-
90
- end
@@ -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
@@ -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,49 @@
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
+
16
+ def flush
17
+ SemanticLogger.flush
18
+ end
19
+
20
+ def <<(msg)
21
+ # To satisfy test calls. This function is available on "Logger" class by default.
22
+ end
23
+ end
24
+
25
+ module Logger
26
+ ::Sinatra::Base.class_eval do
27
+ def self.logger(config)
28
+ if config[:filename].nil?
29
+ raise "Minodes::Sinatra::Logger -- File name is not specified. Please, set `file_name` in the configuration block!"
30
+ end
31
+
32
+ config[:level] ||= :trace
33
+
34
+ set :logging, true
35
+ use ::Rack::CommonLogger, ::SemanticLogger["Access"]
36
+
37
+ ::Sinatra::Base.before do
38
+ ::SemanticLogger.default_level = config[:level]
39
+ ::SemanticLogger.appenders.each { |a| ::SemanticLogger.remove_appender(a) }
40
+ ::SemanticLogger.add_appender(file_name: config[:filename], formatter: :color)
41
+
42
+ env["rack.errors"] = ::Minodes::Sinatra::ErrorLogger.new
43
+ env["rack.logger"] = ::SemanticLogger[self.class.name]
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,7 @@
1
+ module Minodes
2
+ module Sinatra
3
+ module Logger
4
+ VERSION = "0.2.6"
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 = "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 CHANGED
@@ -1,125 +1,111 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: sinatra-logger
3
- version: !ruby/object:Gem::Version
4
- hash: 25
5
- prerelease: false
6
- segments:
7
- - 0
8
- - 1
9
- - 1
10
- version: 0.1.1
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.6
11
5
  platform: ruby
12
- authors:
13
- - kematzy
6
+ authors:
7
+ - Yehya Abouelnaga
14
8
  autorequire:
15
- bindir: bin
9
+ bindir: exe
16
10
  cert_chain: []
17
-
18
- date: 2010-08-29 00:00:00 +08:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
22
- name: sinatra
11
+ date: 2016-07-26 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
23
21
  prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
27
24
  - - ">="
28
- - !ruby/object:Gem::Version
29
- hash: 15
30
- segments:
31
- - 1
32
- - 0
33
- version: "1.0"
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
34
  type: :runtime
35
- version_requirements: *id001
36
- - !ruby/object:Gem::Dependency
37
- name: rspec
38
35
  prerelease: false
39
- requirement: &id002 !ruby/object:Gem::Requirement
40
- none: false
41
- requirements:
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
42
38
  - - ">="
43
- - !ruby/object:Gem::Version
44
- hash: 27
45
- segments:
46
- - 1
47
- - 3
48
- - 0
49
- version: 1.3.0
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'
50
48
  type: :development
51
- version_requirements: *id002
52
- - !ruby/object:Gem::Dependency
53
- name: sinatra-tests
54
49
  prerelease: false
55
- requirement: &id003 !ruby/object:Gem::Requirement
56
- none: false
57
- requirements:
58
- - - ">="
59
- - !ruby/object:Gem::Version
60
- hash: 23
61
- segments:
62
- - 0
63
- - 1
64
- - 6
65
- version: 0.1.6
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'
66
62
  type: :development
67
- version_requirements: *id003
68
- description: A Sinatra extension that makes logging easy
69
- email: kematzy@gmail.com
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
70
73
  executables: []
71
-
72
74
  extensions: []
73
-
74
- extra_rdoc_files:
75
- - LICENSE
76
- - README.rdoc
77
- files:
78
- - .document
79
- - .gitignore
80
- - LICENSE
81
- - README.rdoc
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
82
81
  - Rakefile
83
- - VERSION
84
- - lib/sinatra/logger.rb
85
- - sinatra-logger.gemspec
86
- - spec/sinatra/logger_spec.rb
87
- - spec/spec.opts
88
- - spec/spec_helper.rb
89
- has_rdoc: true
90
- homepage: http://github.com/kematzy/sinatra-logger
91
- licenses: []
92
-
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: {}
93
91
  post_install_message:
94
- rdoc_options:
95
- - --charset=UTF-8
96
- require_paths:
92
+ rdoc_options: []
93
+ require_paths:
97
94
  - lib
98
- required_ruby_version: !ruby/object:Gem::Requirement
99
- none: false
100
- requirements:
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ requirements:
101
97
  - - ">="
102
- - !ruby/object:Gem::Version
103
- hash: 3
104
- segments:
105
- - 0
106
- version: "0"
107
- required_rubygems_version: !ruby/object:Gem::Requirement
108
- none: false
109
- requirements:
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ requirements:
110
102
  - - ">="
111
- - !ruby/object:Gem::Version
112
- hash: 3
113
- segments:
114
- - 0
115
- version: "0"
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
116
105
  requirements: []
117
-
118
106
  rubyforge_project:
119
- rubygems_version: 1.3.7
107
+ rubygems_version: 2.5.1
120
108
  signing_key:
121
- specification_version: 3
122
- summary: Easy logging with Sinatra
123
- test_files:
124
- - spec/sinatra/logger_spec.rb
125
- - spec/spec_helper.rb
109
+ specification_version: 4
110
+ summary: A gem that wires `SemanticLogger` to Sinatra painlessly
111
+ test_files: []
data/.document DELETED
@@ -1,5 +0,0 @@
1
- README.rdoc
2
- lib/**/*.rb
3
- bin/*
4
- features/**/*.feature
5
- LICENSE
data/LICENSE DELETED
@@ -1,20 +0,0 @@
1
- Copyright (c) 2009 kematzy
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,182 +0,0 @@
1
- = Sinatra::Logger
2
-
3
- A Sinatra extension that makes logging within Your apps easy.
4
-
5
-
6
- == Installation
7
-
8
- $ (sudo)? gem install sinatra-logger
9
-
10
- == Dependencies
11
-
12
- This Gem depends upon the following:
13
-
14
- === Runtime:
15
-
16
- * sinatra ( >= 1.0 )
17
- * logger
18
-
19
- === Development & Tests:
20
-
21
- * rspec (>= 1.3.0 )
22
- * rack-test (>= 0.5.3)
23
- * rspec_hpricot_matchers (>= 0.1.0)
24
- * sinatra-tests (>= 0.1.6)
25
-
26
-
27
- == Getting Started
28
-
29
- To get logging in your app, just register the extension
30
- in your sub-classed Sinatra app:
31
-
32
- class YourApp < Sinatra::Base
33
-
34
- # NB! you need to set the root of the app first
35
- set :root, '/path/2/the/root/of/your/app'
36
-
37
- register(Sinatra::Logger)
38
- <snip...>
39
- end
40
-
41
-
42
- In your "classic" Sinatra app, you just require the extension like this:
43
-
44
- require 'rubygems'
45
- require 'sinatra'
46
- require 'sinatra/logger'
47
-
48
- # NB! you need to set the root of the app first
49
- set :root, '/path/2/the/root/of/your/app'
50
-
51
- <snip...>
52
-
53
-
54
-
55
- Then in your App's route or helper method declarations, just use the <tt>#logger</tt>...
56
-
57
- get '/some/route' do
58
- logger.debug("some informative message goes here")
59
- <snip...>
60
- end
61
-
62
- helpers do
63
- def some_helper_method
64
- logger.info("some equally informative message goes here")
65
- <snip...>
66
- end
67
- end
68
-
69
-
70
- That's pretty painless, no?
71
-
72
-
73
- === Logging Levels
74
-
75
- The <b>default Log level</b> is <tt>:warn</tt>.
76
-
77
- All the available logging levels are those of Logger[http://ruby-doc.org/stdlib/libdoc/logger/rdoc/classes/Logger.html], which are:
78
-
79
- * <tt>logger.fatal(msg)</tt> - - (FATAL) - an unhandleable error that results in a program crash
80
-
81
- * <tt>logger.error(msg)</tt> - - (ERROR) - a handleable error condition
82
-
83
- * <tt>logger.warn(msg)</tt> - - (WARN) - a warning
84
-
85
- * <tt>logger.info(msg)</tt> - - (INFO) - generic (useful) information about system operation
86
-
87
- * <tt>logger.debug(msg)</tt> - - (DEBUG) - low-level information for developers
88
-
89
-
90
- OK, by now you might be asking yourself,
91
-
92
- <em>"So where does the log messages go then ?"</em>.
93
-
94
-
95
- === Logging Locations
96
-
97
- By default the logger will log it's message to the following path:
98
-
99
- < the root of your app >/log/< environment >.log
100
-
101
- In other words if your app's root is [ <tt>/home/www/your-great-app/</tt> ] and it's
102
- running in <tt>:production</tt> mode, then the log location would become:
103
-
104
- /home/www/your-great-app/log/production.log
105
-
106
- <b>NB!</b> this extension takes for granted that you have a ../log/ directory with write access at the root of your app.
107
-
108
-
109
- === Custom Logging Location
110
-
111
- If the defaults are NOT for you, then just do...
112
-
113
- class YourApp < Sinatra::Base
114
-
115
- register(Sinatra::Logger)
116
-
117
- set: :logger_log_file, lambda { "/path/2/your/log/file.ext" }
118
-
119
- <snip...>
120
-
121
- end
122
-
123
-
124
- # the lambda { } is required, especially if you have variables in the path
125
-
126
- ..., now your log messages will be written to that log file.
127
-
128
-
129
- === Setting Log Level
130
-
131
- Finally, to use a different Log level for your app, other than the default <tt>:warn</tt> just...
132
-
133
- class YourApp < Sinatra::Base
134
-
135
- register(Sinatra::Logger)
136
-
137
- set: :logger_level, :fatal # or :error, :warn, :info, :debug
138
- <snip...>
139
- end
140
-
141
-
142
- That's it. I hope that's easy enough.
143
-
144
-
145
- == RTFM
146
-
147
- If the above is not clear enough, please check the Specs for a better understanding.
148
-
149
-
150
- == Errors / Bugs
151
-
152
- If something is not behaving intuitively, it is a bug, and should be reported.
153
- Report it here: http://github.com/kematzy/sinatra-logger/issues
154
-
155
-
156
- == TODOs
157
-
158
- * Making the logging work with Rack::CommonLogger, but still retain it's independence.
159
-
160
- * Any other improvements you can think of.
161
-
162
-
163
-
164
- == Note on Patches/Pull Requests
165
-
166
- * Fork the project.
167
- * Make your feature addition or bug fix.
168
- * Add tests for it. This is important so I don't break it in a
169
- future version unintentionally.
170
- * Commit, do not mess with rakefile, version, or history.
171
- * (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
172
- * Send me a pull request. Bonus points for topic branches.
173
-
174
- == Copyright
175
-
176
- Copyright (c) 2010 kematzy. Released under the MIT License.
177
-
178
- See LICENSE for details.
179
-
180
- == Inspirational Source
181
-
182
- * Monk Glue
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.1.1
@@ -1,201 +0,0 @@
1
-
2
- require 'logger'
3
-
4
- module Sinatra
5
-
6
- # = Sinatra::Logger
7
- #
8
- # A Sinatra extension that makes logging within Your apps easy.
9
- #
10
- #
11
- # == Installation
12
- #
13
- # $ (sudo)? gem install sinatra-logger
14
- #
15
- # == Dependencies
16
- #
17
- # This Gem depends upon the following:
18
- #
19
- # === Runtime:
20
- #
21
- # * sinatra ( >= 1.0 )
22
- # * logger
23
- #
24
- # === Development & Tests:
25
- #
26
- # * rspec (>= 1.3.0 )
27
- # * rack-test (>= 0.5.3)
28
- # * rspec_hpricot_matchers (>= 0.1.0)
29
- # * sinatra-tests (>= 0.1.6)
30
- #
31
- #
32
- # == Getting Started
33
- #
34
- # To get logging in your app, just register the extension
35
- # in your sub-classed Sinatra app:
36
- #
37
- # class YourApp < Sinatra::Base
38
- #
39
- # # NB! you need to set the root of the app first
40
- # # set :root, '/path/2/the/root/of/your/app'
41
- #
42
- # register(Sinatra::Logger)
43
- #
44
- # <snip...>
45
- #
46
- # end
47
- #
48
- #
49
- # In your "classic" Sinatra app, you just require the extension like this:
50
- #
51
- # require 'rubygems'
52
- # require 'sinatra'
53
- # require 'sinatra/logger'
54
- #
55
- # # NB! you need to set the root of the app first
56
- # # set :root, '/path/2/the/root/of/your/app'
57
- #
58
- # <snip...>
59
- #
60
- #
61
- # Then in your App's route or helper method declarations, just use the <tt>#logger</tt>...
62
- #
63
- # get '/some/route' do
64
- # logger.debug("some informative message goes here")
65
- # <snip...>
66
- # end
67
- #
68
- # helpers do
69
- # def some_helper_method
70
- # logger.info("some equally informative message goes here")
71
- # <snip...>
72
- # end
73
- # end
74
- #
75
- #
76
- # That's pretty painless, no?
77
- #
78
- #
79
- # === Logging Levels
80
- #
81
- # The <b>default Log level</b> is <tt>:warn</tt>.
82
- #
83
- # All the available logging levels are those of Logger[http://ruby-doc.org/stdlib/libdoc/logger/rdoc/classes/Logger.html], which are:
84
- #
85
- # * <tt>logger.fatal(msg)</tt> - - (FATAL) - an unhandleable error that results in a program crash
86
- #
87
- # * <tt>logger.error(msg)</tt> - - (ERROR) - a handleable error condition
88
- #
89
- # * <tt>logger.warn(msg)</tt> - - (WARN) - a warning
90
- #
91
- # * <tt>logger.info(msg)</tt> - - (INFO) - generic (useful) information about system operation
92
- #
93
- # * <tt>logger.debug(msg)</tt> - - (DEBUG) - low-level information for developers
94
- #
95
- #
96
- # OK, by now you might be asking yourself,
97
- #
98
- # <em>"So where does the log messages go then ?"</em>.
99
- #
100
- #
101
- # === Logging Locations
102
- #
103
- # By default the logger will log it's message to the following path:
104
- #
105
- # < the root of your app >/log/< environment >.log
106
- #
107
- # In other words if your app's root is [ <tt>/home/www/your-great-app/</tt> ] and it's
108
- # running in <tt>:production</tt> mode, then the log location would become:
109
- #
110
- # /home/www/your-great-app/log/production.log
111
- #
112
- # <b>NB!</b> this extension takes for granted that you have a ../log/ directory with write access at the root of your app.
113
- #
114
- #
115
- # === Custom Logging Location
116
- #
117
- # If the defaults are NOT for you, then just do...
118
- #
119
- # class YourApp < Sinatra::Base
120
- #
121
- # register(Sinatra::Logger)
122
- #
123
- # set: :logger_log_file, lambda { "/path/2/your/log/file.ext" }
124
- #
125
- # <snip...>
126
- #
127
- # end
128
- #
129
- #
130
- # # the lambda { } is required, especially if you have variables in the path
131
- #
132
- # ..., now your log messages will be written to that log file.
133
- #
134
- #
135
- # === Setting Log Level
136
- #
137
- # Finally, to use a different Log level for your app, other than the default <tt>:warn</tt> just...
138
- #
139
- # class YourApp < Sinatra::Base
140
- #
141
- # register(Sinatra::Logger)
142
- #
143
- # set: :logger_level, :fatal # or :error, :warn, :info, :debug
144
- # <snip...>
145
- # end
146
- #
147
- #
148
- # That's it. I hope that's easy enough.
149
- #
150
- module Logger
151
-
152
- VERSION = '0.1.1'
153
- ##
154
- # Returns the version string for this extension
155
- #
156
- # ==== Examples
157
- #
158
- # Sinatra::Logger.version => 'Sinatra::Logger v0.1.0'
159
- #
160
- def self.version; "Sinatra::Logger v#{VERSION}"; end
161
-
162
-
163
- module Helpers
164
-
165
- ##
166
- # Provides easy access to the Logger object throughout your
167
- # application
168
- #
169
- # ==== Examples
170
- #
171
- # logger.warn("messsage")
172
- #
173
- #
174
- # @api public
175
- def logger
176
- @logger ||= begin
177
- @logger = ::Logger.new(self.class.logger_log_file)
178
- @logger.level = ::Logger.const_get((self.class.logger_level || :warn).to_s.upcase)
179
- @logger.datetime_format = "%Y-%m-%d %H:%M:%S"
180
- @logger
181
- end
182
- end
183
-
184
- end #/module Helpers
185
-
186
-
187
- def self.registered(app)
188
- app.helpers Sinatra::Logger::Helpers
189
-
190
- # set the output log level
191
- app.set :logger_level, :warn
192
- # set the full path to the log file
193
- app.set :logger_log_file, lambda { File.join(root, 'log', "#{environment}.log") }
194
-
195
- end #/ self.registered
196
-
197
- end #/module Logger
198
-
199
- register(Sinatra::Logger)
200
-
201
- end #/ Sinatra
@@ -1,61 +0,0 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
- # -*- encoding: utf-8 -*-
5
-
6
- Gem::Specification.new do |s|
7
- s.name = %q{sinatra-logger}
8
- s.version = "0.1.1"
9
-
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["kematzy"]
12
- s.date = %q{2010-08-29}
13
- s.description = %q{A Sinatra extension that makes logging easy}
14
- s.email = %q{kematzy@gmail.com}
15
- s.extra_rdoc_files = [
16
- "LICENSE",
17
- "README.rdoc"
18
- ]
19
- s.files = [
20
- ".document",
21
- ".gitignore",
22
- "LICENSE",
23
- "README.rdoc",
24
- "Rakefile",
25
- "VERSION",
26
- "lib/sinatra/logger.rb",
27
- "sinatra-logger.gemspec",
28
- "spec/sinatra/logger_spec.rb",
29
- "spec/spec.opts",
30
- "spec/spec_helper.rb"
31
- ]
32
- s.homepage = %q{http://github.com/kematzy/sinatra-logger}
33
- s.rdoc_options = ["--charset=UTF-8"]
34
- s.require_paths = ["lib"]
35
- s.rubygems_version = %q{1.3.7}
36
- s.summary = %q{Easy logging with Sinatra}
37
- s.test_files = [
38
- "spec/sinatra/logger_spec.rb",
39
- "spec/spec_helper.rb"
40
- ]
41
-
42
- if s.respond_to? :specification_version then
43
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
44
- s.specification_version = 3
45
-
46
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
47
- s.add_runtime_dependency(%q<sinatra>, [">= 1.0"])
48
- s.add_development_dependency(%q<rspec>, [">= 1.3.0"])
49
- s.add_development_dependency(%q<sinatra-tests>, [">= 0.1.6"])
50
- else
51
- s.add_dependency(%q<sinatra>, [">= 1.0"])
52
- s.add_dependency(%q<rspec>, [">= 1.3.0"])
53
- s.add_dependency(%q<sinatra-tests>, [">= 0.1.6"])
54
- end
55
- else
56
- s.add_dependency(%q<sinatra>, [">= 1.0"])
57
- s.add_dependency(%q<rspec>, [">= 1.3.0"])
58
- s.add_dependency(%q<sinatra-tests>, [">= 0.1.6"])
59
- end
60
- end
61
-
@@ -1,194 +0,0 @@
1
-
2
- require File.expand_path(File.dirname(File.dirname(__FILE__)) + '/spec_helper')
3
-
4
- describe "Sinatra" do
5
-
6
- class MyTestApp
7
- register Sinatra::Logger
8
-
9
- helpers do
10
-
11
- def dummy_helper(level, message)
12
- logger.send(level, message)
13
- "Level: #{level}, Message: #{message}"
14
- end
15
- end
16
-
17
- get '/logger/:msg' do
18
- logger.warn("Message: #{params[:msg]}")
19
- erb("Message: #{params[:msg]}", :layout => false )
20
- end
21
-
22
- end
23
-
24
- it_should_behave_like "MyTestApp"
25
-
26
- describe "Logger" do
27
-
28
- describe "with Default Settings" do
29
-
30
- before(:each) do
31
- FileUtils.mkdir_p "#{fixtures_path}/log"
32
- @log_file = "#{fixtures_path}/log/#{MyTestApp.environment}.log"
33
- `touch #{@log_file}`
34
- end
35
-
36
- after(:each) do
37
- `echo '' > #{@log_file}`
38
- end
39
-
40
- describe "Configuration" do
41
-
42
- it "should set :logger_level to :warn" do
43
- app.settings.logger_level.should == :warn
44
- end
45
-
46
- it "should set :logger_log_file to [../log/< environment >.log]" do
47
- app.settings.logger_log_file.should == "#{fixtures_path}/log/test.log"
48
- end
49
-
50
- end #/ Configuration
51
-
52
- describe "Helpers" do
53
-
54
- describe "#logger" do
55
-
56
- it "should create a #{MyTestApp.environment}.log file when initialized" do
57
- test(?f, @log_file).should == true
58
- end
59
-
60
- it "should return an instance of Logger" do
61
- app.should respond_to(:logger)
62
- app.logger.should be_a_kind_of(::Logger)
63
- end
64
-
65
- it "should log when called from within a route" do
66
- get('/logger/this-works')
67
- body.should == "Message: this-works"
68
- IO.read(@log_file).should match(/WARN -- : Message: this-works/)
69
- end
70
-
71
- it "should log when called from within helper methods" do
72
- erb_app '<%= dummy_helper(:warn, "works too") %>'
73
- IO.read(@log_file).should match(/WARN -- : works too/)
74
- body.should == "Level: warn, Message: works too"
75
- end
76
-
77
- it "should NOT log lower levels" do
78
- erb_app '<%= dummy_helper(:info, "default-info") %>'
79
- IO.read(@log_file).should_not match(/INFO -- : default-info/)
80
- body.should == "Level: info, Message: default-info"
81
-
82
- erb_app '<%= dummy_helper(:debug, "default-debug") %>'
83
- IO.read(@log_file).should_not match(/DEBUG -- : default-debug/)
84
- body.should == "Level: debug, Message: default-debug"
85
- end
86
-
87
- end #/ #logger
88
-
89
- end #/ Helpers
90
-
91
- end #/ with Default Settings
92
-
93
- describe "with Custom Settings" do
94
-
95
- class MyCustomTestApp
96
- register Sinatra::Logger
97
-
98
- set :logger_level, :debug
99
- set :logger_log_file, lambda { "#{fixtures_path}/log/custom.log" }
100
-
101
- helpers do
102
-
103
- def dummy_helper(level, message)
104
- logger.send(level, message)
105
- "Level: #{level}, Message: #{message}"
106
- end
107
- end
108
-
109
- get '/customlogger/:msg' do
110
- logger.warn("Message: #{params[:msg]}")
111
- erb("CustomMessage: #{params[:msg]}", :layout => false )
112
- end
113
-
114
- end
115
-
116
- before(:each) do
117
- class ::Test::Unit::TestCase
118
- def app; ::MyCustomTestApp.new ; end
119
- end
120
- @app = app
121
-
122
- FileUtils.mkdir_p "#{fixtures_path}/log"
123
- @custom_log_file = "#{fixtures_path}/log/custom.log"
124
- `touch #{@custom_log_file}`
125
- end
126
-
127
- after(:each) do
128
- class ::Test::Unit::TestCase
129
- def app; nil ; end
130
- end
131
- @app = nil
132
-
133
- `echo '' > #{@custom_log_file}`
134
- end
135
-
136
- describe "Configuration" do
137
-
138
- it "should set :logger_level to :debug" do
139
- app.settings.logger_level.should == :debug
140
- end
141
-
142
- it "should set :logger_log_file to [../log/custom.log]" do
143
- app.settings.logger_log_file.should == "#{fixtures_path}/log/custom.log"
144
- end
145
-
146
- end #/ Configuration
147
-
148
- describe "Helpers" do
149
-
150
- describe "#logger" do
151
-
152
- it "should create a custom.log file when initialised" do
153
- test(?f, @custom_log_file).should == true
154
- end
155
-
156
- it "should return an instance of Logger" do
157
- app.logger.should be_a_kind_of(::Logger)
158
- end
159
-
160
- it "should log when called from within a route" do
161
- get('/customlogger/this-works')
162
- body.should == "CustomMessage: this-works"
163
- IO.read(@custom_log_file).should match(/WARN -- : Message: this-works/)
164
- end
165
-
166
- it "should log when called from within helper methods" do
167
- erb_app '<%= dummy_helper(:info, "works as well") %>'
168
- IO.read(@custom_log_file).should match(/INFO -- : works as well/)
169
- body.should == "Level: info, Message: works as well"
170
-
171
- erb_app '<%= dummy_helper(:warn, "works too") %>'
172
- IO.read(@custom_log_file).should match(/WARN -- : works too/)
173
- body.should == "Level: warn, Message: works too"
174
- end
175
-
176
- it "should log higher levels" do
177
- erb_app '<%= dummy_helper(:info, "custom-info") %>'
178
- IO.read(@custom_log_file).should match(/INFO -- : custom-info/)
179
- body.should == "Level: info, Message: custom-info"
180
-
181
- erb_app '<%= dummy_helper(:debug, "custom-debug") %>'
182
- IO.read(@custom_log_file).should match(/DEBUG -- : custom-debug/)
183
- body.should == "Level: debug, Message: custom-debug"
184
- end
185
-
186
- end #/ #logger
187
-
188
- end #/ Helpers
189
-
190
- end #/ with Custom Settings
191
-
192
- end #/ Logger
193
-
194
- end #/ Sinatra
@@ -1 +0,0 @@
1
- --color
@@ -1,61 +0,0 @@
1
-
2
-
3
- $LOAD_PATH.unshift(File.dirname(__FILE__))
4
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
5
-
6
-
7
- #--
8
- # DEPENDENCIES
9
- #++
10
- %w(
11
- sinatra/base
12
- fileutils
13
- ).each {|lib| require lib }
14
-
15
- #--
16
- ## SINATRA EXTENSIONS
17
- #++
18
- %w(
19
- sinatra/tests
20
- sinatra/logger
21
- ).each {|ext| require ext }
22
-
23
-
24
- ENV['RACK_ENV'] = 'test'
25
-
26
- Spec::Runner.configure do |config|
27
- config.include RspecHpricotMatchers
28
- config.include Sinatra::Tests::TestCase
29
- config.include Sinatra::Tests::RSpec::SharedSpecs
30
- end
31
-
32
- def fixtures_path
33
- "#{File.dirname(File.expand_path(__FILE__))}/fixtures"
34
- end
35
-
36
- class MyTestApp < Sinatra::Base
37
- set :root, "#{fixtures_path}"
38
- set :app_dir, "#{fixtures_path}/app"
39
- set :public, "#{fixtures_path}/public"
40
- set :views, "#{app_dir}/views"
41
- enable :raise_errors
42
-
43
- register(Sinatra::Tests)
44
-
45
- end #/class MyTestApp
46
-
47
- class MyCustomTestApp < Sinatra::Base
48
- set :root, "#{fixtures_path}"
49
- set :app_dir, "#{fixtures_path}/app"
50
- set :public, "#{fixtures_path}/public"
51
- set :views, "#{app_dir}/views"
52
- enable :raise_errors
53
-
54
- register(Sinatra::Tests)
55
-
56
- end #/class MyCustomTestApp
57
-
58
-
59
- class Test::Unit::TestCase
60
- Sinatra::Base.set :environment, :test
61
- end