Latest release: v0.2.2

Logging

Content

Tracy

First of all, we need to register our universal tuned logger for the future purpose.

extensions:
    logging: Contributte\Logging\DI\TracyLoggingExtension
1
2

After that, we need to setup logDir.

logging:
    logDir: %appDir%/../log
1
2

Basically, it overrides Tracy's default logger by our universal, pluggable logger.

Default loggers

There are 2 types of loggers defined by default.

  • ExceptionFileLogger - creates exception.log file
  • BlueScreenFileLogger - creates exception-*.html
  • SendMailLogger - sends exception to email

You can redefine these loggers in logging.loggers.

logging:
    loggers: 
        - Contributte\Logging\ExceptionFileLogger(%logDir%)
        - Contributte\Logging\BlueScreenFileLogger(%logDir%)
        - Contributte\Logging\SendMailLogger(
            Contributte\Logging\Mailer\TracyMailer(
                from@email,
                [to@email, to2@email]
            ),
            %logDir%
        )
        - App\Model\MyCustomerLogger
1
2
3
4
5
6
7
8
9
10
11
12

Custom logger

To create your custom logger you have to implement Contributte\Logging\ILogger.

<?php

namespace App\Model;

use Contributte\Logging\ILogger;

class MyDatabaseLogger implements ILogger
{

    /**
     * @param mixed $message
     * @param string $priority
     * @return void
     */
    public function log($message, $priority = self::INFO)
    {
        // store exception to database...
    }

}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

And register it in neon.

logging:
    loggers: 
        - App\Model\MyDatabaseLogger(@connection)
1
2
3

Slack

extensions:
    logging: Contributte\Logging\DI\TracyLoggingExtension
    slack: Contributte\Logging\DI\SlackLoggingExtension
1
2
3

There is a configuration you have to fill in.

Key Requirements Default
url required -
channel required -
username optional Tracy
icon_emoji optional 🚀
icon_url optional -
slack:
    url: https://hooks.slack.com/services/<code1>/<code2>/<code3>
    channel: tracy
1
2
3

Formatters

By default, there are 5 formatters for your slack-channel-pleasure.

You can disable it like this:

slack:
    formatters: []
1
2

And configure your own formatters. They will be loaded automatically, if you implement needed interface (Contributte\Logging\Slack\Formatter\IFormatter).

services:
    - App\Slack\MySuperTrouperFormatter
1
2

Contributte\Logging\Slack\Formatter\ContextFormatter

  • Setup context with all configured data (channel, icon, etc).

Contributte\Logging\Slack\Formatter\ColorFormatter

  • danger -> ILogger::CRITICAL
  • #ff0000 -> ILogger::EXCEPTION
  • warning -> ILogger::ERROR

Contributte\Logging\Slack\Formatter\ExceptionFormatter

ContextFormatter

Contributte\Logging\Slack\Formatter\ExceptionPreviousExceptionsFormatter

ContextFormatter

Contributte\Logging\Slack\Formatter\ExceptionStackTraceFormatter

ContextFormatter

Sentry

extensions:
    logging: Contributte\Logging\DI\TracyLoggingExtension
    sentry: Contributte\Logging\DI\SentryLoggingExtension
1
2
3

This extension requires to have sentry installed.

composer require sentry/sentry
1

Now you should register new company/profile at Sentry's page (https://sentry.io/organizations/new/). There you obtained key, secret and project ID. Put these variables into neon file.

sentry:
    url: https://<key>:<secret>@sentry.io/<project>
1
2