require_once 'vendor/autoload.php';
use Monolog\Logger; use Monolog\Handler\StreamHandler; $log = new Logger('myapp'); $log->pushHandler(new StreamHandler('logs/app.log', Logger::ERROR)); $log->error('Something went wrong!');In this example, we're creating a new Logger object with the name "myapp", which we can use to identify log entries from our application. We're also adding a StreamHandler object to the logger, which will write to a file called "app.log" in a "logs" subdirectory of our project's root directory. The Logger::ERROR constant is passed as the second argument to the StreamHandler constructor, which tells Monolog to only log messages at the "error" severity level or higher. Finally, we're calling the Logger object's "error" method to actually write the log entry. This method takes a string message as its only argument, which we've set to "Something went wrong!" in this case. Overall, Monolog is an extremely flexible and powerful logging library that can be used for a wide range of applications. Its comprehensive documentation and large user community make it an excellent choice for any PHP developer looking to add logging capabilities to their projects.