Class: Sappho::AutoFlushLog
- Inherits:
-
Object
- Object
- Sappho::AutoFlushLog
- Defined in:
- lib/sappho-basics/auto_flush_log.rb
Direct Known Subclasses
Constant Summary collapse
- LOG_LEVELS =
{ 'debug' => Logger::DEBUG, 'info' => Logger::INFO, 'warn' => Logger::WARN, 'error' => Logger::ERROR, 'fatal' => Logger::FATAL }
- LOG_DETAIL =
{ 'message' => proc { |severity, datetime, progname, | "#{}\n" }, 'test' => proc { |severity, datetime, progname, | "#{severity} #{}\n" } }
Class Method Summary collapse
Instance Method Summary collapse
- #debug(message) ⇒ Object
- #debug? ⇒ Boolean
- #error(error) ⇒ Object
- #fatal(error) ⇒ Object
- #info(message) ⇒ Object
-
#initialize(file, level, detail) ⇒ AutoFlushLog
constructor
A new instance of AutoFlushLog.
- #warn(message) ⇒ Object
Constructor Details
#initialize(file, level, detail) ⇒ AutoFlushLog
Returns a new instance of AutoFlushLog.
26 27 28 29 30 31 |
# File 'lib/sappho-basics/auto_flush_log.rb', line 26 def initialize file, level, detail @mutex = Mutex.new @log = Logger.new file @log.level = LOG_LEVELS.has_key?(level) ? LOG_LEVELS[level] : Logger::INFO @log.formatter = LOG_DETAIL[detail] if LOG_DETAIL.has_key?(detail) end |
Class Method Details
.file(file) ⇒ Object
82 83 84 |
# File 'lib/sappho-basics/auto_flush_log.rb', line 82 def AutoFlushLog.file file @@file = file end |
Instance Method Details
#debug(message) ⇒ Object
33 34 35 36 37 38 |
# File 'lib/sappho-basics/auto_flush_log.rb', line 33 def debug @mutex.synchronize do @log.debug $stdout.flush end if @log.debug? end |
#debug? ⇒ Boolean
70 71 72 |
# File 'lib/sappho-basics/auto_flush_log.rb', line 70 def debug? @log.debug? end |
#error(error) ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/sappho-basics/auto_flush_log.rb', line 54 def error error @mutex.synchronize do @log.error "error! #{error.}" error.backtrace.each { |error| @log.error error } $stdout.flush end if @log.error? end |
#fatal(error) ⇒ Object
62 63 64 65 66 67 68 |
# File 'lib/sappho-basics/auto_flush_log.rb', line 62 def fatal error @mutex.synchronize do @log.fatal "error! #{error.}" error.backtrace.each { |error| @log.fatal error } $stdout.flush end if @log.fatal? end |
#info(message) ⇒ Object
40 41 42 43 44 45 |
# File 'lib/sappho-basics/auto_flush_log.rb', line 40 def info @mutex.synchronize do @log.info $stdout.flush end if @log.info? end |
#warn(message) ⇒ Object
47 48 49 50 51 52 |
# File 'lib/sappho-basics/auto_flush_log.rb', line 47 def warn @mutex.synchronize do @log.warn $stdout.flush end if @log.warn? end |