Rand Stats

The uploading author of cpan:RBT does not match the META author of github:rbt.

LogP6::Writer::StackDriver

cpan:RBT

NAME

LogP6::Writer::StackDriver - writer implementation for local stackdriver logging

SYNOPSIS

Useful for logging within the Google Cloud environment where fluentd will pickup logs and feed them into StackDriver.

Use of this module ensures your messages are treated as single entries (no multi-line issues) and enables use of triggers/calculations on special fields via MDC.

CONFIGURATION

You can configure the writer from code by instantiating object of LogP6::WriterConf::StackDriver class. It takes the following parameters:

EXAMPLE

use LogP6 :configure;   # use library in configure mode
use LogP6::WriterConf::StackDriver;
use Cro::HTTP::Router;

my $sd = LogP6::WriterConf::StackDriver.new(
  :handle($*ERR), # Change to use STDERR
  :name<audit>

  use-source-location => False,  # Disable source location

  mdc-key-cro-request => 'webapp-request',
);

cliche(
  :name<cl>,
  :matcher<audit>,
  grooves => ( writer($sd), filter(:level($debug)) ) # Debug level to $sd
);

my $app = route {
  get -> 'healthz' {

    # Note, only that instance of $log will have the MDC information. Consider creating
    # a context object for the request and passing it along the work pipeline.
    my $log = get-logger('audit');
    $log.mdc-put('webapp-request', request());
    $log.debug('Request for healthz');

    content 'text/plain', 'READY';
  }
}

$!cro-service = Cro::HTTP::Server.new(:host<0.0.0.0>, :port<10000>, :$app);
$!cro-service.start;

AUTHOR

Rod Taylor rbt@cpan.org

Source can be located at: github. Comments and Pull Requests are welcome.

COPYRIGHT AND LICENSE

Copyright 2020 Rod Taylor

This library is free software; you can redistribute it and/or modify it under the Artistic License 2.0.