1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* lib/logger.rb: add Logger#<<(msg) for writing msg without any formatting.

* test/logger/test_logger.rb: ditto.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4586 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nahi 2003-09-23 14:12:42 +00:00
parent 603e0b1f19
commit 406fd7754e
3 changed files with 45 additions and 1 deletions

View file

@ -1,3 +1,10 @@
Mon Sep 23 23:10:16 2003 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
* lib/logger.rb: add Logger#<<(msg) for writing msg without any
formatting.
* test/logger/test_logger.rb: ditto.
Mon Sep 22 21:28:57 2003 WATANABE Hirofumi <eban@ruby-lang.org>
* MANIFEST: updated.

View file

@ -185,6 +185,24 @@ class Logger
end
alias log add
# SYNOPSIS
# Logger#<<(msg)
#
# ARGS
# msg Message.
#
# RETURN
# Same as IO#<<. If logdev is not given, returns nil.
#
# DESCRIPTION
# Dump given message to log device without any formatting.
#
def <<(msg)
unless @logdev.nil?
@logdev.write(msg)
end
end
# SYNOPSIS
# Logger#debug(progname = nil) { ... } = nil
# Logger#info(progname = nil) { ... } = nil

View file

@ -1,6 +1,5 @@
require 'test/unit'
require 'logger'
GC.start
class TestLoggerSeverity < Test::Unit::TestCase
def test_enum
@ -210,4 +209,24 @@ class TestLogger < Test::Unit::TestCase
log = log_add(logger, INFO, MyMsg.new)
assert_equal("my_msg\n", log.msg)
end
def test_lshift
r, w = IO.pipe
logger = Logger.new(w)
logger << "msg"
read_ready, = IO.select([r], nil, nil, 0.1)
w.close
msg = r.read
r.close
assert_equal("msg", msg)
#
r, w = IO.pipe
logger = Logger.new(w)
logger << "msg2\n\n"
read_ready, = IO.select([r], nil, nil, 0.1)
w.close
msg = r.read
r.close
assert_equal("msg2\n\n", msg)
end
end