Sha256: cd88dfc4b5b4db608183d98f00d49e8f9c3bc3f6efac965a6e53e0900a7f99a0

Contents?: true

Size: 1.53 KB

Versions: 18

Compression:

Stored size: 1.53 KB

Contents

# Copyright (C) 2019  Kouhei Sutou <kou@clear-code.com>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

module ChupaText
  class CaptureLogger
    class << self
      def capture
        original_logger = ChupaText.logger
        begin
          output = []
          ChupaText.logger = new(output)
          yield
          output
        ensure
          ChupaText.logger = original_logger
        end
      end
    end

    def initialize(output)
      @output = output
    end

    def debug(message=nil)
      @output << [:debu, message || yield]
    end

    def info(message=nil)
      @output << [:info, message || yield]
    end

    def warn(message=nil)
      @output << [:warn, message || yield]
    end

    def error(message=nil)
      @output << [:error, message || yield]
    end

    def fatal(message=nil)
      @output << [:fatal, message || yield]
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
chupa-text-1.3.6 lib/chupa-text/capture-logger.rb
chupa-text-1.3.5 lib/chupa-text/capture-logger.rb
chupa-text-1.3.4 lib/chupa-text/capture-logger.rb
chupa-text-1.3.3 lib/chupa-text/capture-logger.rb
chupa-text-1.3.2 lib/chupa-text/capture-logger.rb
chupa-text-1.3.1 lib/chupa-text/capture-logger.rb
chupa-text-1.3.0 lib/chupa-text/capture-logger.rb
chupa-text-1.2.9 lib/chupa-text/capture-logger.rb
chupa-text-1.2.8 lib/chupa-text/capture-logger.rb
chupa-text-1.2.7 lib/chupa-text/capture-logger.rb
chupa-text-1.2.6 lib/chupa-text/capture-logger.rb
chupa-text-1.2.5 lib/chupa-text/capture-logger.rb
chupa-text-1.2.4 lib/chupa-text/capture-logger.rb
chupa-text-1.2.3 lib/chupa-text/capture-logger.rb
chupa-text-1.2.2 lib/chupa-text/capture-logger.rb
chupa-text-1.2.1 lib/chupa-text/capture-logger.rb
chupa-text-1.2.0 lib/chupa-text/capture-logger.rb
chupa-text-1.1.9 lib/chupa-text/capture-logger.rb