### Home Classes Methods

### In Files

- lib/ramaze/log/informer.rb

### Parent

Object

### Methods

- ::new
- #closed?
- #log
- #log_interpolate
- #shutdown
- #timestamp

### Included Modules

- Ramaze::Logging
- Innate::Traited

### Class/Module Index

Quicksearch

- Ramaze
- Ramaze::App
- Ramaze::AppGraph
- Ramaze::Bin
- Ramaze::Bin::Console
- Ramaze::Bin::Create
- Ramaze::Bin::Helper
- Ramaze::Bin::Restart
- Ramaze::Bin::Runner
- Ramaze::Bin::Start
- Ramaze::Bin::Status
- Ramaze::Bin::Stop
- Ramaze::Cache
- Ramaze::Cache::LRU
- Ramaze::Cache::LocalMemCache
- Ramaze::Cache::MemCache
- Ramaze::Cache::Redis
- Ramaze::Cache::Sequel
- Ramaze::Controller
- Ramaze::CoreExtensions
- Ramaze::CoreExtensions::Array
- Ramaze::CoreExtensions::Binding
- Ramaze::CoreExtensions::Kernel
- Ramaze::CoreExtensions::Numeric
- Ramaze::CoreExtensions::Object
- Ramaze::CoreExtensions::Proc
- Ramaze::CoreExtensions::String
- Ramaze::Current
- Ramaze::DefaultController
- Ramaze::Dictionary
- Ramaze::Fiber
- Ramaze::Files
- Ramaze::GemSetup
- Ramaze::Gestalt
- Ramaze::Helper
- Ramaze::Helper::Auth
- Ramaze::Helper::Bench
- Ramaze::Helper::BlueForm
- Ramaze::Helper::BlueForm::Form
- Ramaze::Helper::CSRF
- Ramaze::Helper::Cache
- Ramaze::Helper::Cache::SingletonMethods
- Ramaze::Helper::Disqus
- Ramaze::Helper::Email
- Ramaze::Helper::Erector
- Ramaze::Helper::Flash
- Ramaze::Helper::Formatting
- Ramaze::Helper::Gestalt
- Ramaze::Helper::Gravatar
- Ramaze::Helper::Identity
- Ramaze::Helper::Layout
- Ramaze::Helper::Layout::SingletonMethods
- Ramaze::Helper::Link
- Ramaze::Helper::Localize
- Ramaze::Helper::Localize::Dictionary
- Ramaze::Helper::Localize::Parser
- Ramaze::Helper::Markaby
- Ramaze::Helper::Maruku
- Ramaze::Helper::Paginate
- Ramaze::Helper::Paginate::Paginator
- Ramaze::Helper::Paginate::Paginator::ArrayPager
- Ramaze::Helper::Paginate::Paginator::DataMapperPager
- Ramaze::Helper::Remarkably
- Ramaze::Helper::RequestAccessor
- Ramaze::Helper::SendFile
- Ramaze::Helper::SimpleCaptcha
- Ramaze::Helper::Stack
- Ramaze::Helper::Thread
- Ramaze::Helper::Ultraviolet
- Ramaze::Helper::Upload
- Ramaze::Helper::Upload::ClassMethods
- Ramaze::Helper::Upload::UploadedFile
- Ramaze::Helper::UserHelper
- Ramaze::Helper::UserHelper::Wrapper
- Ramaze::Helper::XHTML
- Ramaze::LRUHash
- Ramaze::Logger
- Ramaze::Logger::Analogger
- Ramaze::Logger::Growl
- Ramaze::Logger::Informer
- Ramaze::Logger::Knotify
- Ramaze::Logger::LogHub
- Ramaze::Logger::Logger
- Ramaze::Logger::RotatingInformer
- Ramaze::Logger::Syslog
- Ramaze::Logger::Xosd
- Ramaze::Logging
- Ramaze::MiddlewareCompiler
- Ramaze::Plugin
- Ramaze::Reloader
- Ramaze::Reloader::Hooks
- Ramaze::Reloader::WatchInotify
- Ramaze::Reloader::WatchStat
- Ramaze::Request
- Ramaze::Response
- Ramaze::SpecLogger
- Ramaze::Struct
- Ramaze::View
- Ramaze::View::Erector
- Ramaze::View::Erubis
- Ramaze::View::Ezamar
- Ramaze::View::Gestalt
- Ramaze::View::Haml
- Ramaze::View::Liquid
- Ramaze::View::Liquid::Tag
- Ramaze::View::Lokar
- Ramaze::View::Mustache
- Ramaze::View::Mustache::RamazeContext
- Ramaze::View::Nagoro
- Ramaze::View::Remarkably
- Ramaze::View::Sass
- Ramaze::View::Slippers
- Ramaze::View::Tagz
- Ramaze::View::Tagz::Methods
- Ramaze::View::Tenjin
- Nagoro
- Nagoro::Pipe
- Nagoro::Pipe::RenderPartial
- Bacon
- Bacon::PrettyOutput
- Erector
- Erector::Widget
- Rack
- Rack::RouteExceptions
- Tenjin
- Tenjin::Template
- BlankSlate
- Controller
- Fiber
- FiberError
- MainController
- Object
- OrderedSet
- Thread

No matching classes.

# Ramaze::Logger::Informer

A minimal logger for Ramaze, supports files, CLI, colors and some customization.

### Constants

COLORS

  Which tag should be in what color

### Attributes

colorize[RW]
log_levels[RW]
out[RW]

### Public Class Methods

new(out = $stdout, log_levels = [:debug, :error, :info, :warn]) click to toggle source

Create a new instance of Informer.

@example

    Informer.new          # => logs to stdout with all levels being shown.
    Informer.new($stderr) # => same, but to stderr

    # same, but logs to the file foo.log (or creates it if it doesn't
    # exist yet)
    Informer.new("foo.log")

    Informer.new($stdout, [:info]) #=> show only #info messages to stdout.

@param [String] out Specifies where the output should go. By default

    this is set to STDOUT.

@param [Array] log_leves Array containing the levels that should be

    logged.

    # File lib/ramaze/log/informer.rb, line 54
    def initialize(out = $stdout, log_levels = [:debug, :error, :info, :warn])
      @colorize = false

      @out =
        case out
        when STDOUT, :stdout, 'stdout'
          $stdout
        when STDERR, :stderr, 'stderr'
          $stderr
        when IO
          out
        else
          if out.respond_to?(:puts)
            out
          else
            File.open(out.to_s, 'ab+')
          end
        end

      if @out.respond_to?(:tty?) and class_trait[:colorize]
        @colorize = @out.tty?
      end

      @log_levels = log_levels
    end

### Public Instance Methods

closed?() click to toggle source

Is @out closed?

    # File lib/ramaze/log/informer.rb, line 144
    def closed?
      @out.respond_to?(:closed?) and @out.closed?
    end

log(tag, *messages) click to toggle source

Integration to Logging

@param [String] tag The log level for the current message(s). @param [Array] messages Array containing the data that should be logged.

    # File lib/ramaze/log/informer.rb, line 96
    def log tag, *messages
      return if closed? || !@log_levels.include?(tag)
      messages.flatten!

      prefix = tag.to_s.upcase.ljust(5)

      if @colorize
        color = COLORS[tag] ||= :white
        prefix.replace prefix.send(color)
      end

      messages.each do |message|
        @out.puts(log_interpolate(prefix, message))
      end

      @out.flush if @out.respond_to?(:flush)
    end

log_interpolate(prefix, text, time = timestamp) click to toggle source

Takes the prefix (tag), text and timestamp and applies it to the :format trait.

@param [String] prefix @param [String] text @param [Integer] time

    # File lib/ramaze/log/informer.rb, line 122
    def log_interpolate prefix, text, time = timestamp
      message = class_trait[:format].dup

      vars = { '%time' => time, '%prefix' => prefix, '%text' => text }
      vars.each{|from, to| message.gsub!(from, to) }

      message
    end

shutdown() click to toggle source

Close the file we log to if it isn't closed already.

    # File lib/ramaze/log/informer.rb, line 83
    def shutdown
      if @out.respond_to?(:close)
        Log.debug("close, #{@out.inspect}")
        @out.close
      end
    end

timestamp() click to toggle source

This uses timestamp trait or a date in the format of

    %Y-%m-%d %H:%M:%S
    # => "2007-01-19 21:09:32"

    # File lib/ramaze/log/informer.rb, line 136
    def timestamp
      mask = class_trait[:timestamp]
      Time.now.strftime(mask || "%Y-%m-%d %H:%M:%S")
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.