Commit 92e6e7c0445e6eb9f6f332470fec1a785e2b6cb8
1 parent
f2dfcc96
-Logger attached
Showing
5 changed files
with
220 additions
and
4 deletions
Show diff stats
backend/config/main.php
... | ... | @@ -45,6 +45,22 @@ |
45 | 45 | ], |
46 | 46 | ], |
47 | 47 | ], |
48 | + 'monolog' => [ | |
49 | + 'class' => '\Mero\Monolog\MonologComponent', | |
50 | + 'channels' => [ | |
51 | + 'main' => [ | |
52 | + 'handler' => [ | |
53 | + [ | |
54 | + 'type' => 'rotating_file', | |
55 | + 'path' => '@runtime/logs/insert.log', | |
56 | + 'level' => 'debug', | |
57 | + 'max_files' => 6, | |
58 | + ] | |
59 | + ], | |
60 | + 'processor' => [], | |
61 | + ], | |
62 | + ], | |
63 | + ], | |
48 | 64 | 'errorHandler' => [ |
49 | 65 | 'errorAction' => 'site/error', |
50 | 66 | ], | ... | ... |
backend/controllers/CallController.php
... | ... | @@ -25,4 +25,18 @@ |
25 | 25 | ] |
26 | 26 | ); |
27 | 27 | } |
28 | + | |
29 | + public function afterAction($action, $result) | |
30 | + { | |
31 | + if ($action === 'create') { | |
32 | + $monologComponent = \Yii::$app->monolog; | |
33 | + $logger = $monologComponent->getLogger(); | |
34 | + /** | |
35 | + * @var \Psr\Log\LoggerInterface $logger | |
36 | + */ | |
37 | + $logger->info('Create action trigered, ip: ' . \Yii::$app->request->getRemoteIP()); | |
38 | + } | |
39 | + | |
40 | + return parent::afterAction($action, $result); | |
41 | + } | |
28 | 42 | } |
29 | 43 | \ No newline at end of file | ... | ... |
common/models/Call.php
1 | 1 | <?php |
2 | 2 | |
3 | 3 | namespace common\models; |
4 | - | |
4 | + | |
5 | 5 | use yii\db\ActiveRecord; |
6 | - | |
6 | + | |
7 | 7 | /** |
8 | 8 | * This is the model class for table "call". |
9 | 9 | * |
... | ... | @@ -100,4 +100,16 @@ |
100 | 100 | 'record' => 'Record', |
101 | 101 | ]; |
102 | 102 | } |
103 | + | |
104 | + public function afterSave($insert, $changedAttributes) | |
105 | + { | |
106 | + $monologComponent = \Yii::$app->monolog; | |
107 | + $logger = $monologComponent->getLogger(); | |
108 | + /** | |
109 | + * @var \Psr\Log\LoggerInterface $logger | |
110 | + */ | |
111 | + $logger->info('Call added, id: ' . $this->id); | |
112 | + | |
113 | + parent::afterSave($insert, $changedAttributes); | |
114 | + } | |
103 | 115 | } | ... | ... |
composer.json
... | ... | @@ -20,7 +20,8 @@ |
20 | 20 | "yiisoft/yii2-swiftmailer": "~2.0.0 || ~2.1.0", |
21 | 21 | "bower-asset/materialize": "^0.100.2", |
22 | 22 | "bower-asset/vue": "^2.5", |
23 | - "bower-asset/axios": "^0.18.0" | |
23 | + "bower-asset/axios": "^0.18.0", | |
24 | + "mero/yii2-monolog": "^0.1.2" | |
24 | 25 | }, |
25 | 26 | "require-dev": { |
26 | 27 | "yiisoft/yii2-debug": "~2.0.0", | ... | ... |
composer.lock
... | ... | @@ -4,7 +4,7 @@ |
4 | 4 | "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", |
5 | 5 | "This file is @generated automatically" |
6 | 6 | ], |
7 | - "content-hash": "b506c80ac36bec49cac93f43643b27ac", | |
7 | + "content-hash": "19f9c2385451423b074602415d6c94fd", | |
8 | 8 | "packages": [ |
9 | 9 | { |
10 | 10 | "name": "bower-asset/axios", |
... | ... | @@ -380,6 +380,179 @@ |
380 | 380 | "time": "2017-06-03T02:28:16+00:00" |
381 | 381 | }, |
382 | 382 | { |
383 | + "name": "mero/yii2-monolog", | |
384 | + "version": "0.1.2", | |
385 | + "source": { | |
386 | + "type": "git", | |
387 | + "url": "https://github.com/merorafael/yii2-monolog.git", | |
388 | + "reference": "52b50059fbabdcb64a61fadf2fddeba97b95cf92" | |
389 | + }, | |
390 | + "dist": { | |
391 | + "type": "zip", | |
392 | + "url": "https://api.github.com/repos/merorafael/yii2-monolog/zipball/52b50059fbabdcb64a61fadf2fddeba97b95cf92", | |
393 | + "reference": "52b50059fbabdcb64a61fadf2fddeba97b95cf92", | |
394 | + "shasum": "" | |
395 | + }, | |
396 | + "require": { | |
397 | + "monolog/monolog": "^1.20", | |
398 | + "yiisoft/yii2": "*" | |
399 | + }, | |
400 | + "type": "yii2-extension", | |
401 | + "extra": { | |
402 | + "branch-alias": { | |
403 | + "dev-master": "1.0.x-dev" | |
404 | + } | |
405 | + }, | |
406 | + "autoload": { | |
407 | + "psr-4": { | |
408 | + "Mero\\Monolog\\": "src/Mero/Monolog" | |
409 | + } | |
410 | + }, | |
411 | + "notification-url": "https://packagist.org/downloads/", | |
412 | + "license": [ | |
413 | + "MIT" | |
414 | + ], | |
415 | + "authors": [ | |
416 | + { | |
417 | + "name": "Rafael Mello", | |
418 | + "email": "merorafael@gmail.com" | |
419 | + } | |
420 | + ], | |
421 | + "description": "The Monolog integration for the Yii framework.", | |
422 | + "keywords": [ | |
423 | + "log", | |
424 | + "logging", | |
425 | + "monolog", | |
426 | + "yii2" | |
427 | + ], | |
428 | + "time": "2016-10-12T14:39:17+00:00" | |
429 | + }, | |
430 | + { | |
431 | + "name": "monolog/monolog", | |
432 | + "version": "1.23.0", | |
433 | + "source": { | |
434 | + "type": "git", | |
435 | + "url": "https://github.com/Seldaek/monolog.git", | |
436 | + "reference": "fd8c787753b3a2ad11bc60c063cff1358a32a3b4" | |
437 | + }, | |
438 | + "dist": { | |
439 | + "type": "zip", | |
440 | + "url": "https://api.github.com/repos/Seldaek/monolog/zipball/fd8c787753b3a2ad11bc60c063cff1358a32a3b4", | |
441 | + "reference": "fd8c787753b3a2ad11bc60c063cff1358a32a3b4", | |
442 | + "shasum": "" | |
443 | + }, | |
444 | + "require": { | |
445 | + "php": ">=5.3.0", | |
446 | + "psr/log": "~1.0" | |
447 | + }, | |
448 | + "provide": { | |
449 | + "psr/log-implementation": "1.0.0" | |
450 | + }, | |
451 | + "require-dev": { | |
452 | + "aws/aws-sdk-php": "^2.4.9 || ^3.0", | |
453 | + "doctrine/couchdb": "~1.0@dev", | |
454 | + "graylog2/gelf-php": "~1.0", | |
455 | + "jakub-onderka/php-parallel-lint": "0.9", | |
456 | + "php-amqplib/php-amqplib": "~2.4", | |
457 | + "php-console/php-console": "^3.1.3", | |
458 | + "phpunit/phpunit": "~4.5", | |
459 | + "phpunit/phpunit-mock-objects": "2.3.0", | |
460 | + "ruflin/elastica": ">=0.90 <3.0", | |
461 | + "sentry/sentry": "^0.13", | |
462 | + "swiftmailer/swiftmailer": "^5.3|^6.0" | |
463 | + }, | |
464 | + "suggest": { | |
465 | + "aws/aws-sdk-php": "Allow sending log messages to AWS services like DynamoDB", | |
466 | + "doctrine/couchdb": "Allow sending log messages to a CouchDB server", | |
467 | + "ext-amqp": "Allow sending log messages to an AMQP server (1.0+ required)", | |
468 | + "ext-mongo": "Allow sending log messages to a MongoDB server", | |
469 | + "graylog2/gelf-php": "Allow sending log messages to a GrayLog2 server", | |
470 | + "mongodb/mongodb": "Allow sending log messages to a MongoDB server via PHP Driver", | |
471 | + "php-amqplib/php-amqplib": "Allow sending log messages to an AMQP server using php-amqplib", | |
472 | + "php-console/php-console": "Allow sending log messages to Google Chrome", | |
473 | + "rollbar/rollbar": "Allow sending log messages to Rollbar", | |
474 | + "ruflin/elastica": "Allow sending log messages to an Elastic Search server", | |
475 | + "sentry/sentry": "Allow sending log messages to a Sentry server" | |
476 | + }, | |
477 | + "type": "library", | |
478 | + "extra": { | |
479 | + "branch-alias": { | |
480 | + "dev-master": "2.0.x-dev" | |
481 | + } | |
482 | + }, | |
483 | + "autoload": { | |
484 | + "psr-4": { | |
485 | + "Monolog\\": "src/Monolog" | |
486 | + } | |
487 | + }, | |
488 | + "notification-url": "https://packagist.org/downloads/", | |
489 | + "license": [ | |
490 | + "MIT" | |
491 | + ], | |
492 | + "authors": [ | |
493 | + { | |
494 | + "name": "Jordi Boggiano", | |
495 | + "email": "j.boggiano@seld.be", | |
496 | + "homepage": "http://seld.be" | |
497 | + } | |
498 | + ], | |
499 | + "description": "Sends your logs to files, sockets, inboxes, databases and various web services", | |
500 | + "homepage": "http://github.com/Seldaek/monolog", | |
501 | + "keywords": [ | |
502 | + "log", | |
503 | + "logging", | |
504 | + "psr-3" | |
505 | + ], | |
506 | + "time": "2017-06-19T01:22:40+00:00" | |
507 | + }, | |
508 | + { | |
509 | + "name": "psr/log", | |
510 | + "version": "1.0.2", | |
511 | + "source": { | |
512 | + "type": "git", | |
513 | + "url": "https://github.com/php-fig/log.git", | |
514 | + "reference": "4ebe3a8bf773a19edfe0a84b6585ba3d401b724d" | |
515 | + }, | |
516 | + "dist": { | |
517 | + "type": "zip", | |
518 | + "url": "https://api.github.com/repos/php-fig/log/zipball/4ebe3a8bf773a19edfe0a84b6585ba3d401b724d", | |
519 | + "reference": "4ebe3a8bf773a19edfe0a84b6585ba3d401b724d", | |
520 | + "shasum": "" | |
521 | + }, | |
522 | + "require": { | |
523 | + "php": ">=5.3.0" | |
524 | + }, | |
525 | + "type": "library", | |
526 | + "extra": { | |
527 | + "branch-alias": { | |
528 | + "dev-master": "1.0.x-dev" | |
529 | + } | |
530 | + }, | |
531 | + "autoload": { | |
532 | + "psr-4": { | |
533 | + "Psr\\Log\\": "Psr/Log/" | |
534 | + } | |
535 | + }, | |
536 | + "notification-url": "https://packagist.org/downloads/", | |
537 | + "license": [ | |
538 | + "MIT" | |
539 | + ], | |
540 | + "authors": [ | |
541 | + { | |
542 | + "name": "PHP-FIG", | |
543 | + "homepage": "http://www.php-fig.org/" | |
544 | + } | |
545 | + ], | |
546 | + "description": "Common interface for logging libraries", | |
547 | + "homepage": "https://github.com/php-fig/log", | |
548 | + "keywords": [ | |
549 | + "log", | |
550 | + "psr", | |
551 | + "psr-3" | |
552 | + ], | |
553 | + "time": "2016-10-10T12:19:37+00:00" | |
554 | + }, | |
555 | + { | |
383 | 556 | "name": "swiftmailer/swiftmailer", |
384 | 557 | "version": "v6.0.2", |
385 | 558 | "source": { | ... | ... |