Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP Tiny Logger #49

Merged
merged 1 commit into from
Sep 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 26 additions & 0 deletions php/school_app/src/Repository/EventSubscriber.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php namespace SchoolApp\Repository;

use MongoDB\Driver\Monitoring\CommandFailedEvent;
use MongoDB\Driver\Monitoring\CommandStartedEvent;
use MongoDB\Driver\Monitoring\CommandSucceededEvent;

class EventSubscriber implements \MongoDB\Driver\Monitoring\CommandSubscriber
{
public function commandSucceeded(CommandSucceededEvent $event): void
{
$this->writeToLog("Command Succeeded!\n");
}
public function commandFailed(CommandFailedEvent $event): void
{
$this->writeToLog("Command Failed!\n");
}
public function commandStarted(CommandStartedEvent $event): void
{
$this->writeToLog("Command Started!\n");
}
private function writeToLog(string $msg){
$myfile = fopen("/school_app/logfile.txt", "a");
fwrite($myfile, $msg);
fclose($myfile);
}
}
1 change: 1 addition & 0 deletions php/school_app/src/Repository/Mongo.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ private function __construct() {
static function getInstance() {
static $instance;
if ($instance == null) {
\MongoDB\Driver\Monitoring\addSubscriber(new EventSubscriber());
$instance = new Mongo();
}
return $instance;
Expand Down