Log4PHP
  • 1 Minute to read
  • Dark
    Light
  • PDF

Log4PHP

  • Dark
    Light
  • PDF

Article summary

Guide on setting up Stackify's log4php 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

Install stackify/log4php module into your project:

composer require stackify/log4php

Configure stackify/log4php module

Replace Application Name and Environment Name with appropriate values.

<root>
    <appender_ref ref="stackifyAppender" />
</root>

<appender name="stackifyAppender" class="\Stackify\Log\Log4php\Appender">
    <param name="appName" value="Application Name" />
    <param name="environmentName" value="Environment Name" />
</appender>

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.

<param name="logServerVariables" value="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 ... &')]. 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/log4php module into your project:

composer require stackify/log4php

Configure stackify/log4php module

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

<root>
    <appender_ref ref="stackifyAppender" />
</root>

<appender name="stackifyAppender" class="\Stackify\Log\Log4php\Appender">
    <param name="appName" value="Application Name" />
    <param name="environmentName" value="Environment Name" />
    <param name="mode" value="exec" />
    <param name="apiKey" value="Stackify API Key" />
</appender>

Optional Settings

Proxy:
ExecTransport supports data delivery through proxy. Specify proxy using libcurl format: <[protocol://][user:password@]proxyhost[:port]>:

<param name="proxy" value="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.

<param name="curlPath" value="/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.
<param name="logServerVariables" value="true" />

Was this article helpful?