Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow custom loggers #768

Merged
merged 12 commits into from Jun 2, 2017
12 changes: 12 additions & 0 deletions CHANGELOG.md
@@ -1,6 +1,18 @@
# Hanami
The web, with simplicity.

## v1.0.0 - 2017-04-06

## v1.0.0.rc1 - 2017-03-31
### Added
- [Luca Guidi] Allow `logger` setting in `config/environment.rb` to accept arbitrary arguments to make `Hanami::Logger` to be compatible with Ruby's `Logger`. (eg. `logger 'daily', level: :info`)

### Fixed
- [Luca Guidi] Ensure code reloading don't misconfigure mailer settings (regression from v1.0.0.beta3)
- [Luca Guidi] Ensure database disconnection to happen in the same thread of `Hanami.boot`
- [Luca Guidi] Ensure `mailer` block in `config/environment.rb` to be evaluated multiple times, according to the current Hanami environment
- [Luca Guidi] Ensure a Hanami project to require only once the code under `lib/`

## v1.0.0.beta3 - 2017-03-17
### Fixed
- [Luca Guidi] Try to disconnect from database at the boot time. This is useful to prune stale connection during production deploys.
Expand Down
44 changes: 21 additions & 23 deletions FEATURES.md
Expand Up @@ -3,21 +3,19 @@

## Features

## v1.0.0.beta3 - 2017-03-17
### v1.0.0 - 2017-04-06

## v1.0.0.beta2 - 2017-03-02
- Logger rotation
- Added: `Action#unsafe_send_file` to send files outside of the public directory

## v1.0.0.beta1 - 2017-02-14
- CLI: `hanami generate model` now also generates a migration
- Project logger `Hanami.logger`
- Automatic logging of HTTP requests, migrations, and SQL queries

## v0.9.2 - 2016-12-19
### v0.9.2 - 2016-12-19

## v0.9.1 - 2016-11-18
### v0.9.1 - 2016-11-18

## v0.9.0 - 2016-11-15
### v0.9.0 - 2016-11-15

- Experimental repositories associations (only "has many")
- Database automapping for SQL databases
Expand All @@ -30,7 +28,7 @@
- Native support for PostgreSQL types
- CLI: `hanami secret` to generate and print a new session secret for a single Hanami app

## v0.8.0 - 2016-07-22
### v0.8.0 - 2016-07-22

- New validation syntax based on predicates
- Custom and shared predicates for validations
Expand All @@ -49,19 +47,19 @@
- Experimental code reloading via `entr(1)`
- CLI: `hanami new` can be used with `--template` argument to generate a new project with (`erb`/`haml`/`slim`) templates

## v0.7.3 - 2016-05-23
### v0.7.3 - 2016-05-23

## v0.7.2 - 2016-02-09
### v0.7.2 - 2016-02-09

## v0.7.1 - 2016-02-05
### v0.7.1 - 2016-02-05

## v0.7.0 - 2016-01-22
### v0.7.0 - 2016-01-22

- Renamed from Lotus to Hanami

## v0.6.1 - 2016-01-19
### v0.6.1 - 2016-01-19

## v0.6.0 - 2016-01-12
### v0.6.0 - 2016-01-12

- Assets preprocessors support (eg. Sass, ES6, Opal, Less, CoffeScript..)
- Assets compressors (eg. YUI, UglifyJS2, Google Closure Compiler, Sass..)
Expand All @@ -82,16 +80,16 @@
- Custom initializers (`apps/web/config/initializers`)
- Rake tasks `:preload` and `:environment`

## v0.5.0 - 2015-09-30
### v0.5.0 - 2015-09-30

- Mailers
- CLI: `lotus generate mailer`
- SQL joins
- Custom coercers for data mapper

## v0.4.1 - 2015-07-10
### v0.4.1 - 2015-07-10

## v0.4.0 - 2015-06-23
### v0.4.0 - 2015-06-23

- Application architecture
- Database migrations
Expand All @@ -101,14 +99,14 @@
- Force SSL
- Number formatting helper

## v0.3.2 - 2015-05-22
### v0.3.2 - 2015-05-22

- Automatic secure cookies
- Routing helpers for actions
- Send files from actions
- `Lotus.root` returns top level directory of the project.

## v0.3.1 - 2015-05-15
### v0.3.1 - 2015-05-15

- CLI: `lotus generate app admin` creates a new application (`apps/admin`).
- CLI: `lotus generate model user`. It generates entity, repository and related unit test files.
Expand All @@ -119,7 +117,7 @@
- Nested RESTful resource(s)
- String pluralization and singularization

## v0.3.0 - 2015-03-23
### v0.3.0 - 2015-03-23

- CLI: `lotus generate action web dashboard#index`. It generates an action, a view, a template, a route and related unit test files.
- CLI: `lotus db console`. It starts a database REPL.
Expand All @@ -138,14 +136,14 @@
- Interactors (aka Service Objects)
- Database transactions

## v0.2.1 - 2015-02-06
### v0.2.1 - 2015-02-06

- Allow entities to include validations.
- `lotus new .` to generate a Lotus project for an existing code base (Eg. a gem that needs a web UI).
- `lotus new` supports `--path` (for destination directory), `--test` (to generate Minitest or RSpec boilerplate).
- Lotus logger

## v0.2.0 - 2014-12-23
### v0.2.0 - 2014-12-23

- Support Minitest as default testing framework (`bundle exec rake` runs the entire test suite of an application).
- Support for _Method Override_ technique.
Expand All @@ -171,7 +169,7 @@
- JSON body parser for non-GET HTTP requests
- Routes inspector for CLI

## v0.1.0 - 2014-06-23
### v0.1.0 - 2014-06-23

- Run multiple Lotus applications in the same Ruby process
- Serve static files
Expand Down
26 changes: 13 additions & 13 deletions Gemfile
Expand Up @@ -7,15 +7,15 @@ unless ENV['TRAVIS']
end

gem 'i18n'
gem 'hanami-utils', '~> 1.0.0.beta1', require: false, github: 'hanami/utils', branch: '1.0.x'
gem 'hanami-validations', '~> 1.0.0.beta1', require: false, github: 'hanami/validations', branch: '1.0.x'
gem 'hanami-router', '~> 1.0.0.beta1', require: false, github: 'hanami/router', branch: '1.0.x'
gem 'hanami-controller', '~> 1.0.0.beta1', require: false, github: 'hanami/controller', branch: '1.0.x'
gem 'hanami-view', '~> 1.0.0.beta1', require: false, github: 'hanami/view', branch: '1.0.x'
gem 'hanami-model', '~> 1.0.0.beta1', require: false, github: 'hanami/model', branch: '1.0.x'
gem 'hanami-helpers', '~> 1.0.0.beta1', require: false, github: 'hanami/helpers', branch: '1.0.x'
gem 'hanami-mailer', '~> 1.0.0.beta1', require: false, github: 'hanami/mailer', branch: '1.0.x'
gem 'hanami-assets', '~> 1.0.0.beta1', require: false, github: 'hanami/assets', branch: '1.0.x'
gem 'hanami-utils', '~> 1.0', require: false, git: 'https://github.com/hanami/utils.git', branch: '1.0.x'
gem 'hanami-validations', '~> 1.0', require: false, git: 'https://github.com/hanami/validations.git', branch: '1.0.x'
gem 'hanami-router', '~> 1.0', require: false, git: 'https://github.com/hanami/router.git', branch: '1.0.x'
gem 'hanami-controller', '~> 1.0', require: false, git: 'https://github.com/hanami/controller.git', branch: '1.0.x'
gem 'hanami-view', '~> 1.0', require: false, git: 'https://github.com/hanami/view.git', branch: '1.0.x'
gem 'hanami-model', '~> 1.0', require: false, git: 'https://github.com/hanami/model.git', branch: '1.0.x'
gem 'hanami-helpers', '~> 1.0', require: false, git: 'https://github.com/hanami/helpers.git', branch: '1.0.x'
gem 'hanami-mailer', '~> 1.0', require: false, git: 'https://github.com/hanami/mailer.git', branch: '1.0.x'
gem 'hanami-assets', '~> 1.0', require: false, git: 'https://github.com/hanami/assets.git', branch: '1.0.x'

platforms :ruby do
gem 'sqlite3'
Expand Down Expand Up @@ -50,7 +50,7 @@ gem 'coffee-script', require: false
# HTTP tests
gem 'excon', require: false

gem 'dotenv', '~> 2.0', require: false
gem 'shotgun', '~> 0.9', require: false
gem 'rubocop', '~> 0.43.0', require: false
gem 'coveralls', require: false
gem 'dotenv', '~> 2.0', require: false
gem 'shotgun', '~> 0.9', require: false
gem 'rubocop', '0.48.0', require: false
gem 'coveralls', require: false
20 changes: 10 additions & 10 deletions hanami.gemspec
Expand Up @@ -6,8 +6,8 @@ require 'hanami/version'
Gem::Specification.new do |spec|
spec.name = 'hanami'
spec.version = Hanami::VERSION
spec.authors = ['Luca Guidi', 'Trung Lê', 'Alfonso Uceda Pompa']
spec.email = ['me@lucaguidi.com', 'trung.le@ruby-journal.com', 'uceda73@gmail.com']
spec.authors = ['Luca Guidi']
spec.email = ['me@lucaguidi.com']
spec.summary = 'The web, with simplicity'
spec.description = 'Hanami is a web framework for Ruby'
spec.homepage = 'http://hanamirb.org'
Expand All @@ -21,14 +21,14 @@ Gem::Specification.new do |spec|

spec.metadata['allowed_push_host'] = 'https://rubygems.org'

spec.add_dependency 'hanami-utils', '~> 1.0.0.beta3'
spec.add_dependency 'hanami-validations', '~> 1.0.0.beta2'
spec.add_dependency 'hanami-router', '~> 1.0.0.beta3'
spec.add_dependency 'hanami-controller', '~> 1.0.0.beta3'
spec.add_dependency 'hanami-view', '~> 1.0.0.beta2'
spec.add_dependency 'hanami-helpers', '~> 1.0.0.beta2'
spec.add_dependency 'hanami-mailer', '~> 1.0.0.beta2'
spec.add_dependency 'hanami-assets', '~> 1.0.0.beta2'
spec.add_dependency 'hanami-utils', '~> 1.0'
spec.add_dependency 'hanami-validations', '~> 1.0'
spec.add_dependency 'hanami-router', '~> 1.0'
spec.add_dependency 'hanami-controller', '~> 1.0'
spec.add_dependency 'hanami-view', '~> 1.0'
spec.add_dependency 'hanami-helpers', '~> 1.0'
spec.add_dependency 'hanami-mailer', '~> 1.0'
spec.add_dependency 'hanami-assets', '~> 1.0'
spec.add_dependency 'concurrent-ruby', '~> 1.0'
spec.add_dependency 'thor', '~> 0.19'
spec.add_dependency 'bundler', '~> 1.13'
Expand Down
8 changes: 6 additions & 2 deletions lib/hanami.rb
Expand Up @@ -84,10 +84,14 @@ def self.configuration
#
# NOTE: This MUST NOT be wrapped by a Mutex, because it would cause a deadlock.
#
# @return [NilClass]
#
# @since 0.9.0
def self.boot
Components.release if code_reloading?
Components.resolve('all')
Hanami::Model.disconnect if defined?(Hanami::Model)
nil
end

# Main application that mounts many Rack and/or Hanami applications.
Expand Down Expand Up @@ -196,7 +200,7 @@ def self.environment
#
# @return [TrueClass,FalseClass] the result of the check
#
# @since 1.0.0.beta1
# @since 1.0.0
# @api private
#
# @see http://hanamirb.org/guides/projects/code-reloading/
Expand All @@ -210,7 +214,7 @@ def self.code_reloading?
#
# @return [Hanami::Logger] the logger
#
# @since 1.0.0.beta1
# @since 1.0.0
def self.logger
Components['logger']
end
Expand Down
2 changes: 1 addition & 1 deletion lib/hanami/application_configuration.rb
Expand Up @@ -19,7 +19,7 @@ class ApplicationConfiguration
# @see Hanami::Configuration#ssl?
SSL_SCHEME = 'https'.freeze

# @since 1.0.0.beta1
# @since 1.0.0
# @api private
DEFAULT_SSL_PORT = 443

Expand Down
2 changes: 1 addition & 1 deletion lib/hanami/commands/generate/abstract.rb
Expand Up @@ -65,7 +65,7 @@ def assert_options!
end
end

# @since 1.0.0.beta1
# @since 1.0.0
# @api private
def project_name
Utils::String.new(Hanami::Environment.new.project_name).underscore
Expand Down
8 changes: 7 additions & 1 deletion lib/hanami/commands/new/abstract.rb
Expand Up @@ -6,6 +6,7 @@
require 'hanami/generators/template_engine'
require 'hanami/utils'
require 'hanami/utils/hash'
require 'hanami/utils/string'

module Hanami
# @api private
Expand Down Expand Up @@ -45,7 +46,7 @@ def initialize(options, name)
assert_name!
assert_architecture!

@hanami_model_version = '~> 1.0.0.beta3'
@hanami_model_version = '~> 1.0'
@database_config = Hanami::Generators::DatabaseConfig.new(options[:database], project_name)
@test_framework = Hanami::Generators::TestFramework.new(hanamirc, @options[:test])
@template_engine = Hanami::Generators::TemplateEngine.new(hanamirc, @options[:template])
Expand Down Expand Up @@ -99,6 +100,11 @@ def project_name
ApplicationName.new(real_project_name)
end

# @api private
def project_module
Utils::String.new(project_name).classify
end

# @api private
def project_directory
@name == '.' ? '.' : project_name
Expand Down
1 change: 1 addition & 0 deletions lib/hanami/commands/new/container.rb
Expand Up @@ -25,6 +25,7 @@ def map_templates
def template_options
{
project_name: project_name,
project_module: project_module,
hanami_head: hanami_head?,
code_reloading: code_reloading?,
test: test_framework.framework,
Expand Down
20 changes: 10 additions & 10 deletions lib/hanami/common_logger.rb
Expand Up @@ -3,44 +3,44 @@
module Hanami
# Rack logger for Hanami.app
#
# @since 1.0.0.beta1
# @since 1.0.0
# @api private
class CommonLogger < Rack::CommonLogger
private

# @since 1.0.0.beta1
# @since 1.0.0
# @api private
HTTP_VERSION = 'HTTP_VERSION'.freeze

# @since 1.0.0.beta1
# @since 1.0.0
# @api private
REQUEST_METHOD = 'REQUEST_METHOD'.freeze

# @since 1.0.0.beta1
# @since 1.0.0
# @api private
HTTP_X_FORWARDED_FOR = 'HTTP_X_FORWARDED_FOR'.freeze

# @since 1.0.0.beta1
# @since 1.0.0
# @api private
REMOTE_ADDR = 'REMOTE_ADDR'.freeze

# @since 1.0.0.beta1
# @since 1.0.0
# @api private
SCRIPT_NAME = 'SCRIPT_NAME'.freeze

# @since 1.0.0.beta1
# @since 1.0.0
# @api private
PATH_INFO = 'PATH_INFO'.freeze

# @since 1.0.0.beta1
# @since 1.0.0
# @api private
QUERY_STRING = 'QUERY_STRING'.freeze

# @since 1.0.0.beta1
# @since 1.0.0
# @api private
RACK_ERRORS = 'rack.errors'.freeze

# @since 1.0.0.beta1
# @since 1.0.0
# @api private
#
# rubocop:disable Metrics/AbcSize
Expand Down
2 changes: 1 addition & 1 deletion lib/hanami/components.rb
Expand Up @@ -106,7 +106,7 @@ def self.[](name)
#
# NOTE: this MUST NOT be used unless you know what you're doing.
#
# @since 1.0.0.beta1
# @since 1.0.0
# @api private
def self.release
@_resolved.clear
Expand Down