PHP code example of phalcon / incubator-logger

1. Go to this page and download the library: Download phalcon/incubator-logger library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

phalcon / incubator-logger example snippets


use Aws\CloudWatchLogs\CloudWatchLogsClient;
use Phalcon\Incubator\Logger\Adapter\CloudWatch;
use Phalcon\Logger\Logger;

$di->set(
    'logger',
    function () {
        $client = new CloudWatchLogsClient([
            'credentials' => [
                'key' => 'AMAZON_CLOUDWATCH_KEY',
                'secret' => 'AMAZON_CLOUDWATCH_SECRET',
            ],
            'region' => 'AMAZON_CLOUDWATCH_REGION',
            'version' => 'latest', // Or any specific
        ]);

        $adapter = new CloudWatch($client, '/group/name', 'stream-name');

        return new Logger('messages', ['main' => $adapter]);
    }
);

use Phalcon\Db\Adapter\Pdo\Mysql;
use Phalcon\Incubator\Logger\Adapter\Database as DbLogger;

$di->set(
    'logger',
    function () {
        $connection = new Mysql(
            [
                'host'     => 'localhost',
                'username' => 'root',
                'password' => 'secret',
                'dbname'   => 'audit',
            ]
        );

        $logsName  = 'errors';
        $tableName = 'logs';

        return new DbLogger($connection, $logsName, $tableName);
    }
);

use Phalcon\Incubator\Logger\Adapter\Udp as UdpLogger;

$di->set(
    'logger',
    function () {
        $host = '192.168.1.2';
        $port = 65000;

        return new UdpLogger('errors', $host, $port);
    }
);

$adapter = new \Phalcon\Incubator\Logger\Adapter\Slack('api-token','channel-name');

$logger = new \Phalcon\Logger\Logger('logger-name', ['main-slack' => $adapter]);
$logger->info('Information message to log in the channel channel-name');