lib/vedeu/support/log.rb in vedeu-0.4.36 vs lib/vedeu/support/log.rb in vedeu-0.4.37
- old
+ new
@@ -9,15 +9,15 @@
#
# @param logdev [String|IO] The filename (String) or IO object (typically
# STDOUT, STDERR or an open file).
#
def initialize(logdev)
- @level = DEBUG
+ @level = DEBUG
@default_formatter = Formatter.new
- @formatter = nil
- @logdev = nil
- @logdev = LocklessLogDevice.new(logdev) if logdev
+ @formatter = nil
+ @logdev = nil
+ @logdev = LocklessLogDevice.new(logdev) if logdev
end
# Ensures we can always write to the log file by creating a lock-less
# log device.
#
@@ -26,18 +26,18 @@
# Returns a new instance of Vedeu::LocklessLogDevice.
#
# @param log []
# @return []
def initialize(log = nil)
- @dev = nil
+ @dev = nil
@filename = nil
if log.respond_to?(:write) && log.respond_to?(:close)
@dev = log
else
- @dev = open_logfile(log)
+ @dev = open_logfile(log)
@dev.sync = true
@filename = log
end
end
@@ -97,9 +97,19 @@
#
# @return [TrueClass]
def log(message:, force: false, type: :info)
logger.debug([message_type(type),
message_body(type, message)]) if enabled? || force
+ end
+
+ # @return [TrueClass]
+ def log_stdout(type: :info, message:)
+ $stdout.puts [message_type(type), message_body(type, message)].join
+ end
+
+ # @return [TrueClass]
+ def log_stderr(type: :info, message:)
+ $stderr.puts [message_type(type), message_body(type, message)].join
end
# @return [TrueClass]
def logger
MonoLogger.new(log_file).tap do |log|