PHP code example of avto-dev / events-log-laravel
1. Go to this page and download the library: Download avto-dev/events-log-laravel 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/ */
avto-dev / events-log-laravel example snippets
return [
// ...
'events_channel' => env('EVENTS_LOG_CHANNEL', 'stack'),
// ...
];
return [
'events_channel' => env('EVENTS_LOG_CHANNEL', 'events-stack'),
// ...
'channels' => [
// ...
'events-stack' => [
'driver' => 'stack',
'channels' => ['events-monolog', 'events-logstash'],
],
'events-monolog' => [
'driver' => 'single',
'path' => storage_path('logs/laravel-events.log'),
'level' => 'debug',
],
'events-logstash' => [
'driver' => 'custom',
'via' => AvtoDev\EventsLogLaravel\Logging\EventsLogstashLogger::class,
'path' => storage_path('logs/logstash/laravel-events.log'),
'level' => 'debug',
],
],
];
return [
'default' => env('LOG_CHANNEL', 'app-logstash-udp'),
'events_channel' => env('EVENTS_LOG_CHANNEL', 'events-logstash-udp'),
// ...
'channels' => [
// ...
'app-logstash-udp' => [
'driver' => 'custom',
'via' => AvtoDev\EventsLogLaravel\Logging\DefaultUdpLogstashLogger::class,
'host' => env('LOGSTASH_UDP_HOST', 'logstash'),
'port' => (int) env('LOGSTASH_UDP_PORT', 4560),
'level' => 'debug',
],
'events-logstash-udp' => [
'driver' => 'custom',
'via' => AvtoDev\EventsLogLaravel\Logging\EventsUdpLogstashLogger::class,
'host' => env('LOGSTASH_UDP_HOST', 'logstash'),
'port' => (int) env('LOGSTASH_UDP_PORT', 4560),
'level' => 'debug',
],
],
];
class SomeApplicationEvent implements \AvtoDev\EventsLogLaravel\Contracts\ShouldBeLoggedContract
{
/**
* {@inheritdoc}
*/
public function logLevel(): string
{
return 'info';
}
/**
* {@inheritdoc}
*/
public function logMessage(): string
{
return 'My log message';
}
/**
* {@inheritdoc}
*/
public function logEventExtraData(): array
{
return ['key' => 'any value'];
}
/**
* {@inheritdoc}
*/
public function eventType(): string
{
return 'default_event';
}
/**
* {@inheritdoc}
*/
public function eventSource(): string
{
return 'service_name';
}
/**
* {@inheritdoc}
*/
public function skipLogging() : bool
{
return false;
}
}
event(new SomeApplicationEvent);
class YourEvent extends AvtoDev\EventsLogLaravel\Events\AbstractLoggableEvent
{
/**
* @var int
*/
protected $value = 101;
/**
* {@inheritDoc}
*/
public function logMessage(): string
{
return 'foo bar';
}
/**
* {@inheritDoc}
*/
public function skipLogging(): bool
{
return $this->value > 100;
}
// ...
}