$context Additional context to log. * @param string $event Channel-relative event name, for dedup grouping. */ public function log( string $message, array $context = [], string $event = 'legacy_log' ) { $this->write_log( 'info', $message, $context, $event ); } /** * Logs a debug message. * * @param string $message The message to log. * @param array $context Additional context to log. * @param string $event Channel-relative event name, for dedup grouping. */ public function debug( string $message, array $context = [], string $event = 'legacy_log' ) { $this->write_log( 'debug', $message, $context, $event ); } /** * Logs an informational message. * * @param string $message The message to log. * @param array $context Additional context to log. * @param string $event Channel-relative event name, for dedup grouping. */ public function info( string $message, array $context = [], string $event = 'legacy_log' ) { $this->write_log( 'info', $message, $context, $event ); } /** * Logs a warning message. * * @param string $message The message to log. * @param array $context Additional context to log. * @param string $event Channel-relative event name, for dedup grouping. */ public function warning( string $message, array $context = [], string $event = 'legacy_log' ) { $this->write_log( 'warning', $message, $context, $event ); } /** * Logs an error message. * * @param string $message The message to log. * @param array $context Additional context to log. * @param string $event Channel-relative event name, for dedup grouping. */ public function error( string $message, array $context = [], string $event = 'legacy_log' ) { $this->write_log( 'error', $message, $context, $event ); } /** * Logs a critical message. * * @param string $message The message to log. * @param array $context Additional context to log. * @param string $event Channel-relative event name, for dedup grouping. */ public function critical( string $message, array $context = [], string $event = 'legacy_log' ) { $this->write_log( 'critical', $message, $context, $event ); } /** * Logs a handled exception or error value. * * @param mixed $exception Throwable, WP_Error, PHP/HTTP/DB error data. * @param string $event Channel-relative event name. * @param array $context Additional context to log. */ public function exception( $exception, string $event = 'legacy_log', array $context = [] ) { AO_Logger::instance()->channel( $this->log_channel() )->exception( $exception, $event, $context ); } /** * Routes legacy trait calls to the central logger, scoped to the consuming class's own channel. * * @param string $level Log level. * @param string $message Log message. * @param array $context Log context. * @param string $event Channel-relative event name. */ private function write_log( string $level, string $message, array $context, string $event ): void { AO_Logger::instance()->record( $level, $this->log_channel(), $event, $message, $context ); } /** * Derives a per-consumer channel from the class using this trait, so unrelated * modules' log records don't collapse into a single 'core' dedup bucket. */ private function log_channel(): string { $class = static::class; $pos = strrpos( $class, '\\' ); return false === $pos ? $class : substr( $class, $pos + 1 ); } }