How To Set Origin Shipping in Magento 2.x

Magento 2 Origin Shipping Setting need to calculate the shipping costs for the shipments made from your store as well as calculate product tax cost.

The following below admin settings need to follow.

Step [1] – Go STORES > Configuration, redirects Configuration section.

Step [2] – Left panel, choose SALES > Shipping Settings.

Step [3] – Right panel, Expand the 

Origin section

&

Shipping Policy Parameters section

Step [4] – Origin section having the following below fields.

Before filling any input field, need to uncheck Use System Value

Country : By default, United States, fill as per Store Origin need.
Region/State : By default California, fill as per Store Origin need.
ZIP/Postal Code : By default 90034, fill as per Store Origin need.
City : fill City as per Store Origin need.
Street Address : fill Street Address as per Store Origin need.
Street Address Line 2 : fill Street Address Line 2 as per Store Origin need.

Shipping Policy Parameters section having Apply custom Shipping Policy, By default No selected

Once Yes selected , new input field Shipping Policy displaying to fill
shipping policy content as per Store Shipping Policy need

Click on Save Config button & run CLI command Flush

Finally, Origin Shipping setting has been done.

Magento 2 All Database Tables [500 & more Tables]


How To Set Multi Shipping Settings In Magento 2


How To Set Origin Shipping in Magento 2


Difference Between Offline Shipping Method and Online Shipping Method


Magento 2 Online Customers Options



How To Apply Customer Group Price of Products in Magento 2



How To Add Customer Groups Dropdown in Magento 2 Admin Form and Grid By UI Component


How To Get all Customers Data in Magento 2


How To Create Customer Order in Magento 2 Admin Panel


Magento 2 Login As Customer Not Enabled


How To Configure Customer Account Sharing Options in Magento 2


Magento 2 Redirect To Customer Dashboard After Login


Which Magento 2 database table store customer shipping and billing address


How To Remove Sales Order Data & Customer Data in Magento 2


Which Magento 2 database table store customer’s Email Data


Which Magento 2 Database Table Store Customer Newsletter Data


Which Magento 2 database table store customer’s shipping and billing address



How To Remove Sales Order Data & Customer Data in Magento 2


Which Magento 2 Database Tables Store Customer Rating


Which Magento 2 Database Tables Store Customer Wishlist Products



Magento 2 Increase Customer Session Time


Which Magento 2 Database Table Store Patches

Magento 2.x Online Customers Options

There are two options Online Minutes Interval & Customer Data Lifetime inside Online Customers Options.

The following below steps need to follow.

Step [1] – Go STORES > Configuration, redirects Configuration section.

Step [2] – Left panel, choose CUSTOMERS > Customer Configuration.

Step [3] – Right panel, Expand the Online Customers Options section.

Step [4] – Two options as below

Online Minutes Interval: Enter the number of minutes allowed for a Customer’s Session time on the site. 15 minutes default time, if you leave this field blank, it is considered as 15 minutes.

Customer Data Lifetime: Enter the number of minutes before unsaved customer’s data. 15 minutes default time.

Step [5] – Click on Save Config button & run CLI command Flush

Finally, Online Minutes Interval (Customer Session time period in minute) & Customer Data Lifetime (in minute) has been set.

Other important Magento 2.x issue as below

Magento 2 All Database Tables [500 & more Tables]


How To Set Multi Shipping Settings In Magento 2


How To Set Origin Shipping in Magento 2


Difference Between Offline Shipping Method and Online Shipping Method


Magento 2 Online Customers Options


How To Apply Customer Group Price of Products in Magento 2


How To Add Customer Groups Dropdown in Magento 2 Admin Form and Grid By UI Component


How To Get all Customers Data in Magento 2


How To Create Customer Order in Magento 2 Admin Panel


Magento 2 Login As Customer Not Enabled


How To Configure Customer Account Sharing Options in Magento 2


Magento 2 Redirect To Customer Dashboard After Login


Which Magento 2 database table store customer shipping and billing address


How To Remove Sales Order Data & Customer Data in Magento 2


Which Magento 2 database table store customer’s Email Data


Which Magento 2 Database Table Store Customer Newsletter Data


Which Magento 2 database table store customer’s shipping and billing address


How To Remove Sales Order Data & Customer Data in Magento 2


Which Magento 2 Database Tables Store Customer Rating


Which Magento 2 Database Tables Store Customer Wishlist Products


Magento 2 Increase Customer Session Time


Which Magento 2 Database Table Store Patches

How To Show Tax/VAT Number in Store front in Magento 2.x

There are following below steps need to follow.

Step [1] – Go STORES > Configuration, redirects Configuration section.

Step [2] – Left panel, choose CUSTOMERS > Customer Configuration.

Step [3] – Right panel, Expand the Create New Account Options section.

Step [4] – Go To Show VAT Number on Storefront : No Section, By Default No selected.

Once clicked on drop down, There are two options as Yes & No
select Yes

Show VAT Number on Storefront : Yes  

Step [5] – Go To Right Panel Name and Address Options

Once expand Show Tax / VAT Number

There are three option No, Optional, Required

Select Required

Click on Save Config button & run CLI command Flush

Finally, VAT / TAX displaying on Store front.

How To Get Base URL Magento 2.x Programmatically

There are following below steps need to follow to create Magento 2 custom module to get Base URL, Media URL, Link URL etc,

Step [1] – Create registration.php file under your module [ Namespace / ModuleName ]

File Path=app/code/Mage2db/John/registration.php

Add below content in this file.

<?php
\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    'Mage2db_John',
    __DIR__
);

Step [2] – Create module.xml file under your module [ Namespace / ModuleName ]

File Path=app/code/Mage2db/John/etc/module.xml

Add below content in this file.

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Mage2db_John" setup_version="1.0.0" />
</config>

Step [3] – Create routes.xml file under your module etc directory.

Add below content in this file.

File Path=app/code/Mage2db/John/etc/frontend/routes.xml

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../lib/internal/Magento/Framework/App/etc/routes.xsd">
   <router id="standard">
       <route id="john" frontName="john">
         <module name="Mage2db_John" />
       </route>
   </router>
</config>

Step [4] – Create Controller under your module.

Add below content in this file.

File Path=app/code/Mage2db/John/Controller/Index/Index.php

<?php
namespace Mage2db\John\Controller\Index;

use Magento\Backend\App\Action\Context;

class Index extends \Magento\Framework\App\Action\Action
{
	
    /**
     * @var \Magento\Framework\App\Cache\TypeListInterface
     */
    protected $_cacheTypeList;

    /**
     * @var \Magento\Framework\App\Cache\StateInterface
     */
    protected $_cacheState;

    /**
     * @var \Magento\Framework\App\Cache\Frontend\Pool
     */
    protected $_cacheFrontendPool;

    /**
     * @var \Magento\Framework\View\Result\PageFactory
     */
    protected $resultPageFactory;
	

    /**
     * @param Action\Context $context
     * @param \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList
     * @param \Magento\Framework\App\Cache\StateInterface $cacheState
     * @param \Magento\Framework\App\Cache\Frontend\Pool $cacheFrontendPool
     * @param \Magento\Framework\View\Result\PageFactory $resultPageFactory
     */
    public function __construct(
       \Magento\Framework\App\Action\Context $context,
        \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList,
        \Magento\Framework\App\Cache\StateInterface $cacheState,
        \Magento\Framework\App\Cache\Frontend\Pool $cacheFrontendPool,
        \Magento\Framework\Message\ManagerInterface $messageManager,
        \Magento\Framework\View\Result\PageFactory $resultPageFactory
				
    ) {
        parent::__construct($context);
        $this->_cacheTypeList = $cacheTypeList;
        $this->_cacheState = $cacheState;
        $this->_cacheFrontendPool = $cacheFrontendPool;
        $this->resultPageFactory = $resultPageFactory;
        $this->_messageManager = $messageManager;
				
     }
    
    /**
     * Flush cache storage
     *
     */
    public function execute()
    {
	    $this->resultPage = $this->resultPageFactory->create();  
        return $this->resultPage;
    }
}

Step [5] – Create Helper.php under your module.

Add below content in this file.

File Path=app/code/Mage2db/John/Helper/Data.php

<?php
namespace  Mage2db\John\Helper;
use Magento\Store\Model\StoreManagerInterface;

class Data extends \Magento\Framework\App\Helper\AbstractHelper
{
	protected $storeManager; 

	/**
     * @param \Magento\Framework\App\Helper\Context $context
     */
	public function __construct
	(
   \Magento\Framework\App\Helper\Context $context,   StoreManagerInterface $storeManager
	) 
	{
	    $this->storeManager = $storeManager;	
		parent::__construct($context);
	}
	  
	public function getStoreManagerData()
    {
          //return $storeUrl = $this->storeManager->getStore()->getBaseUrl();
         // get Store Url without index.php
        return $storeUrl = $this->storeManager->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_WEB);
           // get Link Url of store
          // $storeLinkUrl = $this->storeManager->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_DIRECT_LINK);
         // get media Base Url
        //  $storeMediaUrl = $this->storeManager->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA);
      // get Static content Url
      // $storeStaticUrl = $this->storeManager->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_STATIC);
    }
}

Step [6] – Create Block under your module.

Add below content in this file.

app/code/Mage2db/John/Block/Index/Index.php

<?php
namespace  Mage2db\John\Helper;
use Magento\Store\Model\StoreManagerInterface;

class Data extends \Magento\Framework\App\Helper\AbstractHelper
{
	protected $storeManager; 

	/**
     * @param \Magento\Framework\App\Helper\Context $context
     */
	public function __construct
	(
	 \Magento\Framework\App\Helper\Context $context, StoreManagerInterface $storeManager
	) 
	{
	    $this->storeManager = $storeManager;	
		parent::__construct($context);
	}
	  
	public function getStoreManagerData()
    {
          //return $storeUrl = $this->storeManager->getStore()->getBaseUrl();
         // get Store Url without index.php
        return $storeUrl = $this->storeManager->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_WEB);
           // get Link Url of store
          // $storeLinkUrl = $this->storeManager->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_DIRECT_LINK);
         // get media Base Url
        //  $storeMediaUrl = $this->storeManager->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA);
      // get Static content Url
      // $storeStaticUrl = $this->storeManager->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_STATIC);
    }
	  
}

Step [7] – Create view under your module.

under view folder create layout & template file

Layout File

app/code/Mage2db/John/view/frontend/layout/john_index_index.xml

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="2columns-left" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd">
 <body>		
   <referenceContainer name="main.content">			
<block class="Mage2db\John\Block\Index\Index" name="index_index" template="index/index.phtml"> </block>
  </referenceContainer>      
 </body>
</page>

Template File

app/code/Mage2db/John/view/frontend/templates/index/index.phtml

<?php

   //Template index phtml 
  echo"<BR> Base URL===".$baseurl= $block->getbaseurldata();
        
?>		

Step [8] – Finally your custom module for Base URL, Media URL, Link URL etc . has been created

Run the following below commands at your Magento 2 root directory

php bin/magento setup:upgrade
php bin/magento setup:static-content:deploy -f
php bin/magento indexer:reindex
php bin/magento cache:clean
php bin/magento cache:flush

Run below URL

https://mage2db.com/john/index/index

How To Disable One-Page Checkout in Magento 2.x

Magento 2 One-Page Checkout, all required checkout information will be put on a single page. When On-Page Checkout is enabled, the entire checkout process takes place on a single page. Each section of the checkout information is expanded as needed Accordingly, Shoppers won’t be directed to another page to complete their checkout process, It is much more time-saving than the normal checkout process.

On-Page Checkout is enabled by default, if the Store Owner wants to integrate another third party checkout extension, it is necessary to disable One-Page Checkout.

There are following below Admin setting required to disable One-Page Checkout

Step [1] – Go STORES > Configuration, redirects Configuration section.

Step [2] – Click on Left Panel Sales > Checkout

Step [3] – Once Right Panel (Checkout Options) expanded

Step [4] – Set Enable On-Page Checkout to No, after unchecked Use system value

How Many Product Types in Magento Open Source & Adobe Commerce 2.x

There are 7 Products Types in Magento 2

  1. Simple Product
  2. Configurable Product
  3. Grouped Product
  4. Bundle Product
  5. Virtual Product
  6. Downloadable Product
  7. Gift Card Product

[1] – Simple Product ::

The Simple Product is a physical item, most popular product type of a store, this product do not have attribute (selectable variations) as size, color, weight etc.
This product has a single SKU (Stock Keeping Unit)

[2] – Configurable Product ::

The configurable product is a combination of simple products, each simple product has its own attribute (size, color, weight etc) & SKU as well as own stock Inventory.

Example ::

Why Need Configurable Product

customers browse products in any store & getting multiple similar products, they will get annoyed & negatively rankings effect on search engine (Google, Yahoo, Bing etc.), that is why need to create configurable product.

Here Total products variations =12, if not creating configurable product, need to show 12 products on store, its not good presentation of products.

Total Simple Products Variations is 12 = One Configurable Product

[3] – Grouped Product ::

Grouped Product is a combination of multiple single(standalone) product, each product characteristics or are related to each other and presented on one page.

These single(standalone) product as Simple Product or Virtual Product or Downloadable Product etc.

These single(standalone) products are often related to each other and grouped by theme, season, or business purpose.

Each single product from Grouped Product can be purchased separately or group.

Example::

Customer can purchase grouped product Set of Sprite Yoga Traps

There are three set of Sprite Yoga Traps with various foot & prices

Customers can purchase any set of Sprite Yoga Traps as their need

[a] Sprite Yoga Traps 6 foot – 14.00 US$

[b] Sprite Yoga Traps 8 foot – 17.00 US$

[c] Sprite Yoga Traps 10 foot – 21.00 US$

Why Need Grouped Product

Customers can shop all their needed products at once instead of visiting separate product detail pages for shopping, This improve customers satisfaction and keep confident coming back to your store as well as Store business growth, That is why need to create Grouped Product

[4] – Bundle Product ::

Bundle Product is combination of various Simple products or Virtual Product and can be customized as per their need while shopping.

Magento 2, other product types have a button Add to cart in common, while in case bundle products have a different button named Customize and Add to Cart, This enables customers to customize the product using a list of options before adding to the cart.

Example ::

This bundled product Customize Spite Yoga Companion Kit appears with four individual items as

  • Sprite Stasis Ball
  • Sprite Foam Yoga Brick
  • Sprite Yoga Strap
  • Sprite Foam Roller.

Each product has several options for customers to select (product variations)

[5] – Virtual Product ::

Virtual Product do not have physical or digital entries. There are multiple products as non-tangible items such as memberships, services, warranties, or subscriptions and digital downloads of books, music, videos, OTT (Netflix, Amazon Prime Video) etc.. These products cannot be shipped or downloaded from the link. This is a great way to sell services or intellectual products such as warranties, subscription or updates.

Example ::

[6] – Downloadable Products ::

Downloadable Product have downloadable counterpart. There are multiple products as Software, eBooks, E-Learning, Fonts, Courses, Graphics & digital art, Video Game, MP3, MP4, Tickets etc. Downloadable product does not allow selecting a shipping method at checkout, simply because shipping is not needed and client receives purchased entity right away.

Example ::

[7] Gift Card (Adobe Commerce):: Gift Card products are applicable by Adobe Commerce.

“A Gift Card is a form of payment that can be used to do shopping at online stores or physical stores.”

Adobe Commerce 2.x supports three Gift Card

  1. Physical Gift Cards [Printed Gift Cards]:: [Printed Gift Cards] to be mailed(Posted) recipients street address or postal address or shipping address or physical mail not by Email ID
    Physical Gift Cards can be mass produced in advance and embossed with unique codes.
  2. Virtual Gift Cards:: A Virtual Gift Card has “No Stock Quantity” and is always “In Stock Quantity”. It is always required recipients Email ID.
  3. Combined Gift Card = It is combination of Physical Gift Card & Virtual Gift Card

Adobe Commerce 2.x allow 7 Type Products including Gift Card Products

Magento Open Source 2.x allow 6 Type Products

Difference Between Virtual and Downloadable Products

How To Set CSRF Token in Magento 2.x

There are following below Admin setting to do CSRF Token in Magento 2

Step [1] – Go To STORES > Configuration, redirects on configuration.

Step [2] – Left Panel Advanced -> Admin, redirects on [Right Panel]

Step [3] – Right Panel (Security) need to set as below

set Add Secret Key to URLs to Yes

Step [4] – Finally CSRF Token setting has been integrated.

Magento 2 CSRF Token Settings Video

HTTP Security Headers Checker Tool

https://www.site2info.com/sitesecurity.php

All Website HTTP Security Headers
Protect Website Against Vulnerability Attack, Hacker Attack, Virus Attack

Magento 2 All Database Tables [500 & more Tables]


HTTP Security Headers Checker Tool – Security Headers Response


How to add Feature-Policy Security Header


How to add X-Content-Type-Options Security Header


How to add Expect-CT Security Header


How to add X-Frame-Options Security Header


How to add X-XSS-Protection Security Header


How to add Referrer Policy Security Header


Referrer Policy Header Security


Magento 2 Admin Security


How to add HTTP Strict Transport Security (HSTS)


How To Set CSRF Token in Magento 2


What is CSRF and CSRF Token

What is CSRF and CSRF Token

Cross-site request forgery (CSRF or XSRF) , also know as One Click Attack, is a web security vulnerability that allows an Attacker / Hacker to attack on web application & to induce authenticated users to perform actions that they do not intend to perform. 

Cross Site Request Forgery = Cross Site + Request Forgery

Cross-Site Request Forgery Working Model

Attackers using multiple social engineering technique to attack by using CSRF or XSRF, This technique working as The victim into clicking a URL that having maliciously crafted or set of maliciously crafted , unauthorized request for a specific Web application, Then user’s browser sending this maliciously crafted or set of maliciously crafted request to a targeted Web application. The request also includes any credentials information to the particular website (user session or cookies). Id use as from of an active session with a targeted Web application, the application response this new request as an authorized request submitted by the authorized user.
Finally, The attacker successfully exploited the Web application infected with CSRF vulnerability.

There are multiple below cases, to attack CSRF

  • Submitting or deleting a record Form
  • Submitting a transaction Form
  • Purchasing a product Form
  • Changing a password Form
  • Sending a message Form
  • Contact Form

Application Prevent Against Cross-Site Request Forgery Attack

Preventing CSRF Attack, requires the inclusion of an unpredictable token in the body or URL of each HTTP request. Such tokens should at a minimum be unique per user session as well as be unique per request.

  • Properly validate submission form before the relevant action is executed
  • The preferred option is to include the unique token in a hidden field. The unique token can also be included in the URL itself, or a URL parameter.
  • Check Referrer field of each request.
  • Use Captcha on all critical page.

CSRF is a common form of attack and has ranked several times in the OWASP Top Ten (Open Web Application Security Project).

Magento 2 CSRF Token Settings Video

HTTP Security Headers Checker Tool

https://www.site2info.com/sitesecurity.php

All Website HTTP Security Headers
To Protect Website Against Vulnerability Attack, Hacker Attack, Virus Attack

Magento 2 All Database Tables [500 & more Tables]


HTTP Security Headers Checker Tool – Security Headers Response


How to add Feature-Policy Security Header


How to add X-Content-Type-Options Security Header


How to add Expect-CT Security Header


How to add X-Frame-Options Security Header


How to add X-XSS-Protection Security Header


How to add Referrer Policy Security Header


Referrer Policy Header Security


Magento 2 Admin Security


How to add HTTP Strict Transport Security (HSTS)


How To Set CSRF Token in Magento 2


What is CSRF and CSRF Token

Why Magento 2.s Prohibited The Direct Use of The ObjectManager

Magento 2 prohibits the direct use of the ObjectManager in code because it hides the real dependencies of a class

Magento 2.x Coding Standard Rules / Regulations

The main reason, the Object Manager directly is that direct use of the Object Manager causes the extension not to be installable in compiled production mode.

Never call the object manager directly because the Magento 2 Framework handles this automatically

By 2017, The Magento 2 Marketplace runs a compile and install test on all extensions by using properly Magento 2 Coding Standard. If your extension uses the Object Manager directly, it will fail these tests and be rejected from the Marketplace until you resolve this problem and reupload.

How To Setup Magento 2.x Coding Standard

How To Create a Custom Log File in Magento 2.x

Magento 2 Logs having ecommerce store information records for the analysis purpose, as each functionality of ecommerce store either working fine or not, Its both status store in log files One of the most common examples of such events is the error log.
Logs file store path

Magento 2 Root Directory /Var/log/

log folder contains the common log files as below

  1. system logs — [Magento2 Root//Var/log/system.log]
  2. exception log — [Magento2 Root//Var/log/exception.log]
  3. debug logs — [Magento2 Root//Var/log/debug.log]
  4. connector logs — [Magento2 Root//Var/log/connector.log]
  5. install logs — [Magento2 Root//Var/log/install.log]

How To Create Custom Log File in Magento 2

There are following below steps need to follow to create Magento 2 custom log file.

Step [1] – Create registration.php file under your module [ Namespace / ModuleName ]

File Path=Mage2db/John/registration.php

Add below content in this file.

<?php
\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    'Mage2db_John',
    __DIR__
);

Step [2] – Create module.xml file under your module [ Namespace / ModuleName ]

File Path=Mage2db/John/etc/module.xml

Add below content in this file.

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Mage2db_John" setup_version="1.0.0" />
</config>

Step [3] – Create routes.xml file under your module etc directory. Add below content in this file.

File Path=Mage2db\John\etc\frontend\routes.xml

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../lib/internal/Magento/Framework/App/etc/routes.xsd">
   <router id="standard">
       <route id="john" frontName="john">
         <module name="Mage2db_John" />
       </route>
   </router>
</config>

Step [4] – Create di.xml file under your module etc directory. Add below content in this file.File Path=Mage2db\John\etc\di.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd">
    <type name="Mage2db\John\Logger\Handler">
        <arguments>
            <argument name="filesystem" xsi:type="object">Magento\Framework\Filesystem\Driver\File</argument>
        </arguments>
    </type>
    <type name="Mage2db\John\Logger\Logger">
        <arguments>
            <argument name="name" xsi:type="string">John</argument>
            <argument name="handlers" xsi:type="array">
                <item name="system" xsi:type="object">Mage2db\John\Logger\Handler</item>
            </argument>
        </arguments>
    </type>
</config>

Step [5] – Create Handler.php file under your module Logger directory. Here, Custom Log File path store.

Add below content in this file.

File Path=Mage2db\John\Logger\Handler.php

<?php
namespace Mage2db\John\Logger;
 
use Monolog\Logger;
 
class Handler extends \Magento\Framework\Logger\Handler\Base
{
    protected $loggerType = Logger::INFO;
 
    protected $fileName = '/var/log/mage2db_john_log_file.log';
}

Step [6] – Create Logger.php file under your module Logger directory. Add below content in this file.

File Path=Mage2db\John\Logger\Logger.php

<?php
namespace Mage2db\John\Logger;
 
class Logger extends \Monolog\Logger
{
}

Step [7] – Create Controller Index.php file under your module Controller Index directory, where custom logger costructor defined.

Here we have defined custom message to store Custom Log File.

Add below content in this file.

File Path=Mage2db/John/Controller/Index/Index.php

<?php
namespace Mage2db\John\Controller\Index;

use Magento\Backend\App\Action\Context;
use \Magento\Framework\Controller\ResultFactory;


class Index extends \Magento\Framework\App\Action\Action
{
	
    /**
     * @var \Magento\Framework\App\Cache\TypeListInterface
     */
    protected $_cacheTypeList;

    /**
     * @var \Magento\Framework\App\Cache\StateInterface
     */
    protected $_cacheState;

    /**
     * @var \Magento\Framework\App\Cache\Frontend\Pool
     */
    protected $_cacheFrontendPool;

    /**
     * @var \Magento\Framework\View\Result\PageFactory
     */
    protected $resultPageFactory;
	
    /**
     * Logging instance
     * @var \Mage2db\John\Logger\Logger
     */
    protected $_logger;
	
	
 /**
  * @param Action\Context $context
  * @param \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList
  * @param \Magento\Framework\App\Cache\StateInterface $cacheState
  * @param \Magento\Framework\App\Cache\Frontend\Pool $cacheFrontendPool
  * @param \Magento\Framework\View\Result\PageFactory $resultPageFactory
  **/
    public function __construct(
       \Magento\Framework\App\Action\Context $context,
        \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList,
        \Magento\Framework\App\Cache\StateInterface $cacheState,
        \Magento\Framework\App\Cache\Frontend\Pool $cacheFrontendPool,
        \Magento\Framework\Message\ManagerInterface $messageManager,
        \Magento\Framework\View\Result\PageFactory $resultPageFactory,
	\Mage2db\John\Logger\Logger $logger
		
    ) {
        parent::__construct($context);
        $this->_cacheTypeList = $cacheTypeList;
        $this->_cacheState = $cacheState;
        $this->_cacheFrontendPool = $cacheFrontendPool;
        $this->resultPageFactory = $resultPageFactory;
        $this->_messageManager = $messageManager;
	$this->_logger = $logger;
				
     }
    
    /**
     * Flush cache storage
     *
     */
    public function execute()
    {
		
$this->_logger->info("Mage2db.com created  custom module for Custom Log");
		
$this->resultPage = $this->resultPageFactory->create();  
        return $this->resultPage;
    }
}

Step [8] – Finally your custom Log with custom module has been created

Run the following below commands at your Magento 2 root directory

php bin/magento setup:upgrade
php bin/magento setup:static-content:deploy -f
php bin/magento indexer:reindex
php bin/magento cache:clean
php bin/magento cache:flush

Run below URL

https://mage2db.com/john/index/index

Change https://mage2db.com to your Base URL, Output as below

Custom Log File store path

Magento 2 Root Directory / var / log / mage2db_john_log_file.txt

[2021-12-07 19:59:58] John.INFO: Mage2db.com created  custom module for Custom Log [] []