The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Log::Dispatch::TextTable - log events to a textual table

VERSION

version 0.033

SYNOPSIS

  use Log::Dispatch;
  use Log::Dispatch::TextTable;
 
  my $log = Log::Dispatch->new;
 
  $log->add(Log::Dispatch::TextTable->new(
    name      => 'text_table',
    min_level => 'debug',
    flush_if  => sub { (shift)->event_count >= 60 },
  ));
 
  while (@events) {
    # every 60 events, a formatted table is printed to the screen
    $log->warn($_);
  }

DESCRIPTION

This provides a Log::Dispatch log output system that builds logged events into a textual table and, when done, does something with the table. By default, it will print the table.

PERL VERSION

This library should run on perls released even a long time ago. It should work on any version of perl released in the last five years.

Although it may work on older versions of perl, no guarantee is made that the minimum required version will not be increased. The version may be increased for any reason, and there is no promise that patches will be accepted to lower the minimum required perl.

METHODS

new

 my $table_log = Log::Dispatch::TextTable->new(\%arg);

This method constructs a new Log::Dispatch::TextTable output object. Valid arguments are:

  send_to  - a coderef indicating where to send the logging table (optional)
             defaults to print to stdout; see transmit method
  flush_if - a coderef indicating whether, if ever, to flush (optional)
             defaults to never flush; see should_flush and flush methods
  columns  - an arrayref of columns to include in the table; message, level,
             and time are always provided

log_message

This is the method which performs the actual logging, as detailed by Log::Dispatch::Output. It adds the data to the table and may flush. (See "should_flush".)

table

This method returns the Text::Table object being used for the log's logging.

entry_count

This method returns the current number of entries in the table.

flush

This method transmits the current table and then clears it. This is useful for emptying large tables every now and then.

should_flush

This method returns true if the logger is ready to flush its contents. This is always false, unless a flush_if callback was provided during instantiation.

The callback is passed the Log::Dispatch::TextTable object and a reference to the last entry logged.

transmit

This method sends out the table's current contents to their destination via the callback provided via the send_to argument to new.

TODO

I'd like to make it possible to transmit just the rows since the last transmit without flushing, but Text::Table needs a bit of a patch for that.

AUTHOR

Ricardo SIGNES <cpan@semiotic.systems>

CONTRIBUTORS

  • Ricardo SIGNES <rjbs@codesimply.com>

  • Ricardo Signes <rjbs@semiotic.systems>

COPYRIGHT AND LICENSE

This software is copyright (c) 2022 by Ricardo SIGNES.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.