To replace an existing logger with a new one:
Merb::Logger.set_log(log{String, IO},level{Symbol, String})
Available logging levels are
Merb::Logger::{ Fatal, Error, Warn, Info, Debug }
Logging via:
Merb.logger.fatal(message<String>,&block) Merb.logger.error(message<String>,&block) Merb.logger.warn(message<String>,&block) Merb.logger.info(message<String>,&block) Merb.logger.debug(message<String>,&block)
Logging with autoflush:
Merb.logger.fatal!(message<String>,&block) Merb.logger.error!(message<String>,&block) Merb.logger.warn!(message<String>,&block) Merb.logger.info!(message<String>,&block) Merb.logger.debug!(message<String>,&block)
Flush the buffer to
Merb.logger.flush
Remove the current log object
Merb.logger.close
To initialize the logger you create a new object, proxies to set_log.
Merb::Logger.new(log{String, IO},level{Symbol, String})
VERSION | = | '0.9.3' unless defined?(Merb::VERSION) | ||
RELEASE | = | '' unless defined?(Merb::RELEASE) |
Merb::RELEASE meanings: ‘dev’ : unreleased ‘pre’ :
pre-release Gem candidates
nil : released You should never check in to trunk with this changed. It should stay ‘dev’. Change it to nil in release tags. |
environment | -> | env |
Any specific outgoing headers should be included here. These are not the content-type header but anything in addition to it. transform_method should be set to a symbol of the method used to transform a resource into this mime type. For example for the :xml mime type an object might be transformed by calling :to_xml, or for the :js mime type, :to_json. If there is no transform method, use nil.
Adding a mime-type adds a render_type method that sets the content type and calls render.
By default this does: def render_all, def render_yaml, def render_text, def render_html, def render_xml, def render_js, and def render_yaml
key<Symbol>: | The name of the mime-type. This is used by the provides API |
transform_method<~to_s>: | The associated method to call on objects to convert them to the appropriate mime-type. For instance, :json would use :to_json as its transform_method. |
values<Array[String]>: | A list of possible values sent in the Accept header, such as text/html, that should be associated with this content-type. |
new_response_headers<Hash>: | The response headers to set for the the mime type. |
*rakefiles: | Rakefile pathss to add to the list of Rakefiles. |
Recommended way to add Rakefiles load path for plugins authors.
If block was given configures using the block.
&block: | Configuration parameter block, see example below. |
Hash: | The current configuration. |
See Merb::GlobalHelpers.load_config for configuration options list.
Merb.config do beer "good" hashish :foo => "bar" environment "development" log_level "debug" use_mutex false session_store "cookie" session_secret_key "0d05a226affa226623eb18700" exception_details true reload_classes true reload_time 0.5 end
RegExp: | Regular expression against which deferred actions are matched by Rack application handler. |
Concatenates :deferred_actions configuration option values.
type<Symbol>: | The type of path to retrieve directory for, e.g. :view. |
String: | The directory for the requested type. |
Ask the question about which environment you‘re in.
env<Symbol, String>: | Name of the environment to query |
Merb.env #=> production Merb.env?(:production) #=> true Merb.env?(:development) #=> false
Allows flat apps by setting no default framework directories and yielding a Merb::Router instance. This is optional since the router will automatically configure the app with default routes.
r<Merb::Router::Behavior>: | The root behavior upon which new routes can be added. |
Used by script/frozen-merb and other freezers to mark Merb as frozen. See Merb::GlobalHelpers.frozen? for more details on framework freezing.
Boolean: | True if Merb is running via script/frozen-merb or other freezer. |
Freezing means bundling framework libraries with your application making it independent from environment it runs in. This is a good practice to freeze application framework and gems it uses and very useful when application is run in some sort of sandbox, for instance, shared hosting with preconfigured gems.
type<Symbol>: | The type of path to retrieve glob for, e.g. :view. |
String: | The pattern with which to match files within the type directory. |
Load configuration and assign logger.
options<Hash>: | Options to pass on to the Merb config. |
:host<String>: | host to bind to, default is 0.0.0.0. |
:port<Fixnum>: | port to run Merb application on, default is 4000. |
:adapter<String>: | name of Rack adapter to use, default is "runner" |
:rackup<String>: | name of Rack init file to use, default is "rack.rb" |
:reload_classes<Boolean>: | whether Merb should reload classes on each request, default is true |
:environment<String>: | name of environment to use, default is development |
:merb_root<String>: | Merb application root, default is Dir.pwd |
:use_mutex<Boolean>: | turns action dispatch synchronization on or off, default is on (true) |
:session_id_key<String>: | session identifier, default is _session_id |
:log_delimiter<String>: | what Merb logger uses as delimiter between message sections, default is " ~ " |
:log_auto_flush<Boolean>: | whether the log should automatically flush after new messages are added, defaults to true. |
:log_file<IO>: | IO for logger. Default is STDOUT. |
:log_level<Symbol>: | logger level, default is :warn |
:disabled_components<Array[Symbol]>: | array of disabled component names, for instance, to disable json gem, specify :json. Default is empty array. |
:deferred_actions<Array(Symbol, String)]>: | names of actions that should be deferred no matter what controller they belong to. Default is empty array. |
Some of these options come from command line on Merb application start, some of them are set in Merb init file or environment-specific.
key<Symbol>: | The key that represents the mime-type. |
Symbol: | The transform method for the mime type, e.g. :to_json. |
ArgumentError: | The requested mime type is not valid. |
This is the core mechanism for setting up your application layout. There are three application layouts in Merb:
Regular app/:type layout of Ruby on Rails fame:
app/models for models app/mailers for mailers (special type of controllers) app/parts for parts, Merb components app/views for templates app/controllers for controller lib for libraries
Flat application layout:
application.rb for models, controllers, mailers, etc config/init.rb for initialization and router configuration config/framework.rb for framework and dependencies configuration views for views
and Camping-style "very flat" application layout, where the whole Merb application and configs fit into a single file.
Autoloading for lib uses empty glob by default. If you want to have your libraries under lib use autoload, add the following to Merb init file:
Merb.push_path(:lib, Merb.root / "lib", "**/*.rb") # glob set explicity.
Then lib/magicwand/lib/magicwand.rb with MagicWand module will be autoloaded when you first access that constant.
This method gives you a way to build up your own application structure, for instance, to reflect the structure Rails uses to simplify transition of legacy application, you can set it up like this:
Merb.push_path(:models, Merb.root / "app" / "models", "**/*.rb") Merb.push_path(:mailers, Merb.root / "app" / "models", "**/*.rb") Merb.push_path(:controllers, Merb.root / "app" / "controllers", "**/*.rb") Merb.push_path(:views, Merb.root / "app" / "views", "**/*.rb")
type<Symbol>: | The type of path being registered (i.e. :view) |
path<String>: | The full path |
file_glob<String>: | A glob that will be used to autoload files under the path. Defaults to "**/*.rb". |
Array(String): | Paths Rakefiles are loaded from. |
Recommended way to find out what paths Rakefiles are loaded from.
Removes a MIME-type from the mime-type list.
key<Symbol>: | The key that represents the mime-type to remove. |
:all is the key for */*; It can‘t be removed.
Removes given types of application components from load path Merb uses for autoloading.
*args<Array(Symbol)>: | components names, for instance, :views, :models |
Using this combined with Merb::GlobalHelpers.push_path you can make your Merb application use legacy Rails application components.
Merb.root = "path/to/legacy/app/root" Merb.remove_paths(:mailers) Merb.push_path(:mailers, Merb.root / "app" / "models", "**/*.rb")
Will make Merb use app/models for mailers just like Ruby on Rails does.
*path: | The relative path (or list of path components) to a directory under the root of the application. |
String: | The full path including the root. |
Merb.root = "/home/merb/app" Merb.path("images") # => "/home/merb/app/images" Merb.path("views", "admin") # => "/home/merb/app/views/admin"