File: replay_logger.rb

package info (click to toggle)
ruby-dotenv 3.1.8-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 156 kB
  • sloc: ruby: 539; makefile: 4
file content (20 lines) | stat: -rw-r--r-- 553 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
module Dotenv
  # A logger that can be used before the apps real logger is initialized.
  class ReplayLogger < Logger
    def initialize
      super(nil) # Doesn't matter what this is, it won't be used.
      @logs = []
    end

    # Override the add method to store logs so we can replay them to a real logger later.
    def add(*args, &block)
      @logs.push([args, block])
    end

    # Replay the store logs to a real logger.
    def replay(logger)
      @logs.each { |args, block| logger.add(*args, &block) }
      @logs.clear
    end
  end
end