Class: Mamiya::Logger
- Inherits:
-
Object
- Object
- Mamiya::Logger
- Extended by:
- Forwardable
- Includes:
- Logger::Severity
- Defined in:
- lib/mamiya/logger.rb
Defined Under Namespace
Classes: LogDev
Instance Attribute Summary collapse
-
#color ⇒ Object
Returns the value of attribute color.
Class Method Summary collapse
Instance Method Summary collapse
- #[](progname) ⇒ Object
- #add_output(*outputs) ⇒ Object
- #dup ⇒ Object
-
#initialize(color: , outputs: , level: ) ⇒ Logger
constructor
A new instance of Logger.
- #orig_dup ⇒ Object
- #remove_output(*outputs) ⇒ Object
- #with_additional_file(*outputs) ⇒ Object
- #with_clean_progname ⇒ Object
Constructor Details
#initialize(color: , outputs: , level: ) ⇒ Logger
22 23 24 25 26 27 28 29 |
# File 'lib/mamiya/logger.rb', line 22 def initialize(color: self.class.defaults[:color], outputs: self.class.defaults[:outputs], level: self.class.defaults[:level]) @logdev = LogDev.new(outputs) @logger = ::Logger.new(@logdev) @logger.level = level @logger.formatter = method(:format) @color = color.nil? ? @logdev.tty? : color end |
Instance Attribute Details
#color ⇒ Object
Returns the value of attribute color.
31 32 33 |
# File 'lib/mamiya/logger.rb', line 31 def color @color end |
Class Method Details
.defaults ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/mamiya/logger.rb', line 12 def self.defaults return @defaults if @defaults if ENV["MAMIYA_LOG_LEVEL"] level = ::Logger::Severity.const_get(ENV["MAMIYA_LOG_LEVEL"].upcase) rescue INFO else level = INFO end @defaults = {color: nil, outputs: [STDOUT], level: level} end |
Instance Method Details
#[](progname) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/mamiya/logger.rb', line 74 def [](progname) self.dup.tap do |new_logger| new_logger.instance_eval do if @logger.progname && !@logger.progname.empty? @logger.progname = "#{@logger.progname}/#{progname}" else @logger.progname = progname end end end end |
#add_output(*outputs) ⇒ Object
41 42 43 |
# File 'lib/mamiya/logger.rb', line 41 def add_output(*outputs) @logdev.add(*outputs) end |
#dup ⇒ Object
60 61 62 63 64 65 66 |
# File 'lib/mamiya/logger.rb', line 60 def dup self.orig_dup.tap do |new_logger| new_logger.instance_eval do @logger = @logger.dup end end end |
#orig_dup ⇒ Object
58 |
# File 'lib/mamiya/logger.rb', line 58 alias orig_dup dup |
#remove_output(*outputs) ⇒ Object
45 46 47 |
# File 'lib/mamiya/logger.rb', line 45 def remove_output(*outputs) @logdev.remove(*outputs) end |
#with_additional_file(*outputs) ⇒ Object
49 50 51 52 53 54 55 56 |
# File 'lib/mamiya/logger.rb', line 49 def with_additional_file(*outputs) @logdev.add_output(*outputs) yield ensure @logdev.remove_output(*outputs) end |
#with_clean_progname ⇒ Object
68 69 70 71 72 |
# File 'lib/mamiya/logger.rb', line 68 def with_clean_progname self.dup.tap do |new| new.progname = nil end end |