diff --git a/backend/config/main.php b/backend/config/main.php index bed1c45..8866868 100644 --- a/backend/config/main.php +++ b/backend/config/main.php @@ -45,6 +45,22 @@ ], ], ], + 'monolog' => [ + 'class' => '\Mero\Monolog\MonologComponent', + 'channels' => [ + 'main' => [ + 'handler' => [ + [ + 'type' => 'rotating_file', + 'path' => '@runtime/logs/insert.log', + 'level' => 'debug', + 'max_files' => 6, + ] + ], + 'processor' => [], + ], + ], + ], 'errorHandler' => [ 'errorAction' => 'site/error', ], diff --git a/backend/controllers/CallController.php b/backend/controllers/CallController.php index 0e4cd23..84ce11e 100755 --- a/backend/controllers/CallController.php +++ b/backend/controllers/CallController.php @@ -25,4 +25,18 @@ ] ); } + + public function afterAction($action, $result) + { + if ($action === 'create') { + $monologComponent = \Yii::$app->monolog; + $logger = $monologComponent->getLogger(); + /** + * @var \Psr\Log\LoggerInterface $logger + */ + $logger->info('Create action trigered, ip: ' . \Yii::$app->request->getRemoteIP()); + } + + return parent::afterAction($action, $result); + } } \ No newline at end of file diff --git a/common/models/Call.php b/common/models/Call.php index 53f42b0..f7698d0 100755 --- a/common/models/Call.php +++ b/common/models/Call.php @@ -1,9 +1,9 @@ 'Record', ]; } + + public function afterSave($insert, $changedAttributes) + { + $monologComponent = \Yii::$app->monolog; + $logger = $monologComponent->getLogger(); + /** + * @var \Psr\Log\LoggerInterface $logger + */ + $logger->info('Call added, id: ' . $this->id); + + parent::afterSave($insert, $changedAttributes); + } } diff --git a/composer.json b/composer.json index 8f47ca6..cd1a17b 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,8 @@ "yiisoft/yii2-swiftmailer": "~2.0.0 || ~2.1.0", "bower-asset/materialize": "^0.100.2", "bower-asset/vue": "^2.5", - "bower-asset/axios": "^0.18.0" + "bower-asset/axios": "^0.18.0", + "mero/yii2-monolog": "^0.1.2" }, "require-dev": { "yiisoft/yii2-debug": "~2.0.0", diff --git a/composer.lock b/composer.lock index eed415f..d798c30 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "b506c80ac36bec49cac93f43643b27ac", + "content-hash": "19f9c2385451423b074602415d6c94fd", "packages": [ { "name": "bower-asset/axios", @@ -380,6 +380,179 @@ "time": "2017-06-03T02:28:16+00:00" }, { + "name": "mero/yii2-monolog", + "version": "0.1.2", + "source": { + "type": "git", + "url": "https://github.com/merorafael/yii2-monolog.git", + "reference": "52b50059fbabdcb64a61fadf2fddeba97b95cf92" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/merorafael/yii2-monolog/zipball/52b50059fbabdcb64a61fadf2fddeba97b95cf92", + "reference": "52b50059fbabdcb64a61fadf2fddeba97b95cf92", + "shasum": "" + }, + "require": { + "monolog/monolog": "^1.20", + "yiisoft/yii2": "*" + }, + "type": "yii2-extension", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Mero\\Monolog\\": "src/Mero/Monolog" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Rafael Mello", + "email": "merorafael@gmail.com" + } + ], + "description": "The Monolog integration for the Yii framework.", + "keywords": [ + "log", + "logging", + "monolog", + "yii2" + ], + "time": "2016-10-12T14:39:17+00:00" + }, + { + "name": "monolog/monolog", + "version": "1.23.0", + "source": { + "type": "git", + "url": "https://github.com/Seldaek/monolog.git", + "reference": "fd8c787753b3a2ad11bc60c063cff1358a32a3b4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Seldaek/monolog/zipball/fd8c787753b3a2ad11bc60c063cff1358a32a3b4", + "reference": "fd8c787753b3a2ad11bc60c063cff1358a32a3b4", + "shasum": "" + }, + "require": { + "php": ">=5.3.0", + "psr/log": "~1.0" + }, + "provide": { + "psr/log-implementation": "1.0.0" + }, + "require-dev": { + "aws/aws-sdk-php": "^2.4.9 || ^3.0", + "doctrine/couchdb": "~1.0@dev", + "graylog2/gelf-php": "~1.0", + "jakub-onderka/php-parallel-lint": "0.9", + "php-amqplib/php-amqplib": "~2.4", + "php-console/php-console": "^3.1.3", + "phpunit/phpunit": "~4.5", + "phpunit/phpunit-mock-objects": "2.3.0", + "ruflin/elastica": ">=0.90 <3.0", + "sentry/sentry": "^0.13", + "swiftmailer/swiftmailer": "^5.3|^6.0" + }, + "suggest": { + "aws/aws-sdk-php": "Allow sending log messages to AWS services like DynamoDB", + "doctrine/couchdb": "Allow sending log messages to a CouchDB server", + "ext-amqp": "Allow sending log messages to an AMQP server (1.0+ required)", + "ext-mongo": "Allow sending log messages to a MongoDB server", + "graylog2/gelf-php": "Allow sending log messages to a GrayLog2 server", + "mongodb/mongodb": "Allow sending log messages to a MongoDB server via PHP Driver", + "php-amqplib/php-amqplib": "Allow sending log messages to an AMQP server using php-amqplib", + "php-console/php-console": "Allow sending log messages to Google Chrome", + "rollbar/rollbar": "Allow sending log messages to Rollbar", + "ruflin/elastica": "Allow sending log messages to an Elastic Search server", + "sentry/sentry": "Allow sending log messages to a Sentry server" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Monolog\\": "src/Monolog" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jordi Boggiano", + "email": "j.boggiano@seld.be", + "homepage": "http://seld.be" + } + ], + "description": "Sends your logs to files, sockets, inboxes, databases and various web services", + "homepage": "http://github.com/Seldaek/monolog", + "keywords": [ + "log", + "logging", + "psr-3" + ], + "time": "2017-06-19T01:22:40+00:00" + }, + { + "name": "psr/log", + "version": "1.0.2", + "source": { + "type": "git", + "url": "https://github.com/php-fig/log.git", + "reference": "4ebe3a8bf773a19edfe0a84b6585ba3d401b724d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/log/zipball/4ebe3a8bf773a19edfe0a84b6585ba3d401b724d", + "reference": "4ebe3a8bf773a19edfe0a84b6585ba3d401b724d", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Log\\": "Psr/Log/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interface for logging libraries", + "homepage": "https://github.com/php-fig/log", + "keywords": [ + "log", + "psr", + "psr-3" + ], + "time": "2016-10-10T12:19:37+00:00" + }, + { "name": "swiftmailer/swiftmailer", "version": "v6.0.2", "source": { -- libgit2 0.21.4