Skip to content

Instantly share code, notes, and snippets.

@kyletaylored
Last active April 19, 2023 14:53
Show Gist options
  • Save kyletaylored/c133cf719bf64edc0075bb0d7133688e to your computer and use it in GitHub Desktop.
Save kyletaylored/c133cf719bf64edc0075bb0d7133688e to your computer and use it in GitHub Desktop.
How to integrate Monolog with New Relic in Drupal 9
{
"require": {
"drupal/monolog": "^2.2",
"newrelic/monolog-enricher": "^2.0"
}
}
parameters:
monolog.channel_handlers:
default:
handlers:
- name: "new_relic_buffered"
processors:
- "drupal_message_placeholder"
- "new_relic_processor"
- name: "new_relic_error"
services:
monolog.processor.new_relic_processor:
class: NewRelic\Monolog\Enricher\Processor
# Log API New Relic Processor
# Has build in buffering for New Relic requests.
monolog.handler.new_relic_log:
class: NewRelic\Monolog\Enricher\Handler
arguments: ["200", false]
# Log API New Relic Handler (buffered)
# Buffered handler waits for all messages before batch sending.
monolog.handler.new_relic_buffered:
class: Monolog\Handler\BufferHandler
arguments: ["@monolog.handler.new_relic_log"]
# Error Event New Relic Handler
# Uses newrelic_notice_error to send logs to the Triage Errors inbox.
monolog.handler.new_relic_error:
class: Monolog\Handler\NewRelicHandler
arguments: ["300", false]
# Rotating file
# Store logs in Pantheon's default log directory.
monolog.handler.rotating_file:
class: Monolog\Handler\RotatingFileHandler
arguments: ["/logs/php/application.log", "15", "200", false]
<?php
// Pantheon specific settings.
if (!empty($_ENV['PANTHEON_ENVIRONMENT'])) {
// Load monolog config.
$monolog_services = __DIR__ . '/monolog.services.yml';
if (file_exists($monolog_services)) {
$settings['container_yamls'][] = $monolog_services;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment