Class: ASpaceLogger
- Inherits:
-
Logger
- Object
- Logger
- ASpaceLogger
- Defined in:
- common/aspace_logger.rb
Instance Method Summary collapse
-
#add(severity, message = nil, progname = nil, &block) ⇒ Object
-
#add_to_backlog(formatted_messsage) ⇒ Object
-
#backlog ⇒ Object
-
#backlog_and_flush ⇒ Object
-
#flush_backlog ⇒ Object
-
#initialize(logdev) ⇒ ASpaceLogger
constructor
A new instance of ASpaceLogger.
-
#start_recording ⇒ Object
-
#stop_recording ⇒ Object
Constructor Details
#initialize(logdev) ⇒ ASpaceLogger
Returns a new instance of ASpaceLogger.
6 7 8 9 10 |
# File 'common/aspace_logger.rb', line 6 def initialize(logdev) @backlog = Atomic.new([]) @recording = Atomic.new(false) super(logdev) end |
Instance Method Details
#add(severity, message = nil, progname = nil, &block) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'common/aspace_logger.rb', line 12 def add(severity, = nil, progname = nil, &block) if @recording.value == true if ! if block = block.call else # O_o # # https://ruby-doc.org/stdlib-2.1.0/libdoc/logger/rdoc/Logger.html#method-i-add # "Program name string. Can be omitted. Treated as a message if no message and block are given." = progname progname = nil end end add_to_backlog((format_severity(severity), Time.now, progname, )) end super(severity, , progname, &block) end |
#add_to_backlog(formatted_messsage) ⇒ Object
34 35 36 37 38 39 40 41 |
# File 'common/aspace_logger.rb', line 34 def add_to_backlog( formatted_messsage ) if @backlog.value.length > 100 flush_backlog stop_recording else @backlog.update { |bl| bl << formatted_messsage } end end |
#backlog ⇒ Object
43 44 45 |
# File 'common/aspace_logger.rb', line 43 def backlog @backlog.value.join("") end |
#backlog_and_flush ⇒ Object
61 62 63 64 65 66 |
# File 'common/aspace_logger.rb', line 61 def backlog_and_flush backlog_cache = backlog flush_backlog start_recording backlog_cache end |
#flush_backlog ⇒ Object
47 48 49 |
# File 'common/aspace_logger.rb', line 47 def flush_backlog @backlog.update { |bl| bl = [] } end |
#start_recording ⇒ Object
51 52 53 54 |
# File 'common/aspace_logger.rb', line 51 def start_recording return if @recording.value == true @recording.update { |r| r = true } end |
#stop_recording ⇒ Object
56 57 58 59 |
# File 'common/aspace_logger.rb', line 56 def stop_recording return unless @recording.value == true @recording.update { |r| r = false } end |