PHP Monolog

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
  2. Go to your project directory and install latest version of the library using following command

    sudo php composer.phar require monolog/monolog
    

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

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

  5. Add Configuration and send test events
  6. Add configuration to the source file and send some test events

    require_once __DIR__ . '/vendor/autoload.php';
    use Monolog\Logger;
    use Monolog\Handler\LogglyHandler;
    use Monolog\Formatter\LogglyFormatter;
    
    $log = new Logger('appName');
    $log->pushHandler(new LogglyHandler('TOKEN/tag/monolog', Logger::INFO));
    
    $log->addWarning('test logs to loggly');
    

    Replace:

  7. Verify Events
  8. 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

    Advanced PHP Monolog Options

    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.
    Thanks for the feedback! We'll use it to improve our support documentation.


Top