This commit is contained in:
候学杰 2018-05-02 19:24:15 +08:00
parent 8c4606868d
commit 2ae8d99338
3 changed files with 240 additions and 8 deletions

View File

@ -12,6 +12,7 @@
}
},
"require": {
"illuminate/support": "^5.5"
"monolog/monolog": "^1.23",
"illuminate/database": "^5.6"
}
}

230
composer.lock generated
View File

@ -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": "8e27bbe8d16662983c8105d23ac979d2",
"content-hash": "42855112902b3b78f8cff7d97a6515c7",
"packages": [
{
"name": "doctrine/inflector",
@ -73,6 +73,50 @@
],
"time": "2018-01-09T20:05:19+00:00"
},
{
"name": "illuminate/container",
"version": "v5.6.19",
"source": {
"type": "git",
"url": "https://github.com/illuminate/container.git",
"reference": "4a42d667a05ec6d31f05b532cdac7e8e68e5ea2a"
},
"dist": {
"type": "zip",
"url": "https://files.phpcomposer.com/files/illuminate/container/4a42d667a05ec6d31f05b532cdac7e8e68e5ea2a.zip",
"reference": "4a42d667a05ec6d31f05b532cdac7e8e68e5ea2a",
"shasum": ""
},
"require": {
"illuminate/contracts": "5.6.*",
"php": "^7.1.3",
"psr/container": "~1.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "5.6-dev"
}
},
"autoload": {
"psr-4": {
"Illuminate\\Container\\": ""
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Taylor Otwell",
"email": "taylor@laravel.com"
}
],
"description": "The Illuminate Container package.",
"homepage": "https://laravel.com",
"time": "2018-01-21T02:13:38+00:00"
},
{
"name": "illuminate/contracts",
"version": "v5.6.19",
@ -117,6 +161,65 @@
"homepage": "https://laravel.com",
"time": "2018-04-07T17:05:26+00:00"
},
{
"name": "illuminate/database",
"version": "v5.6.19",
"source": {
"type": "git",
"url": "https://github.com/illuminate/database.git",
"reference": "1d0eebfe6cf18a8e2f7e392dec829559f7c0cc17"
},
"dist": {
"type": "zip",
"url": "https://files.phpcomposer.com/files/illuminate/database/1d0eebfe6cf18a8e2f7e392dec829559f7c0cc17.zip",
"reference": "1d0eebfe6cf18a8e2f7e392dec829559f7c0cc17",
"shasum": ""
},
"require": {
"illuminate/container": "5.6.*",
"illuminate/contracts": "5.6.*",
"illuminate/support": "5.6.*",
"php": "^7.1.3"
},
"suggest": {
"doctrine/dbal": "Required to rename columns and drop SQLite columns (~2.6).",
"fzaninotto/faker": "Required to use the eloquent factory builder (~1.4).",
"illuminate/console": "Required to use the database commands (5.6.*).",
"illuminate/events": "Required to use the observers with Eloquent (5.6.*).",
"illuminate/filesystem": "Required to use the migrations (5.6.*).",
"illuminate/pagination": "Required to paginate the result set (5.6.*)."
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "5.6-dev"
}
},
"autoload": {
"psr-4": {
"Illuminate\\Database\\": ""
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Taylor Otwell",
"email": "taylor@laravel.com"
}
],
"description": "The Illuminate Database package.",
"homepage": "https://laravel.com",
"keywords": [
"database",
"laravel",
"orm",
"sql"
],
"time": "2018-04-29T12:57:53+00:00"
},
{
"name": "illuminate/support",
"version": "v5.6.19",
@ -174,6 +277,84 @@
"homepage": "https://laravel.com",
"time": "2018-04-29T13:02:42+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://files.phpcomposer.com/files/Seldaek/monolog/fd8c787753b3a2ad11bc60c063cff1358a32a3b4.zip",
"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": "nesbot/carbon",
"version": "1.27.0",
@ -271,6 +452,53 @@
],
"time": "2017-02-14T16:28:37+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://files.phpcomposer.com/files/php-fig/log/4ebe3a8bf773a19edfe0a84b6585ba3d401b724d.zip",
"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": "psr/simple-cache",
"version": "1.0.1",

View File

@ -3,9 +3,9 @@
namespace Arch\Listeners;
use Illuminate\Database\Events\QueryExecuted;
use Monolog\Handler\StreamHandler;
use Monolog\Formatter\LineFormatter;
use Monolog\Handler\RotatingFileHandler;
use Monolog\Logger;
use Psr\Log\LoggerInterface;
class QueryListener
{
@ -16,7 +16,11 @@ class QueryListener
*/
public function __construct()
{
//
$this->logger = new Logger(env('APP_NAME', 'APP_NAME'));
$handler = new RotatingFileHandler(storage_path('/logs/sql.log'), 15);
$formatter = new LineFormatter(null, null, false, true);
$handler->setFormatter($formatter);
$this->logger->pushHandler($handler);
}
/**
@ -30,9 +34,8 @@ class QueryListener
if (env('APP_DEBUG')) {
$sql = str_replace("?", "'%s'", $event->sql);
$log = vsprintf($sql, $event->bindings);
$logger = new Logger(env('APP_NAME', 'APP_NAME'));
$logger->pushHandler(new StreamHandler(storage_path('logs/sql.log')));
$logger->info($log);
$this->logger->info($log);
}
}
}