View on GitHub

Log4php-slack-appender

A log4php appender build as wrapper for "maknz/slack" package

Download this project as a .zip file Download this project as a tar.gz file

Slack as appender for log4php

Status

Dependency Status Latest Stable Version Total Downloads Latest Unstable Version License

Monthly Downloads Daily Downloads

Master Branch

Build Status StyleCI Coverage Status

Develop Branch

Build Status StyleCI Coverage Status

Description

This package allows you to use Slack for PHP easily and elegantly in your app as an log4php appender. Read the instructions below to get it set up.

Requirements

PHP >= 5.2 || ^7.0

Installation

You can install the package using the Composer package manager. You can install it by running this command in your project root:

composer require fahl-design/log4php-slack-appender

Then create an incoming webhook for each Slack team you'd like to send messages to. You'll need the webhook URL(s) in order to configure this package.

After you got your hook url add it as endpoint to your configuration

XML appender config example

    <log4php:configuration xmlns:log4php="http://logging.apache.org/log4php/" threshold="all">
        <appender name="default" class="LoggerAppenderSlack">
            <!-- get endpoint url from https://my.slack.com/services/new/incoming-webhook -->
            <param name="endpoint" value="https://hooks.slack.com/services/XXXXXXXXXXXXXXX/XXXXXXXXXXXXXXX/XXXXXXXXXXXXXXX" />
            <param name="channel" value="#yourChannel" />
            <param name="username" value="Log4php" />
            <param name="icon" value=":ghost:" />
        </appender>
        <logger name="myLogger">
            <appender_ref ref="default" />
        </logger>
        <root>
            <level value="DEBUG" />
        </root>
    </log4php:configuration>

php (config.php) appender config example

    <?php 
    return [
        'rootLogger' => [
            'appenders' => ['default'],
        ],
        'myLogger' => [
            'appenders' => ['default'],
        ],
        'appenders' => [
            'default' => [
                'class' => 'LoggerAppenderSlack',
                'params' => [
                    'endpoint' => 'https://hooks.slack.com/services/XXXXXXXXXXXXXXX/XXXXXXXXXXXXXXX/XXXXXXXXXXXXXXX',
                    'channel' => '#yourChannel',
                    'username' => 'log4php',
                    'icon' => ':ghost:', // emoji or an icon url
                ]
            ]
        ]
    ];

Usage

Check example (src/examples)

Logger::configure(__DIR__.'/../resources/appender_slack.xml');

$logger = Logger::getLogger('myLogger');
$logger->debug('Hello World!');

ToDo