Class: JPSClient::Logger
- Inherits:
-
Object
- Object
- JPSClient::Logger
- Defined in:
- lib/jpsclient/utils/logger.rb
Overview
简单的Logger实现,替代Funlog
Class Method Summary collapse
Instance Method Summary collapse
- #error(message) ⇒ Object
- #fancyinfo_complete(message) ⇒ Object
- #fancyinfo_error(message) ⇒ Object
- #fancyinfo_start(message) ⇒ Object
- #fancyinfo_success(message) ⇒ Object
- #fancyinfo_update(message) ⇒ Object
- #info(message) ⇒ Object
-
#initialize ⇒ Logger
constructor
A new instance of Logger.
Constructor Details
#initialize ⇒ Logger
Returns a new instance of Logger.
8 9 10 |
# File 'lib/jpsclient/utils/logger.rb', line 8 def initialize @verbose = ENV['JPS_DEBUG'] == 'true' end |
Class Method Details
.instance ⇒ Object
4 5 6 |
# File 'lib/jpsclient/utils/logger.rb', line 4 def self.instance @instance ||= new end |
Instance Method Details
#error(message) ⇒ Object
40 41 42 |
# File 'lib/jpsclient/utils/logger.rb', line 40 def error() $stderr.puts "ERROR: #{}" end |
#fancyinfo_complete(message) ⇒ Object
30 31 32 33 34 |
# File 'lib/jpsclient/utils/logger.rb', line 30 def () # 完成时先清除当前行,然后打印完成信息 print "\r" + " " * 100 + "\r" # 清除当前行 puts "✅ #{}" end |
#fancyinfo_error(message) ⇒ Object
20 21 22 |
# File 'lib/jpsclient/utils/logger.rb', line 20 def () puts "❌ #{}" end |
#fancyinfo_start(message) ⇒ Object
12 13 14 |
# File 'lib/jpsclient/utils/logger.rb', line 12 def () puts "▶ #{}" if @verbose || true # 总是显示开始信息 end |
#fancyinfo_success(message) ⇒ Object
16 17 18 |
# File 'lib/jpsclient/utils/logger.rb', line 16 def () puts "✅ #{}" end |
#fancyinfo_update(message) ⇒ Object
24 25 26 27 28 |
# File 'lib/jpsclient/utils/logger.rb', line 24 def () # 进度更新,使用 \r 实现覆盖 print "\r#{}" $stdout.flush end |
#info(message) ⇒ Object
36 37 38 |
# File 'lib/jpsclient/utils/logger.rb', line 36 def info() puts if @verbose end |