Class: Ponder::Logger::Twoflogger
- Inherits:
-
Object
- Object
- Ponder::Logger::Twoflogger
- Defined in:
- lib/ponder/logger/twoflogger.rb,
lib/ponder/logger/twoflogger18.rb
Instance Attribute Summary collapse
-
#level ⇒ Object
Returns the value of attribute level.
-
#levels ⇒ Object
Returns the value of attribute levels.
-
#time_format ⇒ Object
Returns the value of attribute time_format.
Instance Method Summary collapse
-
#initialize(destination = Ponder.root.join('logs', 'log.log'), level = :debug, time_format = '%Y-%m-%d %H:%M:%S', levels = {:debug => 0, :info => 1, :warn => 2, :error => 3, :fatal => 4, :unknown => 5}) ⇒ Twoflogger
constructor
A new instance of Twoflogger.
- #log_dev=(destination) ⇒ Object
- #start_logging ⇒ Object
- #stop_logging ⇒ Object
Constructor Details
#initialize(destination = Ponder.root.join('logs', 'log.log'), level = :debug, time_format = '%Y-%m-%d %H:%M:%S', levels = {:debug => 0, :info => 1, :warn => 2, :error => 3, :fatal => 4, :unknown => 5}) ⇒ Twoflogger
Returns a new instance of Twoflogger.
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/ponder/logger/twoflogger.rb', line 10 def initialize(destination = Ponder.root.join('logs', 'log.log'), level = :debug, time_format = '%Y-%m-%d %H:%M:%S', levels = {:debug => 0, :info => 1, :warn => 2, :error => 3, :fatal => 4, :unknown => 5}) @level = level @time_format = time_format @levels = levels @queue = Queue.new @mutex = Mutex.new @running = false define_level_shorthand_methods self.log_dev = destination end |
Instance Attribute Details
#level ⇒ Object
Returns the value of attribute level.
8 9 10 |
# File 'lib/ponder/logger/twoflogger.rb', line 8 def level @level end |
#levels ⇒ Object
Returns the value of attribute levels.
8 9 10 |
# File 'lib/ponder/logger/twoflogger.rb', line 8 def levels @levels end |
#time_format ⇒ Object
Returns the value of attribute time_format.
8 9 10 |
# File 'lib/ponder/logger/twoflogger.rb', line 8 def time_format @time_format end |
Instance Method Details
#log_dev=(destination) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/ponder/logger/twoflogger.rb', line 39 def log_dev=(destination) stop_logging if destination.is_a?(Pathname) unless destination.exist? unless destination.dirname.directory? FileUtils.mkdir_p destination.dirname end File.new(destination, 'w+') end @log_dev = File.open(destination, 'a+') @log_dev.sync = true elsif destination.is_a?(IO) @log_dev = destination else raise TypeError, 'need a Pathname or IO' end end |
#start_logging ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/ponder/logger/twoflogger.rb', line 22 def start_logging @running = true @thread = Thread.new do begin while @running do write(@queue.pop) end ensure @log_dev.close if @log_dev.is_a?(File) end end end |
#stop_logging ⇒ Object
35 36 37 |
# File 'lib/ponder/logger/twoflogger.rb', line 35 def stop_logging @running = false end |