use Monolog\Logger; use Monolog\Handler\StreamHandler; // Create the logger $logger = new Logger('my_logger'); // Set up a file handler to write logs to a file $handler = new StreamHandler('path/to/log_file.log', Logger::DEBUG); // Add the handler to the logger $logger->pushHandler($handler); // Log a debug message $logger->debug('Debug message');
use Psr\Log\LoggerInterface; use Psr\Log\LogLevel; function myFunction(LoggerInterface $logger, $parameter) { $logger->log(LogLevel::INFO, "Received parameter: {$parameter}"); // Some code $logger->debug('Debug message'); } // Create the logger $logger = new MyLoggerImplementation(); myFunction($logger, 'some_parameter');In this example, we are using the Psr\Log interface to define a logging interface that can be implemented by different libraries. We define a function that takes an instance of a LoggerInterface and logs a message with info level when it receives a parameter, and another message with debug level later in the function. We then create a logger and pass it to our function along with a parameter.