bloom-ux/wpdb-monolog

Integrate monolog logging with $wpdb using wonolog

Installs: 13

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 4

Forks: 0

Open Issues: 0

Type:wordpress-muplugin

dev-main 2024-03-01 01:12 UTC

This package is auto-updated.

Last update: 2024-03-30 01:19:20 UTC


README

Use monolog with WordPress and log errors to your database.

Installation

Install using composer: composer require bloom-ux/wpdb-monolog:dev-main.

It will install as a mu-plugin.

If you're using composer's autoloader, you're done.

Components

  • \bloom\WPDB_Monolog\WPDB_Handler → monolog handler that writes logs to your WordPress database.
  • \bloom\WPDB_Monolog\WP_Processor → monolog processor that adds "extra" data to a monolog record.

Usage

Basic

There are some helper functions to ease the integration:

<?php
use function bloom\WPDB_Monolog\get_logger_for_channel;
use function bloom\WPDB_Monolog\set_channel_level;

$logger = get_logger_for_channel( 'MyCustomChannel' );
set_channel_level( $logger, 'production' === wp_get_environment_type() ? 400 : 100 );
$logger->info("Lorem ipsum dolor sit amet", array( 'foo' => 'bar' ) );

Custom

You can integrate the handler and/or processor as you see fit with your monolog integration.