Sha256: f88f9ba21f117f2d32fdb6439e64c7dbc6fe86d3623be96954b454657fd6bfaa

Contents?: true

Size: 1.29 KB

Versions: 6

Compression:

Stored size: 1.29 KB

Contents

module Locomotive
  module Builder

    class Logger

      attr_accessor :logger, :logfile_path, :stdout

      def initialize
        self.logger = nil
      end

      # Setup the single instance of the ruby logger.
      #
      # @param [ String ] path The path to the log file (default: log/builder.log)
      # @param [ Boolean ] stdout Instead of having a file, log to the standard output
      #
      def setup(path, stdout = false)
        require 'logger'

        self.stdout = stdout

        self.logfile_path = File.expand_path(File.join(path, 'log', 'builder.log'))
        FileUtils.mkdir_p(File.dirname(logfile_path))

        out = self.stdout ? STDOUT : self.logfile_path

        self.logger = ::Logger.new(out).tap do |log|
          log.level     = ::Logger::DEBUG
          log.formatter = proc do |severity, datetime, progname, msg|
            "#{msg}\n"
          end
        end
      end

      def self.instance
        @@instance ||= self.new
      end

      def self.setup(path, stdout = false)
        self.instance.setup(path, stdout)
      end

      class << self
        %w(debug info warn error fatal unknown).each do |name|
          define_method(name) do |message|
            self.instance.logger.send(name.to_sym, message)
          end
        end
      end

    end

  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
locomotivecms_builder-1.0.0.alpha8 lib/locomotive/builder/logger.rb
locomotivecms_builder-1.0.0.alpha7 lib/locomotive/builder/logger.rb
locomotivecms_builder-1.0.0.alpha6 lib/locomotive/builder/logger.rb
locomotivecms_builder-1.0.0.alpha5 lib/locomotive/builder/logger.rb
locomotivecms_builder-1.0.0.alpha4 lib/locomotive/builder/logger.rb
locomotivecms_builder-1.0.0.alpha3 lib/locomotive/builder/logger.rb