Sha256: af91722391c757e85f74bc6fd3f2f4419ad113926a624b5f174d30e0e3ecfe3d

Contents?: true

Size: 1.25 KB

Versions: 53

Compression:

Stored size: 1.25 KB

Contents

require 'logger'

module Gitea
  module Common 

    ## 
    # Logging support
    # @example 
    #   include Logging
    #   logger.info(xxx)

    module Logging 

      MAX_NUM_LOG = 100
      ROTATE_SIZE = 10 * 1024 * 1024

      # level = Logger::DEBUG | Logger::INFO | Logger::ERROR | Logger::FATAL
      def self.set_log_level(level)
        Logging.logger.level = level
      end

      # 设置日志输出的文件
      def self.set_log_file(file)
        @log_file = file
      end

      # 获取logger
      def logger 
        Logging.logger 
      end

      private 

      def self.logger 
        unless @logger 
          @log_file ||= ENV["GITEA_CLIENT_LOG_PATH"]
          @logger = Logger.new(
            @log_file, MAX_NUM_LOG, ROTATE_SIZE)
          @logger.level = get_env_log_level || Logger::INFO
        end
        @logger
      end

      def self.get_env_log_level
        return unless ENV["GITEA_CLIENT_LOG_LEVEL"]
        case ENV["GITEA_CLIENT_LOG_LEVEL"].upcase
        when "DEBUG"
          Logger::DEBUG
        when "WARN"
          Logger::WARN
        when "ERROR"
          Logger::ERROR
        when "FATAL"
          Logger::FATAL
        when "UNKNOWN"
          Logger::UNKNOWN
        end
      end

    end
  end # Common
end # Gitea

Version data entries

53 entries across 53 versions & 1 rubygems

Version Path
gitea-client-1.6.1 lib/gitea/common/logging.rb
gitea-client-1.6.0 lib/gitea/common/logging.rb
gitea-client-1.5.9 lib/gitea/common/logging.rb
gitea-client-1.5.8 lib/gitea/common/logging.rb
gitea-client-1.5.6 lib/gitea/common/logging.rb
gitea-client-1.5.0 lib/gitea/common/logging.rb
gitea-client-1.4.6 lib/gitea/common/logging.rb
gitea-client-1.4.5 lib/gitea/common/logging.rb
gitea-client-1.4.4 lib/gitea/common/logging.rb
gitea-client-1.4.3 lib/gitea/common/logging.rb
gitea-client-1.4.2 lib/gitea/common/logging.rb
gitea-client-1.4.1 lib/gitea/common/logging.rb
gitea-client-1.4.0 lib/gitea/common/logging.rb
gitea-client-1.3.3 lib/gitea/common/logging.rb
gitea-client-1.3.2 lib/gitea/common/logging.rb
gitea-client-1.3.0 lib/gitea/common/logging.rb
gitea-client-1.3.1 lib/gitea/common/logging.rb
gitea-client-0.11.6 lib/gitea/common/logging.rb
gitea-client-0.11.5 lib/gitea/common/logging.rb
gitea-client-1.2.2 lib/gitea/common/logging.rb