Giter Site home page Giter Site logo

magento2-customlog's Introduction

Custom Log File

While you develop a Magento 2 website, it's very important to create the log text to monitor the errors and system information.

By default in Magento 2, you can use the class Psr\Log\LoggerInterface to create the log text, it will be saved in the system.log file. However, it is difficult to open or read this file when the file size is large because it saves all the log text of a Magento 2 website.

It is easier if you create a new custom log file and save the log text for each your task.

So drari, I am going to create a new custom log file having the format customer-Y-m-d.log, with the "Y-m-d" will be the date of the log text saved. Every when the customer logs in I will save the customer information in this log file.

This is just a example, You can inject the custom log in your catch treatment (I mean when catched you will save errors in a text file..)

To test this module :

  • Create the namespace PHPAISS in the path app\code
  • Create the module named CustomLog in the path app\code\PHPAISS
  • Clone this files and put them into folder app\code\PHPAISS\CustomLog
  • Run the following command lines:
    bin/magento setup:upgrade --keep-generated
    bin/magento cache:flush
  • Go to the storefront, the customer tries to log in
  • Go to folder var/ and see the file customer-Y-m-d.log

In the file app\code\PHPAISS\CustomLog\Observer\CustomerLoginSuccess.php at line 40 :
$this->loggerCustomer->info('Customer ID: '.$customer->getId().' has been logged in successfully!');

There are other functions like warning() error()...
You can see the file \Monolog\Logger and read the comments.

Don't forget to star and share the repository with your friends.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.