PHPackages                             stackify/log4php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Logging &amp; Monitoring](/categories/logging)
4. /
5. stackify/log4php

ActiveLibrary[Logging &amp; Monitoring](/categories/logging)

stackify/log4php
================

Stackify logs and errors for Apache log4php

1.3.0(5y ago)26543Apache-2.0PHP

Since Dec 29Pushed 6mo ago13 watchersCompare

[ Source](https://github.com/stackify/stackify-log-log4php)[ Packagist](https://packagist.org/packages/stackify/log4php)[ Docs](https://github.com/stackify/stackify-log-log4php)[ RSS](/packages/stackify-log4php/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (2)Versions (7)Used By (0)

[![PHP version](https://camo.githubusercontent.com/4bb6614e5c1cea1bfb685b9367c95ef20215bff2dff502e874439f4c9c707a08/68747470733a2f2f62616467652e667572792e696f2f70682f737461636b6966792532466c6f67347068702e737667)](http://badge.fury.io/ph/stackify%2Flog4php)

Stackify log4php Appender
=========================

[](#stackify-log4php-appender)

Apache log4php appender for sending log messages and exceptions to Stackify. Apache log4php &gt;= 2.2.0 is supported.

- **Errors and Logs Overview:**
- **Sign Up for a Trial:**

Installation
------------

[](#installation)

Install the latest version with `composer require stackify/log4php`

### Installation with Linux Agent

[](#installation-with-linux-agent)

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

```

    ...

```

#### Optional Configuration

[](#optional-configuration)

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

```

```

### Installation without Linux Agent

[](#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):

```

    ...

```

#### Optional Configuration

[](#optional-configuration-1)

**Proxy**

- ExecTransport supports data delivery through proxy. Specify proxy using [libcurl format](http://curl.haxx.se/libcurl/c/CURLOPT_PROXY.html): &lt;\[protocol://\]\[user:password@\]proxyhost\[:port\]&gt;

```

```

**Curl path**

- It can be useful to specify `curl` destination path for ExecTransport. This option is set to 'curl' by default.

```

```

Notes
-----

[](#notes)

To get more error details pass Exception objects to the logger if available:

```
try {
    $db->connect();
catch (DbException $ex) {
    $logger->error('DB is not available', $ex);
}
```

All data added to the [MDC](https://logging.apache.org/log4php/apidocs/class-LoggerMDC.html) or [NDC](https://logging.apache.org/log4php/apidocs/class-LoggerNDC.html) will automatically be captured and attached to your log message. This information will be available as JSON data and will be searchable within Stackify.

Troubleshooting
---------------

[](#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](http://php.net/manual/en/errorfunc.configuration.php#ini.error-log). Note that ExecTransport does not produce any errors at all, but you can switch it to debug mode:

```

```

Additional Configuration
------------------------

[](#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](stackify/stackify-api-php#configuration-settings)

### XML Configuration

[](#xml-configuration)

- The string should be a JSON String and HTML Encoded (will improve this eventually.)

```
// Sample PHP Config
$config = array(
    'Debug' => true,
    'DebugLogPath' => '/path/to/log.log'
);
// 1. Converting PHP array to JSON String
// - String: {"Debug":true,"DebugLogPath":"/path/to/log.log"}
$jsonString = json_encode($config);
// 2. XML Encode the JSON String
//   - ' is replaced with &apos;
//   - " is replaced with &quot;
//   - & is replaced with &amp;
//   - < is replaced with &lt;
//   - > is replaced with &gt;
// - Encoded String: {&quot;Debug&quot;:true,&quot;DebugLogPath&quot;:&quot;/path/to/log.log&quot;}
// - Note: In case the string has new line ("\n") or a carriage return ("\r") character, you still need to escape it
//   - \n should be replaced with &#10; or &#xA;
//   - \r should be replaced with &#13; or &#xD;
// - Reference: https://stackoverflow.com/a/29924176/14542233
$xmlEncode = htmlspecialchars($jsonString, ENT_XML1 | ENT_QUOTES, 'UTF-8');

// 3. Add it as a value on XML Configuration

```

### PHP Configuration

[](#php-configuration)

- If using the PHP configuration, basically add the `config` attribute on the `params` under the Stackify Appender settings

```
