Sha256: 45e9b19ae3670e5d1329516ac69ab2da90b23bff665d587e1016dcf3697333e5

Contents?: true

Size: 1.2 KB

Versions: 2

Compression:

Stored size: 1.2 KB

Contents

# encoding: UTF-8

require_relative 'nil_logger'

module GoodData
  class << self
    attr_writer :logger
    attr_writer :stats

    # Turn logging on
    #
    # ### Example
    #
    #     GoodData.logging_on
    #
    def logging_on
      @logger = default_logger if logger.is_a? NilLogger
    end

    # Turn logging on
    #
    # ### Example
    #
    #     GoodData.logging_off
    #
    def logging_off
      @logger = NilLogger.new
    end

    def logging_on?
      !@logger.instance_of?(NilLogger)
    end

    # Returns the logger instance. The default implementation
    # is a logger to stdout on INFO level
    # For some serious logging, set the logger instance using
    # the logger= method
    #
    # ### Example
    #
    #     require 'logger'
    #     GoodData.logger = Logger.new(STDOUT)
    #
    def logger
      @logger ||= default_logger
    end

    def stats_on
      @stats = true
    end

    def stats_on? # rubocop:disable Style/TrivialAccessors
      @stats
    end

    def stats_off
      @stats = false
    end

    private

    # The default logger - stdout and INFO level
    #
    def default_logger
      log = Logger.new(STDOUT)
      log.level = Logger::INFO
      log
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
gooddata-0.6.18 lib/gooddata/core/logging.rb
gooddata-0.6.17 lib/gooddata/core/logging.rb