Logging Package Cheatsheet
Code-verified reference forpackages/logging.
Core Pipeline
Cognesy\Logging\Pipeline\LoggingPipeline:
LoggingPipeline::create(): selffilter(EventFilter $filter): selfenrich(EventEnricher $enricher): selfformat(EventFormatter $formatter): selfwrite(LogWriter $writer): selfbuild(): callable(callable(Event): void)__invoke(): callable(returnsbuild())
build() snapshots the current pipeline configuration. Later builder mutations do not affect an already-built callable.
Minimal usage:
Contracts
EventFilter::__invoke(Event $event): boolEventEnricher::__invoke(Event $event): LogContextEventFormatter::__invoke(Event $event, LogContext $context): LogEntryLogWriter::__invoke(LogEntry $entry): voidContextProvider::getContext(): array
Value Objects
LogEntry:
LogEntry::create(string $level, string $message, array $context = [], ?DateTimeImmutable $timestamp = null, string $channel = 'default'): selfwithContext(array $additionalContext): selfwithLevel(string $level): selfwithMessage(string $message): selfwithChannel(string $channel): selfisLevel(string $level): boolisLevelOrAbove(string $minimumLevel): booljsonSerialize(): array
LogContext:
LogContext::fromEvent(Event $event, array $additionalContext = []): selfwithFrameworkContext(array $context): selfwithPerformanceMetrics(array $metrics): selfwithUserContext(array $context): selftoArray(): arrayjsonSerialize(): array
Built-In Filters
LogLevelFilter(string $minimumLevel = LogLevel::DEBUG)EventClassFilter(array $excludedClasses = [], array $includedClasses = [])EventHierarchyFilter(array $excludedClasses = [], array $includedClasses = [])CompositeFilter(EventFilter ...$filters)(AND logic)
EventHierarchyFilter helpers:
EventHierarchyFilter::httpEventsOnly(): selfEventHierarchyFilter::structuredOutputEventsOnly(): selfEventHierarchyFilter::excludeHttpDebug(): self
Built-In Enrichers
BaseEnricherLazyEnricher(Closure $contextProvider, string $contextKey = 'framework')LazyEnricher::framework(Closure $provider): selfLazyEnricher::metrics(Closure $provider): selfLazyEnricher::user(Closure $provider): self
Built-In Formatters
DefaultFormatter(string $messageTemplate = '{event_class}: {message}', string $channel = 'instructor')MessageTemplateFormatter(array $templates = [], string $defaultTemplate = '{event_name}', string $channel = 'instructor')
MessageTemplateFormatter:
{event_class},{event_name},{event_id}- event-data placeholders like
{method},{url} - framework placeholders like
{framework.request_id}
Built-In Writers
PsrLoggerWriter(LoggerInterface $logger)MonologChannelWriter(Logger $logger, bool $useEntryChannel = true)CallableWriter(Closure $writer)CallableWriter::create(callable $writer): selfCompositeWriter(LogWriter ...$writers)
Framework Factories
Config keys:channel(string)level(string)exclude_events(array<class-string>)include_events(array<class-string>)templates(array<string, string>)
SymfonyLoggingFactory:
create(ContainerInterface $container, LoggerInterface $logger, array $config = []): callabledefaultSetup(ContainerInterface $container, LoggerInterface $logger): callableproductionSetup(ContainerInterface $container, LoggerInterface $logger): callable
Wiretap Integration
Cognesy\Logging\Integrations\EventPipelineWiretap:
EventPipelineWiretap(mixed $pipeline)— wraps acallable(Event): voidpipeline__invoke(object $event): void— forwardsEventinstances to the pipeline, ignores non-Event objects
Framework Integrations
Laravel:- Laravel-specific logging integration lives in
packages/laravel.
Cognesy\Logging\Integrations\Symfony\InstructorLoggingBundleInstructorLoggingExtensionregistersinstructor_logging.pipeline_factoryandinstructor_logging.pipeline_listener.WiretapEventBusPassadds onewiretap()method call to the configured event bus service.
instructor_logging):
enabled(bool, defaulttrue)preset(default|production|custom)event_bus_service(string, defaultCognesy\Events\Contracts\CanHandleEvents)config.channel(string)config.level(emergency|alert|critical|error|warning|notice|info|debug)config.exclude_events(string[])config.include_events(string[])config.templates(array<string, string>)