use Monolog\Logger; use Monolog\Handler\StreamHandler; $logger = new Logger('my_logger'); $logger->pushHandler(new StreamHandler('path/to/your.log', Logger::WARNING)); $logger->warning('This is a warning message');In this example, we are using the Monolog package library. The Logger object is initialized and given a name of "my_logger." We then push a StreamHandler object to the logger that will write logs to a file at the specified path, and only logs with a level of WARNING or greater will be processed. When we log a warning message using $logger->warning('This is a warning message'), it will write that message to the log file.