Skip to content

Maintenance Ruby 3.4 gets fixes, but no new features. Switch to Ruby 4.0 →

instance method

Logger#reopen

() -> self
(::Logger::logdev?) -> self
reopen(logdev = nil)

Sets the logger’s output stream:

  • If logdev is nil, reopens the current output stream.

  • If logdev is a filepath, opens the indicated file for append.

  • If logdev is an IO stream (usually $stdout, $stderr, or an open File object), opens the stream for append.

Example:

Example
logger = Logger.new('t.log')
logger.add(Logger::ERROR, 'one')
logger.close
logger.add(Logger::ERROR, 'two') # Prints 'log writing failed. closed stream'
logger.reopen
logger.add(Logger::ERROR, 'three')
logger.close
File.readlines('t.log')
# =>
# ["# Logfile created on 2022-05-12 14:21:19 -0500 by logger.rb/v1.5.0\n",
#  "E, [2022-05-12T14:21:27.596726 #22428] ERROR -- : one\n",
#  "E, [2022-05-12T14:23:05.847241 #22428] ERROR -- : three\n"]