From 22f26ddb38383e7d6f68effdbe73b57eb66d5afa Mon Sep 17 00:00:00 2001 From: tristan Date: Thu, 22 Jan 2026 11:00:06 +0100 Subject: [PATCH] feat : Ajout du bundle Monolog pour la gestion des logs --- .idea/ferme.iml | 3 + .idea/php.xml | 3 + .idea/workspace.xml | 38 ++++- README.md | 4 + composer.json | 1 + composer.lock | 261 ++++++++++++++++++++++++++++++++++- config/bundles.php | 2 + config/packages/monolog.yaml | 28 ++++ config/reference.php | 147 ++++++++++++++++++++ makefile | 7 + symfony.lock | 12 ++ 11 files changed, 500 insertions(+), 6 deletions(-) create mode 100644 config/packages/monolog.yaml diff --git a/.idea/ferme.iml b/.idea/ferme.iml index 5003136..a55a4eb 100644 --- a/.idea/ferme.iml +++ b/.idea/ferme.iml @@ -147,6 +147,9 @@ + + + diff --git a/.idea/php.xml b/.idea/php.xml index c3e6f97..dfc3b24 100644 --- a/.idea/php.xml +++ b/.idea/php.xml @@ -153,6 +153,9 @@ + + + diff --git a/.idea/workspace.xml b/.idea/workspace.xml index d710e64..d83585d 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -4,10 +4,17 @@ - + + + - + + + + + + { @@ -263,7 +273,7 @@ - + - @@ -496,7 +522,9 @@ - diff --git a/README.md b/README.md index 0ab3b4b..1227aa6 100644 --- a/README.md +++ b/README.md @@ -116,3 +116,7 @@ Sélectionner entity User, taper sont mdp, le copier et l'ajouter dans l'insert INSERT INTO "user" (username, roles, password) VALUES ('Mon user', '["ROLE_USER"]', 'Mon mdp hashé'); ``` +## Gestion des logs +Pour suivre les logs en temps réel : +* tail -f var/log/dev.log +* tail -f var/log/prod.log diff --git a/composer.json b/composer.json index 219d46d..57a7a13 100644 --- a/composer.json +++ b/composer.json @@ -24,6 +24,7 @@ "symfony/flex": "^2", "symfony/framework-bundle": "8.0.*", "symfony/http-client": "8.0.*", + "symfony/monolog-bundle": "^4.0", "symfony/property-access": "8.0.*", "symfony/property-info": "8.0.*", "symfony/runtime": "8.0.*", diff --git a/composer.lock b/composer.lock index 1bc79ae..7617e63 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "f619208e7dd3272e671e7c2b139afa87", + "content-hash": "e122271fbb08b4c19c1fe6084f95aeab", "packages": [ { "name": "api-platform/doctrine-common", @@ -2772,6 +2772,109 @@ }, "time": "2025-07-25T09:04:22+00:00" }, + { + "name": "monolog/monolog", + "version": "3.10.0", + "source": { + "type": "git", + "url": "https://github.com/Seldaek/monolog.git", + "reference": "b321dd6749f0bf7189444158a3ce785cc16d69b0" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Seldaek/monolog/zipball/b321dd6749f0bf7189444158a3ce785cc16d69b0", + "reference": "b321dd6749f0bf7189444158a3ce785cc16d69b0", + "shasum": "" + }, + "require": { + "php": ">=8.1", + "psr/log": "^2.0 || ^3.0" + }, + "provide": { + "psr/log-implementation": "3.0.0" + }, + "require-dev": { + "aws/aws-sdk-php": "^3.0", + "doctrine/couchdb": "~1.0@dev", + "elasticsearch/elasticsearch": "^7 || ^8", + "ext-json": "*", + "graylog2/gelf-php": "^1.4.2 || ^2.0", + "guzzlehttp/guzzle": "^7.4.5", + "guzzlehttp/psr7": "^2.2", + "mongodb/mongodb": "^1.8 || ^2.0", + "php-amqplib/php-amqplib": "~2.4 || ^3", + "php-console/php-console": "^3.1.8", + "phpstan/phpstan": "^2", + "phpstan/phpstan-deprecation-rules": "^2", + "phpstan/phpstan-strict-rules": "^2", + "phpunit/phpunit": "^10.5.17 || ^11.0.7", + "predis/predis": "^1.1 || ^2", + "rollbar/rollbar": "^4.0", + "ruflin/elastica": "^7 || ^8", + "symfony/mailer": "^5.4 || ^6", + "symfony/mime": "^5.4 || ^6" + }, + "suggest": { + "aws/aws-sdk-php": "Allow sending log messages to AWS services like DynamoDB", + "doctrine/couchdb": "Allow sending log messages to a CouchDB server", + "elasticsearch/elasticsearch": "Allow sending log messages to an Elasticsearch server via official client", + "ext-amqp": "Allow sending log messages to an AMQP server (1.0+ required)", + "ext-curl": "Required to send log messages using the IFTTTHandler, the LogglyHandler, the SendGridHandler, the SlackWebhookHandler or the TelegramBotHandler", + "ext-mbstring": "Allow to work properly with unicode symbols", + "ext-mongodb": "Allow sending log messages to a MongoDB server (via driver)", + "ext-openssl": "Required to send log messages using SSL", + "ext-sockets": "Allow sending log messages to a Syslog server (via UDP driver)", + "graylog2/gelf-php": "Allow sending log messages to a GrayLog2 server", + "mongodb/mongodb": "Allow sending log messages to a MongoDB server (via library)", + "php-amqplib/php-amqplib": "Allow sending log messages to an AMQP server using php-amqplib", + "rollbar/rollbar": "Allow sending log messages to Rollbar", + "ruflin/elastica": "Allow sending log messages to an Elastic Search server" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "3.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": "https://seld.be" + } + ], + "description": "Sends your logs to files, sockets, inboxes, databases and various web services", + "homepage": "https://github.com/Seldaek/monolog", + "keywords": [ + "log", + "logging", + "psr-3" + ], + "support": { + "issues": "https://github.com/Seldaek/monolog/issues", + "source": "https://github.com/Seldaek/monolog/tree/3.10.0" + }, + "funding": [ + { + "url": "https://github.com/Seldaek", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/monolog/monolog", + "type": "tidelift" + } + ], + "time": "2026-01-02T08:56:05+00:00" + }, { "name": "nelmio/cors-bundle", "version": "2.6.0", @@ -5272,6 +5375,162 @@ ], "time": "2025-12-31T09:29:34+00:00" }, + { + "name": "symfony/monolog-bridge", + "version": "v8.0.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/monolog-bridge.git", + "reference": "6dd0793eb9ebcecb0b909a5571ac6e82867d7b20" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/monolog-bridge/zipball/6dd0793eb9ebcecb0b909a5571ac6e82867d7b20", + "reference": "6dd0793eb9ebcecb0b909a5571ac6e82867d7b20", + "shasum": "" + }, + "require": { + "monolog/monolog": "^3", + "php": ">=8.4", + "symfony/http-kernel": "^7.4|^8.0", + "symfony/service-contracts": "^2.5|^3" + }, + "require-dev": { + "symfony/console": "^7.4|^8.0", + "symfony/http-client": "^7.4|^8.0", + "symfony/mailer": "^7.4|^8.0", + "symfony/messenger": "^7.4|^8.0", + "symfony/mime": "^7.4|^8.0", + "symfony/security-core": "^7.4|^8.0", + "symfony/var-dumper": "^7.4|^8.0" + }, + "type": "symfony-bridge", + "autoload": { + "psr-4": { + "Symfony\\Bridge\\Monolog\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Provides integration for Monolog with various Symfony components", + "homepage": "https://symfony.com", + "support": { + "source": "https://github.com/symfony/monolog-bridge/tree/v8.0.0" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://github.com/nicolas-grekas", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2025-11-01T09:19:23+00:00" + }, + { + "name": "symfony/monolog-bundle", + "version": "v4.0.1", + "source": { + "type": "git", + "url": "https://github.com/symfony/monolog-bundle.git", + "reference": "3b4ee2717ee56c5e1edb516140a175eb2a72bc66" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/monolog-bundle/zipball/3b4ee2717ee56c5e1edb516140a175eb2a72bc66", + "reference": "3b4ee2717ee56c5e1edb516140a175eb2a72bc66", + "shasum": "" + }, + "require": { + "composer-runtime-api": "^2.0", + "monolog/monolog": "^3.5", + "php": ">=8.2", + "symfony/config": "^7.3 || ^8.0", + "symfony/dependency-injection": "^7.3 || ^8.0", + "symfony/http-kernel": "^7.3 || ^8.0", + "symfony/monolog-bridge": "^7.3 || ^8.0", + "symfony/polyfill-php84": "^1.30" + }, + "require-dev": { + "phpunit/phpunit": "^11.5.41 || ^12.3", + "symfony/console": "^7.3 || ^8.0", + "symfony/yaml": "^7.3 || ^8.0" + }, + "type": "symfony-bundle", + "autoload": { + "psr-4": { + "Symfony\\Bundle\\MonologBundle\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony MonologBundle", + "homepage": "https://symfony.com", + "keywords": [ + "log", + "logging" + ], + "support": { + "issues": "https://github.com/symfony/monolog-bundle/issues", + "source": "https://github.com/symfony/monolog-bundle/tree/v4.0.1" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://github.com/nicolas-grekas", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2025-12-08T08:00:13+00:00" + }, { "name": "symfony/password-hasher", "version": "v8.0.0", diff --git a/config/bundles.php b/config/bundles.php index b80cfea..9af6e40 100644 --- a/config/bundles.php +++ b/config/bundles.php @@ -8,6 +8,7 @@ use Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle; use Lexik\Bundle\JWTAuthenticationBundle\LexikJWTAuthenticationBundle; use Nelmio\CorsBundle\NelmioCorsBundle; use Symfony\Bundle\FrameworkBundle\FrameworkBundle; +use Symfony\Bundle\MonologBundle\MonologBundle; use Symfony\Bundle\SecurityBundle\SecurityBundle; use Symfony\Bundle\TwigBundle\TwigBundle; @@ -20,4 +21,5 @@ return [ NelmioCorsBundle::class => ['all' => true], LexikJWTAuthenticationBundle::class => ['all' => true], ApiPlatformBundle::class => ['all' => true], + MonologBundle::class => ['all' => true], ]; diff --git a/config/packages/monolog.yaml b/config/packages/monolog.yaml new file mode 100644 index 0000000..bbc6f01 --- /dev/null +++ b/config/packages/monolog.yaml @@ -0,0 +1,28 @@ +monolog: + channels: [deprecation] + +when@dev: + monolog: + handlers: + main: + type: stream + path: "%kernel.logs_dir%/%kernel.environment%.log" + level: debug + channels: ["!event"] + console: + type: console + process_psr_3_messages: false + channels: ["!event", "!doctrine", "!console"] + +when@prod: + monolog: + handlers: + main: + type: stream + path: "%kernel.logs_dir%/%kernel.environment%.log" + level: info + channels: ["!deprecation"] + deprecation: + type: stream + channels: [deprecation] + path: "%kernel.logs_dir%/deprecations.log" diff --git a/config/reference.php b/config/reference.php index 8299155..bd0651f 100644 --- a/config/reference.php +++ b/config/reference.php @@ -1608,6 +1608,149 @@ use Symfony\Component\Config\Loader\ParamConfigurator as Param; * ... * }, * } + * @psalm-type MonologConfig = array{ + * use_microseconds?: scalar|null|Param, // Default: true + * channels?: list, + * handlers?: array, + * }>, + * accepted_levels?: list, + * min_level?: scalar|null|Param, // Default: "DEBUG" + * max_level?: scalar|null|Param, // Default: "EMERGENCY" + * buffer_size?: scalar|null|Param, // Default: 0 + * flush_on_overflow?: bool|Param, // Default: false + * handler?: scalar|null|Param, + * url?: scalar|null|Param, + * exchange?: scalar|null|Param, + * exchange_name?: scalar|null|Param, // Default: "log" + * channel?: scalar|null|Param, // Default: null + * bot_name?: scalar|null|Param, // Default: "Monolog" + * use_attachment?: scalar|null|Param, // Default: true + * use_short_attachment?: scalar|null|Param, // Default: false + * include_extra?: scalar|null|Param, // Default: false + * icon_emoji?: scalar|null|Param, // Default: null + * webhook_url?: scalar|null|Param, + * exclude_fields?: list, + * token?: scalar|null|Param, + * region?: scalar|null|Param, + * source?: scalar|null|Param, + * use_ssl?: bool|Param, // Default: true + * user?: mixed, + * title?: scalar|null|Param, // Default: null + * host?: scalar|null|Param, // Default: null + * port?: scalar|null|Param, // Default: 514 + * config?: list, + * members?: list, + * connection_string?: scalar|null|Param, + * timeout?: scalar|null|Param, + * time?: scalar|null|Param, // Default: 60 + * deduplication_level?: scalar|null|Param, // Default: 400 + * store?: scalar|null|Param, // Default: null + * connection_timeout?: scalar|null|Param, + * persistent?: bool|Param, + * message_type?: scalar|null|Param, // Default: 0 + * parse_mode?: scalar|null|Param, // Default: null + * disable_webpage_preview?: bool|null|Param, // Default: null + * disable_notification?: bool|null|Param, // Default: null + * split_long_messages?: bool|Param, // Default: false + * delay_between_messages?: bool|Param, // Default: false + * topic?: int|Param, // Default: null + * factor?: int|Param, // Default: 1 + * tags?: list, + * console_formatter_options?: mixed, // Default: [] + * formatter?: scalar|null|Param, + * nested?: bool|Param, // Default: false + * publisher?: string|array{ + * id?: scalar|null|Param, + * hostname?: scalar|null|Param, + * port?: scalar|null|Param, // Default: 12201 + * chunk_size?: scalar|null|Param, // Default: 1420 + * encoder?: "json"|"compressed_json"|Param, + * }, + * mongodb?: string|array{ + * id?: scalar|null|Param, // ID of a MongoDB\Client service + * uri?: scalar|null|Param, + * username?: scalar|null|Param, + * password?: scalar|null|Param, + * database?: scalar|null|Param, // Default: "monolog" + * collection?: scalar|null|Param, // Default: "logs" + * }, + * elasticsearch?: string|array{ + * id?: scalar|null|Param, + * hosts?: list, + * host?: scalar|null|Param, + * port?: scalar|null|Param, // Default: 9200 + * transport?: scalar|null|Param, // Default: "Http" + * user?: scalar|null|Param, // Default: null + * password?: scalar|null|Param, // Default: null + * }, + * index?: scalar|null|Param, // Default: "monolog" + * document_type?: scalar|null|Param, // Default: "logs" + * ignore_error?: scalar|null|Param, // Default: false + * redis?: string|array{ + * id?: scalar|null|Param, + * host?: scalar|null|Param, + * password?: scalar|null|Param, // Default: null + * port?: scalar|null|Param, // Default: 6379 + * database?: scalar|null|Param, // Default: 0 + * key_name?: scalar|null|Param, // Default: "monolog_redis" + * }, + * predis?: string|array{ + * id?: scalar|null|Param, + * host?: scalar|null|Param, + * }, + * from_email?: scalar|null|Param, + * to_email?: list, + * subject?: scalar|null|Param, + * content_type?: scalar|null|Param, // Default: null + * headers?: list, + * mailer?: scalar|null|Param, // Default: null + * email_prototype?: string|array{ + * id: scalar|null|Param, + * method?: scalar|null|Param, // Default: null + * }, + * verbosity_levels?: array{ + * VERBOSITY_QUIET?: scalar|null|Param, // Default: "ERROR" + * VERBOSITY_NORMAL?: scalar|null|Param, // Default: "WARNING" + * VERBOSITY_VERBOSE?: scalar|null|Param, // Default: "NOTICE" + * VERBOSITY_VERY_VERBOSE?: scalar|null|Param, // Default: "INFO" + * VERBOSITY_DEBUG?: scalar|null|Param, // Default: "DEBUG" + * }, + * channels?: string|array{ + * type?: scalar|null|Param, + * elements?: list, + * }, + * }>, + * } * @psalm-type ConfigType = array{ * imports?: ImportsConfig, * parameters?: ParametersConfig, @@ -1620,6 +1763,7 @@ use Symfony\Component\Config\Loader\ParamConfigurator as Param; * nelmio_cors?: NelmioCorsConfig, * lexik_jwt_authentication?: LexikJwtAuthenticationConfig, * api_platform?: ApiPlatformConfig, + * monolog?: MonologConfig, * "when@dev"?: array{ * imports?: ImportsConfig, * parameters?: ParametersConfig, @@ -1632,6 +1776,7 @@ use Symfony\Component\Config\Loader\ParamConfigurator as Param; * nelmio_cors?: NelmioCorsConfig, * lexik_jwt_authentication?: LexikJwtAuthenticationConfig, * api_platform?: ApiPlatformConfig, + * monolog?: MonologConfig, * }, * "when@prod"?: array{ * imports?: ImportsConfig, @@ -1645,6 +1790,7 @@ use Symfony\Component\Config\Loader\ParamConfigurator as Param; * nelmio_cors?: NelmioCorsConfig, * lexik_jwt_authentication?: LexikJwtAuthenticationConfig, * api_platform?: ApiPlatformConfig, + * monolog?: MonologConfig, * }, * "when@test"?: array{ * imports?: ImportsConfig, @@ -1658,6 +1804,7 @@ use Symfony\Component\Config\Loader\ParamConfigurator as Param; * nelmio_cors?: NelmioCorsConfig, * lexik_jwt_authentication?: LexikJwtAuthenticationConfig, * api_platform?: ApiPlatformConfig, + * monolog?: MonologConfig, * }, * ...