Module: LogStruct::Integrations::Puma::LogWriterPatch

Extended by:
T::Sig
Defined in:
lib/log_struct/integrations/puma.rb

Overview

Patch Puma::LogWriter to intercept log writes

Instance Method Summary collapse

Instance Method Details

#<<(msg) ⇒ T.untyped

Parameters:

  • msg (String)

Returns:

  • (T.untyped)


353
354
355
356
357
358
359
# File 'lib/log_struct/integrations/puma.rb', line 353

def <<(msg)
  any_consumed = T.let(false, T::Boolean)
  msg.to_s.each_line do |l|
    any_consumed = true if ::LogStruct::Integrations::Puma.process_line(l)
  end
  super unless any_consumed
end

#info(msg) ⇒ T.untyped

Parameters:

  • msg (String)

Returns:

  • (T.untyped)


376
377
378
379
# File 'lib/log_struct/integrations/puma.rb', line 376

def info(msg)
  consumed = ::LogStruct::Integrations::Puma.process_line(msg)
  super unless consumed
end

#log(msg) ⇒ T.untyped

Parameters:

  • msg (String)

Returns:

  • (T.untyped)


338
339
340
341
# File 'lib/log_struct/integrations/puma.rb', line 338

def log(msg)
  consumed = ::LogStruct::Integrations::Puma.process_line(msg)
  super unless consumed
end

#puts(msg) ⇒ T.untyped

Parameters:

  • msg (String)

Returns:

  • (T.untyped)


362
363
364
365
366
367
368
369
370
371
372
373
# File 'lib/log_struct/integrations/puma.rb', line 362

def puts(msg)
  consumed = ::LogStruct::Integrations::Puma.process_line(msg)
  if consumed
    # attempt to suppress; only forward if not consumed
    return nil
  end
  if ::Kernel.instance_variables.include?(:@stdout)
    io = T.unsafe(::Kernel.instance_variable_get(:@stdout))
    return io.puts(msg)
  end
  super
end

#write(msg) ⇒ T.untyped

Parameters:

  • msg (String)

Returns:

  • (T.untyped)


344
345
346
347
348
349
350
# File 'lib/log_struct/integrations/puma.rb', line 344

def write(msg)
  any_consumed = T.let(false, T::Boolean)
  msg.to_s.each_line do |l|
    any_consumed = true if ::LogStruct::Integrations::Puma.process_line(l)
  end
  super unless any_consumed
end