Skip to content

Commit

Permalink
Removed the duplication for defining the logger accessors everywhere …
Browse files Browse the repository at this point in the history
…and instead created a logging helper which is included into Object.
  • Loading branch information
mtodd committed Apr 14, 2008
1 parent 32cd998 commit 7b46aa2
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 41 deletions.
3 changes: 3 additions & 0 deletions lib/halcyon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,6 @@ def root
end

end

#logger and klass.logger methods for use everywhere.
Object.send(:include, Halcyon::Logging::Helpers)
10 changes: 1 addition & 9 deletions lib/halcyon/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Halcyon
#
# Manages shutting down and starting up hooks, routing, dispatching, etc.
# Also restricts the requests to acceptable clients, defaulting to all.
class Application
class Application
include Exceptions

autoload :Router, 'halcyon/application/router'
Expand Down Expand Up @@ -167,10 +167,6 @@ def acceptable_request!(env)
end
end

def logger
Halcyon.logger
end

def hooks
self.class.hooks
end
Expand All @@ -183,10 +179,6 @@ def hooks
@hooks ||= {}
end

def logger
Halcyon.logger
end

# Defines routes for the application.
#
# Refer to Halcyon::Application::Router for documentation and resources.
Expand Down
4 changes: 0 additions & 4 deletions lib/halcyon/application/router.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@ class Router < Merb::Router

class << self

def logger
Halcyon.logger
end

# Retrieves the last value from the +route+ call in Halcyon::Controller
# and, if it's a Hash, sets it to +@@default_route+ to designate the
# failover route. If +route+ is not a Hash, though, the internal default
Expand Down
20 changes: 0 additions & 20 deletions lib/halcyon/controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,6 @@ def initialize(env)

class << self

# The current application logger instance, usable in the class context.
# This means you can call <tt>self.logger</tt> from inside of class
# methods, filters, etc.
#
# Examples
# self.logger.debug "Test message"
#
# Returns Logger:logger
def logger
Halcyon.logger
end

# Not implemented.
def before method, &proc
raise NotImplemented.new
Expand All @@ -43,14 +31,6 @@ def after method, &proc

end

# The current application logger instance.
#
# Examples
# self.logger.debug "Deleting user's cached data"
def logger
Halcyon.logger
end

# Returns the request params and the route params.
#
# Returns Hash:{route_params, get_params, post_params}.to_mash
Expand Down
2 changes: 2 additions & 0 deletions lib/halcyon/logging.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module Halcyon
module Logging

autoload :Helpers, 'halcyon/logging/helpers'

autoload :Logger, 'halcyon/logging/logger'
autoload :Logging, 'halcyon/logging/logging'
autoload :Analogger, 'halcyon/logging/analogger'
Expand Down
37 changes: 37 additions & 0 deletions lib/halcyon/logging/helpers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
module Halcyon
module Logging
module Helpers

def self.included(target)
target.extend(ClassMethods)
end

# The current application logger instance.
#
# Examples
# self.logger.debug "Deleting user's cached data"
#
# Returns Logger:logger
def logger
Halcyon.logger
end

module ClassMethods

# The current application logger instance, usable in the class context.
# This means you can call <tt>self.logger</tt> from inside of class
# methods, filters, etc.
#
# Examples
# self.logger.debug "Test message"
#
# Returns Logger:logger
def logger
Halcyon.logger
end

end

end
end
end
8 changes: 0 additions & 8 deletions lib/halcyon/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,8 @@ def call(env)
@app.call(env)
end

def logger
Halcyon.logger
end

class << self

def logger
Halcyon.logger
end

# Loads the configuration file specified into <tt>Halcyon.config</tt>.
# +file+ the configuration file to load
#
Expand Down

0 comments on commit 7b46aa2

Please sign in to comment.