Removing color decorations from strings before writing them to logfile
This is my current solution
class ColourBlind
def initialize(*targets)
@targets = targets
end
def write(*args)
@targets.each {|t| t.write(*args.map {|x| x.gsub(/\e\[(\d+)m/, '')}.compact)}
end
def close
@targets.each(&:close)
end
end
And then:
$logger = Logger.new MultiIO.new($stdout, ColourBlind.new(log_file))
For removal of ANSI colors, I would recommend
string_with_ascii = "..."
string_no_ascii = string_with_ascii.gsub(/\e\[([;\d]+)?m/, '')