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)


379
380
381
382
383
384
385
# File 'lib/log_struct/integrations/puma.rb', line 379

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)


402
403
404
405
# File 'lib/log_struct/integrations/puma.rb', line 402

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

#log(msg) ⇒ T.untyped

Parameters:

  • msg (String)

Returns:

  • (T.untyped)


364
365
366
367
# File 'lib/log_struct/integrations/puma.rb', line 364

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

#puts(msg) ⇒ T.untyped

Parameters:

  • msg (String)

Returns:

  • (T.untyped)


388
389
390
391
392
393
394
395
396
397
398
399
# File 'lib/log_struct/integrations/puma.rb', line 388

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 = ::Kernel.instance_variable_get(:@stdout)
    return io.puts(msg)
  end
  super
end

#write(msg) ⇒ T.untyped

Parameters:

  • msg (String)

Returns:

  • (T.untyped)


370
371
372
373
374
375
376
# File 'lib/log_struct/integrations/puma.rb', line 370

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