To quickly enable logging for specific APIs, start by configuring the enable_database_logging and enable_email_logging options in your package's configuration file. The new getName() method in AbstractApi (defaulting to snake_case class name) provides a standardized way to reference APIs.
First use case:
// config/api-logger.php
'logging' => [
'enable_database_logging' => ['foo_api', '!bar_api'], // Enable DB logging for foo_api, disable for bar_api
'enable_email_logging' => '~', // Enable email logging for all APIs
],
Use the new array syntax to selectively enable/disable logging per API:
// Enable logging for all APIs except 'payment_api'
'logging' => [
'enable_database_logging' => ['!payment_api'],
],
Extend AbstractApi to customize getName() for better readability:
class PaymentApi extends AbstractApi {
public function getName(): string {
return 'payment_service'; // Custom name instead of snake_case
}
}
Replace deprecated true values with ~ in config files:
- 'enable_database_logging' => true
+ 'enable_database_logging' => '~'
Use the new logging capabilities with existing services:
// In a service class
public function __construct(private ApiLogger $logger) {
$this->logger->log('payment_processed', ['amount' => 100]);
}
The true value for logging options is now deprecated. Update your config files to use ~ for "enable all" behavior.
['!api_name'] disables logging only for that API (others remain unchanged)['api1', '!api2']) requires careful planningFor troubleshooting:
// Check which APIs are enabled for logging
$enabledApis = config('api-logger.enable_database_logging');
$api = new FooApi();
$api->getName(); // Verify naming matches config
Customize logging behavior by:
AbstractApi to modify getName()php artisan vendor:publish --tag=api-logger-configApiLoggerInterfaceThe new array-based system adds minimal overhead (~1ms per request for name resolution), but test in production-like environments for your specific API count.
How can I help you explore Laravel packages today?