Class: Aspera::Log
Overview
Singleton object for logging
Constant Summary collapse
- LOG_TYPES =
where logs are sent to
%i[stderr stdout syslog].freeze
- @@format =
rubocop:disable Style/ClassVars
:json
Instance Attribute Summary collapse
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#logger_type ⇒ Object
Returns the value of attribute logger_type.
-
#program_name ⇒ Object
writeonly
Sets the attribute program_name.
Class Method Summary collapse
-
.capture_stderr ⇒ Object
Capture the output of $stderr and log it at debug level.
-
.dump(name, object) ⇒ Object
dump object suitable for Log.log.debug.
-
.levels ⇒ Object
levels are :debug,:info,:warn,:error,fatal,:unknown.
-
.log ⇒ Object
get the logger object of singleton.
Instance Method Summary collapse
-
#level ⇒ Object
get symbol of debug level of underlying logger.
-
#level=(new_level) ⇒ Object
set log level of underlying logger given symbol level.
Instance Attribute Details
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
93 94 95 |
# File 'lib/aspera/log.rb', line 93 def logger @logger end |
#logger_type ⇒ Object
Returns the value of attribute logger_type.
93 94 95 |
# File 'lib/aspera/log.rb', line 93 def logger_type @logger_type end |
#program_name=(value) ⇒ Object (writeonly)
Sets the attribute program_name
94 95 96 |
# File 'lib/aspera/log.rb', line 94 def program_name=(value) @program_name = value end |
Class Method Details
.capture_stderr ⇒ Object
Capture the output of $stderr and log it at debug level
83 84 85 86 87 88 89 90 |
# File 'lib/aspera/log.rb', line 83 def capture_stderr real_stderr = $stderr $stderr = StringIO.new yield log.debug($stderr.string) ensure $stderr = real_stderr end |
.dump(name, object) ⇒ Object
dump object suitable for Log.log.debug
69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/aspera/log.rb', line 69 def dump(name, object) result = case @@format when :json JSON.pretty_generate(object) rescue PP.pp(object, +'') when :ruby PP.pp(object, +'') else raise 'wrong parameter, expect ruby or json' end "#{name.to_s.green} (#{@@format})=\n#{result}" end |
.levels ⇒ Object
levels are :debug,:info,:warn,:error,fatal,:unknown
61 |
# File 'lib/aspera/log.rb', line 61 def levels; Logger::Severity.constants.sort{|a, b|Logger::Severity.const_get(a) <=> Logger::Severity.const_get(b)}.map{|c|c.downcase.to_sym}; end |
.log ⇒ Object
get the logger object of singleton
64 |
# File 'lib/aspera/log.rb', line 64 def log; instance.logger; end |
Instance Method Details
#level ⇒ Object
get symbol of debug level of underlying logger
102 103 104 105 106 107 |
# File 'lib/aspera/log.rb', line 102 def level Logger::Severity.constants.each do |name| return name.downcase.to_sym if @logger.level.eql?(Logger::Severity.const_get(name)) end Aspera.error_unexpected_value(@logger.level){'log level'} end |