2017 © Pedro Peláez
 

library monolog

Stackify logs and errors for Monolog

image

stackify/monolog

Stackify logs and errors for Monolog

  • Wednesday, December 20, 2017
  • by emartin_stackify
  • Repository
  • 7 Watchers
  • 2 Stars
  • 9,462 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 4 Forks
  • 2 Open issues
  • 4 Versions
  • 3 % Grown

The README.md

Stackify Monolog v3 Handler

Monolog handler for sending log messages and exceptions to Stackify. Monolog >= 3.0.0 is supported., (*1)

For Monolog V1, (*2)

Use the 1.x branch, (*3)

For Monolog V2, (*4)

Use the 2.x branch, (*5)

  • Errors and Logs Overview: http://support.stackify.com/errors-and-logs-overview/
  • Sign Up for a Trial: http://www.stackify.com/sign-up/

Installation

Install the latest version with composer require stackify/monolog "~2.0", (*6)

Installation with Linux Agent

This is the suggested installation option, offering the best logging performance., (*7)

PHP:, (*8)

use Monolog\Logger;
use Stackify\Log\Monolog\Handler as StackifyHandler;

$handler = new StackifyHandler('application_name', 'environment_name');
$logger = new Logger('logger');
$logger->pushHandler($handler);

Symfony:, (*9)

services:
    stackify_handler:
        class: "Stackify\\Log\\Monolog\\Handler"
        arguments: ["application_name", "environment_name"]
monolog:
    handlers:
        stackify:
            type: service
            id: stackify_handler

Optional Settings

Log Server Environment Variables - Server environment variables can be added to error log message metadata. Note: This will log all system environment variables; do not enable if sensitive information such as passwords or keys are stored this way., (*10)

```php $handler = new StackifyHandler('application_name', 'environment_name', null, true);, (*11)


### Installation without Linux Agent This option does not require a Stackify Agent to be installed because it sends data directly to Stackify services. It collects log entries in batches, calls curl using the ```exec``` function, and sends data to the background immediately [```exec('curl ... &')```]. This will affect the performance of your application minimally, but it requires permissions to call ```exec``` inside the PHP script and it may cause silent data loss in the event of any network issues. This transport method does not work on Windows. To configure ExecTransport you need to pass the environment name and API key (license key): **PHP:** ```php use Stackify\Log\Transport\ExecTransport; use Stackify\Log\Monolog\Handler as StackifyHandler; $transport = new ExecTransport('api_key'); $handler = new StackifyHandler('application_name', 'environment_name', $transport); $logger = new Logger('logger'); $logger->pushHandler($handler);

Symfony:, (*12)

services:
    stackify_transport:
        class: "Stackify\\Log\\Transport\ExecTransport"
        arguments: ["api_key"]
    stackify_handler:
        class: "Stackify\\Log\\Monolog\\Handler"
        arguments: ["application_name", "environment_name", "@stackify_transport"]
monolog:
    handlers:
        stackify:
            type: service
            id: stackify_handler

Optional Configuration

Proxy - ExecTransport supports data delivery through proxy. Specify proxy using libcurl format: [protocol://][user:password@]proxyhost[:port], (*13)

$transport = new ExecTransport($apiKey, ['proxy' => 'https://55.88.22.11:3128']);

Curl path - It can be useful to specify curl destination path for ExecTransport. This option is set to 'curl' by default., (*14)

$transport = new ExecTransport($apiKey, ['curlPath' => '/usr/bin/curl']);

Log Server Environment Variables - Server environment variables can be added to error log message metadata. Note: This will log all system environment variables; do not enable if sensitive information such as passwords or keys are stored this way., (*15)

```php $handler = new StackifyHandler('application_name', 'environment_name', $transport, true);, (*16)


## Notes To get more error details pass Exception objects to the logger if available: ```php try { $db->connect(); catch (DbException $ex) { // you may use any key name $logger->addError('DB is not available', ['ex' => $ex]); }

Additional Configuration

For additional configurations, you can set on the XML or the PHP File Configuration. Reference for the additional options are located on the stackify logger repository Stackify PHP Logger - Configuration Settings, (*17)

Transport Level

  • This applies to all the transports (ExecTransport, CurlTransport, AgentTransport, AgentSocketTransport) ```php use Monolog\Logger; use Stackify\Log\Monolog\Handler as StackifyHandler;

$config = array( 'CaptureServerVariables' => false, 'CaptureServerVariablesWhitelist' => '*', 'CaptureServerVariablesBlacklist' => 'REMOTE_ADDR,SERVER_ADDR', ... );, (*18)

$transport = new ExecTransport($apiKey, [ 'config' => $config ]);, (*19)

$handler = new StackifyHandler('application_name', 'environment_name', $transport); $logger = new Logger('logger'); $logger->pushHandler($handler);, (*20)

### Handler Level
- This applies to the current Monolog Handler

 ```php
use Monolog\Logger;
use Stackify\Log\Monolog\Handler as StackifyHandler;

$transport = new ExecTransport($apiKey); // Your selected transport (Can be null which defaults to AgentSocketTransport)
$logServerVariables = false; // Default
$config = array(
        'CaptureServerVariables' => false,
        'CaptureServerVariablesWhitelist' => '*',
        'CaptureServerVariablesBlacklist' => 'REMOTE_ADDR,SERVER_ADDR',
        ...
);

$handler = new StackifyHandler('application_name', 'environment_name', $transport, $logServerVariables, $config);
$logger = new Logger('logger');
$logger->pushHandler($handler);

Handler Level Option

  • Include Channel, (*21)

    • This will include the logger name or the channel set for the log entry.

    ```php use Monolog\Logger; use Stackify\Log\Monolog\Handler as StackifyHandler;, (*22)

$transport = new ExecTransport($apiKey); // Your selected transport (Can be null which defaults to AgentSocketTransport) $logServerVariables = false; // Default $config = array( 'IncludeChannel' => true, ... );, (*23)

$handler = new StackifyHandler('application_name', 'environment_name', $transport, $logServerVariables, $config); $logger = new Logger('logger'); $logger->pushHandler($handler);, (*24)


- **Include Extra In Context** - This will include the extra property to the context (merging extra to context) ```php use Monolog\Logger; use Stackify\Log\Monolog\Handler as StackifyHandler; $transport = new ExecTransport($apiKey); // Your selected transport (Can be null which defaults to AgentSocketTransport) $logServerVariables = false; // Default $config = array( 'IncludeExtraInContext' => true, ... ); $handler = new StackifyHandler('application_name', 'environment_name', $transport, $logServerVariables, $config); $logger = new Logger('logger'); $logger->pushProcessor(function ($record) { if (empty($record['extra'])) { $record['extra'] = []; } $record['extra']['dummy'] = 1; return $record; }); $logger->pushHandler($handler);

Symfony

services:
    stackify_transport:
        class: "Stackify\\Log\\Transport\\CurlTransport"
        arguments: ["api_key"]
# Square/Curly Brackets
    stackify_handler:
        class: "Stackify\\Log\\Monolog\\Handler"
        arguments: ["application_name", "environment_name", "@stackify_transport", false, { CaptureServerVariables: false, ... }]
# or
# Dash/Colon Space
    stackify_handler:
        class: "Stackify\\Log\\Monolog\\Handler"
        arguments:
            - "application_name"
            - "environment_name"
            - "@stackify_transport"
            - false
            - CaptureServerVariables: false
              CaptureServerWhitelist: "*"
              CaptureServerBlacklist: null

monolog:
    handlers:
        stackify:
            type: service
            id: stackify_handler

Troubleshooting

If transport does not work, try looking into vendor\stackify\logger\src\Stackify\debug\log.log file (if it is available for writing). Errors are also written to global PHP error_log. Note that ExecTransport does not produce any errors at all, but you can switch it to debug mode:, (*25)

$transport = new ExecTransport($apiKey, ['debug' => true]);

You can set it also on the Logger level. Setting the Debug and DebugLogPath, (*26)

$config = array(
        'DebugLogPath' => '/path/to/log.log',
        'Debug' => true
    );

$logger = new StackifyHandler('application_name', 'environment_name', $transport, $logServerVariables, $config);

License

Copyright 2019 Stackify, LLC., (*27)

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at, (*28)

http://www.apache.org/licenses/LICENSE-2.0, (*29)

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License., (*30)

The Versions

20/12 2017

dev-master

9999999-dev https://github.com/stackify/stackify-log-monolog

Stackify logs and errors for Monolog

  Sources   Download

Apache-2.0

The Requires

 

log psr-3 logging monolog log4php stackify

20/12 2017

1.x-dev

1.9999999.9999999.9999999-dev https://github.com/stackify/stackify-log-monolog

Stackify logs and errors for Monolog

  Sources   Download

Apache-2.0

The Requires

 

log psr-3 logging monolog log4php stackify

20/12 2017

2.x-dev

2.9999999.9999999.9999999-dev https://github.com/stackify/stackify-log-monolog

Stackify logs and errors for Monolog

  Sources   Download

Apache-2.0

The Requires

 

log psr-3 logging monolog log4php stackify

29/12 2014

1.0.0

1.0.0.0 https://github.com/stackify/stackify-log-monolog

Stackify logs and errors for Monolog

  Sources   Download

Apache-2.0

The Requires

 

log psr-3 logging monolog log4php stackify