Documentation forLoggly

PHP Monolog

Loggly provides the infrastructure to aggregate and normalize log events so they are available to explore interactively, build visualizations, or create threshold-based alerting. In general, any method to send logs from a system or application to an external source can be adapted to send logs to Loggly. The following instructions provide one scenario for sending logs to Loggly.

You can send PHP logs to Loggly using the Monolog library. We will automatically parse the JSON format allowing you to quickly drill down into issues. You can see the Loggly Monolog PHP error handler library code on GitHub or the Packagist repository.

PHP Monolog Setup

1. Install Monolog library

Go to your project directory and install latest version of the library using following command

sudo php composer.phar require monolog/monolog 

2. Install PHP Curl

Install PHP Curl library, if it is not already installed using following command.

sudo apt-get install curl libcurl3 libcurl3-dev php5-curl 

3. Add Configuration and send test events

Add configuration to the source file and send some test events

require_once __DIR__ . '/vendor/autoload.php';
use MonologLogger;
use MonologHandlerLogglyHandler;
use MonologFormatterLogglyFormatter;

$log = new Logger('appName');
$log->pushHandler(new LogglyHandler('TOKEN/tag/monolog', Logger::INFO));

$log->warning('test logs to loggly');

Replace:

4. Verify Events

Search Loggly for events with the monolog as tag over the past 20 minutes. It may take a few minutes to index the event. If it doesn’t work, see the troubleshooting section below.

tag:monolog 

Click on one of the logs to show a list of JSON fields (see screenshot below). If you don’t see them, please check that you are using one of our automatically parsed formats.
PHP Monolog Example

Advanced PHP Monolog Options

  • PHP Syslog – Send PHP logs using Syslog.
  • Laravel logs – A wrapper to Monolog library to send logs to Loggly.

Troubleshooting PHP Monolog

  • Wait a few minutes in case indexing needs to catch up
  • Verify if the Customer token is correct in the configuration
  • See our HTTP Troubleshooting Guide to verify HTTP events are being sent to Loggly.
  • Search or post your own PHP Monolog questions, or questions on sending log records or log messages in the community forum.

The scripts are not supported under any SolarWinds support program or service. The scripts are provided AS IS without warranty of any kind. SolarWinds further disclaims all warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The risk arising out of the use or performance of the scripts and documentation stays with you. In no event shall SolarWinds or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the scripts or documentation.