PHP code example of snapsuzun / yii2-logger

1. Go to this page and download the library: Download snapsuzun/yii2-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/ */

    

snapsuzun / yii2-logger example snippets


return [
    //....
    'components' => [
        'logger' => [
            'class' => \snapsuzun\yii2logger\logstash\Logger::class,
            'host' => 'localhost',
            'port' => 12201,
            'logIndex' => 'test', // Index of created logs in ElasticSearch
            'user' => 'username', // Username and password for authenticate on logstash server if it need authentication for create log
            'password' => 'password',
            'transportType' => \snapsuzun\yii2logger\logstash\LogstashInterface::TRANSPORT_HTTP // Maybe TRANSPORT_HTTP or TRANSPORT_SOCKET
        ],
    ],
];

return [
    //....
    'components' => [
        'logger' => [
            'class' => \snapsuzun\yii2logger\logstash\async\LoggerAsync::class,
            'host' => 'localhost',
            'port' => 12201,
            'logIndex' => 'test', // Index of created logs in ElasticSearch
            'user' => 'username', // Username and password for authenticate on logstash server if it need authentication for create log
            'password' => 'password',
            'transportType' => \snapsuzun\yii2logger\logstash\LogstashInterface::TRANSPORT_HTTP, // Maybe TRANSPORT_HTTP or TRANSPORT_SOCKET
            'queue' => 'queue',
        ],
    ],
];

return [
    //....
    'components' => [
        'log' => [
            'targets' => [
                [
                    'class' => \snapsuzun\yii2logger\logstash\LogstashTarget::class,
                    'levels' => ['error', 'warning'],
                    'host' => 'localhost',
                    'port' => 12201,
                    'logIndex' => 'test', // Index of created logs in ElasticSearch
                    'user' => 'username', // Username and password for authenticate on logstash server if it need authentication for create log
                    'password' => 'password',
                    'transportType' => \snapsuzun\yii2logger\logstash\LogstashInterface::TRANSPORT_HTTP // Maybe TRANSPORT_HTTP or TRANSPORT_SOCKET
                ]
            ]
        ]
    ]
]

return [
    //....
    'components' => [
        'log' => [
            'targets' => [
                [
                    'class' => \snapsuzun\yii2logger\logstash\async\LogstashAsyncTarget::class,
                    'levels' => ['error', 'warning'],
                    'host' => 'localhost',
                    'port' => 12201,
                    'logIndex' => 'test', // Index of created logs in ElasticSearch
                    'user' => 'username', // Username and password for authenticate on logstash server if it need authentication for create log
                    'password' => 'password',
                    'transportType' => \snapsuzun\yii2logger\logstash\LogstashInterface::TRANSPORT_HTTP, // Maybe TRANSPORT_HTTP or TRANSPORT_SOCKET
                    'queue' => 'queue'
                ]
            ]
        ]
    ]
]

return [
    //....
    'components' => [
        'logger' => [
            'class' => \snapsuzun\yii2logger\file\Logger::class
        ],
    ],
];