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
- 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
- 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
- Add Configuration and send test events
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');
- TOKEN: your customer token from the source setup page
- 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.
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.
Advanced PHP Monolog Options
- PHP Syslog – Send PHP logs using Syslog.
- Laravel logs – A wrapper to Monolog library to send logs to Loggly.
- Loggly Libraries Catalog – The libraries available for sending PHP 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.