Install the Bundle
composer require digipolisgent/syslog-bundle
Enable the Bundle
Add to config/bundles.php:
return [
// ...
Digipolis\SyslogBundle\DigipolisSyslogBundle::class => ['all' => true],
];
Configure Syslog Identity
Add to config/packages/devmonolog.yaml (or your Monolog config):
digipolis_syslog_identity:
name: "your_app_name"
facility: "local0" # Default: "local0"
host: "localhost" # Default: "localhost"
port: 514 # Default: 514
First Use Case: Logging to ELK Inject the logger in a service/controller:
use Psr\Log\LoggerInterface;
class SomeController
{
public function __construct(private LoggerInterface $logger)
{
}
public function index()
{
$this->logger->info('Test message', ['context' => 'data']);
}
}
Structured Logging for Kibana Use JSON-formatted logs with context arrays for easy filtering in Kibana:
$this->logger->error('Failed to process order', [
'order_id' => 123,
'user_id' => 456,
'error' => 'Payment declined'
]);
Conditional Logging Leverage Monolog’s channel system to route logs differently:
# config/packages/monolog.yaml
monolog:
handlers:
syslog:
type: syslog
level: debug
channels: ["app", "security"]
Custom Formatter Overrides Extend the default formatter (if needed) by creating a custom handler:
# config/packages/monolog.yaml
monolog:
handlers:
custom_syslog:
type: custom_handler
formatter: Digipolis\SyslogBundle\Formatter\ElkFormatter
level: info
Environment-Specific Configs
Use separate configs for dev/prod:
# config/packages/prod/monolog.yaml
digipolis_syslog_identity:
facility: "local1" # Different facility for production
host: "syslog.prod.example.com"
Integration with Laravel (Symfony Bridge)
If using Laravel, bridge the bundle via symfony/monolog-bundle:
// config/app.php
'providers' => [
// ...
Symfony\Bridge\Monolog\MonologServiceProvider::class,
],
Deprecated Bundle
Syslog Facility Limits
local0-local7) are often restricted on shared hosts.user or daemon if local* is blocked.Kibana Parsing Issues
handlers:
file:
type: stream
path: "%kernel.logs_dir%/%kernel.environment%.log"
level: debug
Port/Protocol Conflicts
port: 514, transport: "tcp" in config) for reliability.Context Depth Limits
tail -f /var/log/syslog # Linux
journalctl -u rsyslog # Systemd
logger Command
logger -p local0.info "Test message"
handlers:
debug:
type: stream
path: "php://stderr"
level: debug
Custom Handlers
Extend Digipolis\SyslogBundle\Handler\SyslogHandler to add pre-processing:
class CustomSyslogHandler extends SyslogHandler
{
protected function write(array $record): void
{
$record['extra']['custom_field'] = 'value';
parent::write($record);
}
}
Dynamic Facility/Host Override config via dependency injection:
$container->setParameter('digipolis_syslog_identity.facility', 'local1');
Add Metadata Inject request/user data automatically:
$handler = new SyslogHandler($level, $bubble, [
'extra' => [
'request_id' => $this->getRequestId(),
'user_id' => $this->getUserId(),
],
]);
How can I help you explore Laravel packages today?