From d0a02321bf53798525d17f1c53ed780c2fe7437b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E5=86=9B=E6=A0=8B?= Date: Mon, 17 Aug 2020 10:25:56 +0800 Subject: [PATCH] Add environment variable to set log debug output --- lib/aliyun/common/logging.rb | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/aliyun/common/logging.rb b/lib/aliyun/common/logging.rb index 043785c..52d5a3f 100644 --- a/lib/aliyun/common/logging.rb +++ b/lib/aliyun/common/logging.rb @@ -37,11 +37,27 @@ def self.logger @log_file ||= ENV["ALIYUN_OSS_SDK_LOG_PATH"] @logger = Logger.new( @log_file, MAX_NUM_LOG, ROTATE_SIZE) - @logger.level = Logger::INFO + @logger.level = get_env_log_level || Logger::INFO end @logger end + def self.get_env_log_level + return unless ENV["ALIYUN_OSS_SDK_LOG_LEVEL"] + case ENV["ALIYUN_OSS_SDK_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 # logging end # Common end # Aliyun