Class: Sappho::AutoFlushLog
- Inherits:
-
Object
- Object
- Sappho::AutoFlushLog
- Includes:
- Singleton
- Defined in:
- lib/sappho-basics/auto_flush_log.rb
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" } }
Instance Method Summary collapse
- #debug(message) ⇒ Object
- #debug? ⇒ Boolean
- #error(error) ⇒ Object
- #fatal(error) ⇒ Object
- #info(message) ⇒ Object
-
#initialize ⇒ AutoFlushLog
constructor
A new instance of AutoFlushLog.
- #warn(message) ⇒ Object
Constructor Details
#initialize ⇒ AutoFlushLog
Returns a new instance of AutoFlushLog.
27 28 29 30 31 32 33 34 35 |
# File 'lib/sappho-basics/auto_flush_log.rb', line 27 def initialize @mutex = Mutex.new filename = ENV['application.log.filename'] @log = Logger.new(filename ? File.open(filename, 'a') : $stdout) level = ENV['application.log.level'] @log.level = LOG_LEVELS.has_key?(level) ? LOG_LEVELS[level] : Logger::INFO detail = ENV['application.log.detail'] @log.formatter = LOG_DETAIL[detail] if LOG_DETAIL.has_key?(detail) end |
Instance Method Details
#debug(message) ⇒ Object
37 38 39 40 41 42 |
# File 'lib/sappho-basics/auto_flush_log.rb', line 37 def debug @mutex.synchronize do @log.debug $stdout.flush end if @log.debug? end |
#debug? ⇒ Boolean
74 75 76 |
# File 'lib/sappho-basics/auto_flush_log.rb', line 74 def debug? @log.debug? end |
#error(error) ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/sappho-basics/auto_flush_log.rb', line 58 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
66 67 68 69 70 71 72 |
# File 'lib/sappho-basics/auto_flush_log.rb', line 66 def fatal error @mutex.synchronize do @log.fatal "fatal error! #{error.}" error.backtrace.each { |error| @log.fatal error } $stdout.flush end if @log.fatal? end |
#info(message) ⇒ Object
44 45 46 47 48 49 |
# File 'lib/sappho-basics/auto_flush_log.rb', line 44 def info @mutex.synchronize do @log.info $stdout.flush end if @log.info? end |
#warn(message) ⇒ Object
51 52 53 54 55 56 |
# File 'lib/sappho-basics/auto_flush_log.rb', line 51 def warn @mutex.synchronize do @log.warn $stdout.flush end if @log.warn? end |