mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
daee6fd92a
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@518 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
46 lines
893 B
Ruby
46 lines
893 B
Ruby
module Rails
|
|
module Generator
|
|
class SimpleLogger # :nodoc:
|
|
attr_reader :out
|
|
attr_accessor :quiet
|
|
|
|
def initialize(out = $stdout)
|
|
@out = out
|
|
@quiet = false
|
|
@level = 0
|
|
end
|
|
|
|
def log(status, message, &block)
|
|
@out.print("%12s %s%s\n" % [status, ' ' * @level, message]) unless quiet
|
|
indent(&block) if block_given?
|
|
end
|
|
|
|
def indent(&block)
|
|
@level += 1
|
|
if block_given?
|
|
begin
|
|
block.call
|
|
ensure
|
|
outdent
|
|
end
|
|
end
|
|
end
|
|
|
|
def outdent
|
|
@level -= 1
|
|
if block_given?
|
|
begin
|
|
block.call
|
|
ensure
|
|
indent
|
|
end
|
|
end
|
|
end
|
|
|
|
private
|
|
def method_missing(method, *args, &block)
|
|
log(method.to_s, args.first, &block)
|
|
end
|
|
end
|
|
end
|
|
end
|