I am trying to override the terminate method in \Magento\Framework\App\Bootstrap file which I need to customise the log creation. If anyone overrides this Bootstrap file please provide the solution here.
Thanks in advance.
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It only takes a minute to sign up.
Sign up to join this communityI have used the below steps to create Bootstrap.php patch in Magento 2
vendor/magento/framework/App/Bootstrap.php
Create a the duplicate file and update your required changes
vendor/magento/framework/App/BootstrapUpdated.php
To get the file difference like git diff then please use the below command
diff -u Bootstrap.php BootstrapUpdated.php > bootstrap.patch
After that move bootstrap.patch file into your patch custom directory and remove BootstrapUpdated.php if it first patch then create own directory under Magento root and move your bootstrap.patch file into the directory.
We need to do some manual modification in patch file.this process is common for all the patch file
--- Bootstrap.php 2023-08-14 10:15:16.000000000 -0530
+++ BootstrapUpdated.php 2023-08-14 11:34:47.326054321 -0530
Example:
diff --git a/vendor/magento/framework/App/Bootstrap.php b/vendor/magento/framework/App/Bootstrap.php
index 16d495d922..8c69e73dfb 100644
--- a/vendor/magento/framework/App/Bootstrap.php
+++ b/vendor/magento/framework/App/Bootstrap.php
@@ -435,16 +435,16 @@
if ($this->isDeveloperMode()) {
echo $e;
} else {
- $message = "An error has happened during application run. See exception log for details.\n";
+ $message = "An error has happened during application run. See exception log for details. ";
Use any random index number and use a,b in front all the path. Most important make sure your line number should be get from where the line actually updated in the original file. while doing different it should be starting line of the difference(ex: if ($this->isDeveloperMode()). line 432 from original file) . but the actual line modified from $message(line 435 from original bootstrap file).Please check the first line -/+ symbol in your diff file then update the same in @@ -xxx,xx +xxx,xx @@
Create composer.patches.json if not exist
"patches": {
"magento/framework": {
"BOOTSTRAP-LOG": "m2-patches/bootstrap-log.patch"
}
}
}
Next add your composer.patches.json file in composer.json file
"extra": {
"magento-force": "override",
"composer-exit-on-patch-failure": true,
"patches-file": "composer.patches.json",
"enable-patching": true
},
That's it!. execute composer install and do required Mageno deployment command. Hope this will help to all.