lib/logger.rb in narou-2.5.2 vs lib/logger.rb in narou-2.6.0
- old
+ new
@@ -105,22 +105,34 @@
else
write_color(str, target)
end
end
end
+
+ def write_base(str, stream)
+ str = str.to_s
+ if str.encoding == Encoding::ASCII_8BIT
+ str.force_encoding(Encoding::UTF_8)
+ end
+ write_console(str, stream)
+ end
+
+ def warn(str)
+ self.puts str
+ end
+
+ def error(str)
+ self.puts "<bold><red>[ERROR]</red></bold> ".termcolor + str
+ end
end
class Narou::Logger < StringIO
include Narou::LoggerModule
def write(str)
- str = str.to_s
- if str.encoding == Encoding::ASCII_8BIT
- str.force_encoding(Encoding::UTF_8)
- end
+ write_base(str, STDOUT)
super(str)
- write_console(str, STDOUT)
end
def tty?
STDOUT.tty?
end
@@ -128,28 +140,24 @@
class Narou::LoggerError < StringIO
include Narou::LoggerModule
def write(str)
- str = str.to_s
- if str.encoding == Encoding::ASCII_8BIT
- str.force_encoding(Encoding::UTF_8)
- end
+ write_base(str, STDERR)
super(str)
- write_console(str, STDERR)
end
def tty?
STDERR.tty?
end
end
def warn(str)
- puts str
+ $stdout.warn str
end
def error(str)
- puts "<bold><red>[ERROR]</red></bold> ".termcolor + str
+ $stdout.error str
end
$stdout = Narou::Logger.new
$stderr = Narou::LoggerError.new