---
title: "Monolog v2"
slug: "monolog-v2"
description: "Set up Stackify's Monolog v2 appender to track logs & errors. Install Stackify Linux Agent or use direct method without agent installation."
updated: 2019-11-05T21:14:08Z
published: 2019-11-05T21:14:08Z
---

> ## Documentation Index
> Fetch the complete documentation index at: https://docs.stackify.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Monolog v2

Guide on setting up Stackify's **monolog v2** appender to track application logs and errors.

## Installation with Linux Agent

This is the suggested installation option, offering the best logging performance.

### Install **Stackify Linux Agent**

- [Standard](/docs/linux-installation)
- [Docker](/docs/retrace-docker-install)
- [Kubernetes](/docs/retrace-kubernetes-install)

### Install **stackify/monolog** module into your project:

```
composer require stackify/monolog "~2.0"
```

### Configure **stackify/monolog** module

Replace **Application Name** and **Environment Name** with appropriate values.

**PHP:**

```
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:**

```
services:
    stackify_handler:
        class: "Stackify\\Log\\Monolog\\Handler"
        arguments: ["Application Name", "Environment Name"]
monolog:
    handlers:
        stackify:
            type: service
            id: stackify_handler
```

#### Optional Settings

**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.

```
$handler = new StackifyHandler('Application Name', 'Environment Name', null, true);
```

## Installation without Linux Agent

This option does not require a **Stackify Linux 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 ... &amp;')]`. 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.

### Install **stackify/monolog** module into your project:

```
composer require stackify/monolog "~2.0"
```

### Configure **stackify/monolog** module

Replace **Stackify API Key**, **Application Name** and **Environment Name** with appropriate values.

**PHP:**

```
use Stackify\Log\Transport\ExecTransport;
use Stackify\Log\Monolog\Handler as StackifyHandler;

$transport = new ExecTransport('Stackify API Key');
$handler = new StackifyHandler('Application Name', 'Environment Name', $transport);
$logger = new Logger('logger');
$logger->pushHandler($handler);
```

**Symfony:**

```
services:
    stackify_transport:
        class: "Stackify\\Log\\Transport\ExecTransport"
        arguments: ["Stackify 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 Settings

**Proxy:** ExecTransport supports data delivery through proxy. Specify proxy using libcurl format: `&lt;[protocol://][user:password@]proxyhost[:port]&gt;`:

```
$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.

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

**Server environment variables** can be added to error log message metadata.

 This will log all system environment variables; do not enable if sensitive information such as passwords or keys are stored this way.

                         

```
$handler = new StackifyHandler('Application Name', 'Environment Name', $transport, true);
```
