Sunday, February 5, 2023
  • Home
  • About Us
  • Disclaimer
  • Contact Us
  • Terms & Conditions
  • Privacy Policy
T3llam
  • Home
  • App
  • Mobile
    • IOS
  • Gaming
  • Computing
  • Tech
  • Services & Software
  • Home entertainment
No Result
View All Result
T3llam
  • Home
  • App
  • Mobile
    • IOS
  • Gaming
  • Computing
  • Tech
  • Services & Software
  • Home entertainment
No Result
View All Result
T3llam
No Result
View All Result
Home Services & Software

PrestaShop FileLogger for writing module logs

September 26, 2022
in Services & Software
0
PrestaShop FileLogger for writing module logs
0
SHARES
0
VIEWS
Share on FacebookShare on Twitter

You might also like

Selling privateness for camera-based assistive tech

Distinction between APC and MPC

Learn how to Create a Dynamic Java Net Utility


It’s a recognized greatest follow to maintain logs for crucial processes in order that at any time when a failure happens, we are able to verify logs and discover the explanation of the failure. PrestaShop has its personal FileLogger system that we are able to reuse to generate logs in module. Right here we’ll focus on learn how to generate module logs with varied severity ranges and creating report by parsing the log file.

Generate logs with PrestaShop FileLogger

Let’s dive in immediately on learn how to use FileLogger in module, then we’ll focus on every level afterwards.

// Create an object of PrestaShop FileLogger
$logger = new FileLogger();

// Present file path to write down logs
$filePath = _PS_MODULE_DIR_.'myexamplemodule/log/course of.log';
$logger->setFilename($filePath);
$logger->logDebug('Beginning instance logger course of.');
attempt {
    $warning = false;
    /**
     * Your course of code right here, set warning if any
     */
    if ($warning) {
        // Log warning message to file
        $logger->logWarning($warning);
    } else {
        // Log a hit message to file
        $logger->logInfo('The method was accomplished with out error.');
    }
} catch (Exception $e) {
    // Log error message to file
    $logger->logError('Exception: '.$e->getMessage());
}

Lets perceive above code line by line:

  • Create a FileLogger object: The FileLogger class is already loaded in PrestaShop atmosphere, so you may immediately use it with out together with its file or class in module.
  • Present a file path for logs: We have to present a file path during which FileLogger writes the logs. FileLogger will create the file if not exists. Nonetheless, the folder should exist with writable permissions.
  • Creating logs: We are able to generate 4 varieties (severity) of log messages : DEBUG, WARNING, INFO and ERROR.
    • logDebug: This technique writes DEBUG kind log. This sort of logs are simply data in between the method. Instance:
      • “*DEBUG* 2022/09/22 – 12:10:49: Beginning instance logger course of.”
    • logWarning: This writes the given warning message to log file, instance:
      • “*WARNING* 2022/09/22 – 12:10:49: This can be a warning message”
    • logInfo: This technique writes informative (like a hit data) messages to log file. Instance:
      • “*INFO* 2022/09/22 – 12:10:49: The method was accomplished with out error.”
    • logError: That is used to write down error degree logs to file. Instance:
      • “*ERROR* 2022/09/22 – 12:10:49: Exception: that is an exception message”

The log file seems like this after writing logs:

image-271

Parse log file to generate report:

Since FileLogger makes use of a constant format for every log line, due to this fact we are able to parse the log file and generate a log report in type of a array additionally. The best means to do that is to separate every line and extract needed data. For instance:

Trying to find an skilled
Prestashop Firm ?
Learn Extra


$filePath = _PS_MODULE_DIR_.'myexamplemodule/log/course of.log';
$logDetail = file($filePath);
if ($logDetail) {
    $logArray = array();
    foreach ($logDetail as $knowledge) {
        $logParts = explode(": ", $knowledge);
        $logDateTime = explode("* ", $logParts[0]);
        $message = $logParts[1];
        $logArray[] = array(
            'standing' => Instruments::substr($logDateTime[0], 1),// INFO, ERROR and so forth
            'date' => trim($logDateTime[1]),
            'msg' => trim($message),
        );
    }
    return $logArray;
}

The above code will give us the log particulars in following format:

PrestaShop FileLogger report

That’s all about learn how to use PrestaShop FileLogger to generate logs. If any challenge or doubt within the above course of, please be happy to tell us within the remark part.

I’d be completely satisfied to assist.

Additionally, you may discover our PrestaShop Improvement Companies and a wide variety of high quality PrestaShop Modules.

For any doubt contact us at [email protected].

author-thumb


Ram Chandra
4 Badges

22 September 2022
Previous Post

Here is How To Pair Your Nintendo Change Pleasure-Cons To Your iPhone On iOS 16

Next Post

Flipkart Large Billion Days 2022 Sale: Greatest Smartphone Gives

Related Posts

Selling privateness for camera-based assistive tech
Services & Software

Selling privateness for camera-based assistive tech

by admin
February 5, 2023
Most attainable measurement of subset following the given constraints
Services & Software

Distinction between APC and MPC

by admin
February 5, 2023
Working with Java Variables | Developer.com
Services & Software

Learn how to Create a Dynamic Java Net Utility

by admin
February 5, 2023
Sonatype’s OSS safety choices can now be deployed within the cloud
Services & Software

Sonatype’s OSS safety choices can now be deployed within the cloud

by admin
February 5, 2023
Information Mesh Speed up Workshop
Services & Software

Information Mesh Speed up Workshop

by admin
February 4, 2023
Next Post
Flipkart Large Billion Days Sale 2022 Witnesses Over 1.5 Million Customers per Second on Day 1

Flipkart Large Billion Days 2022 Sale: Greatest Smartphone Gives

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recommended

Inject a International with Internet Extensions in Manifest V3

Decide Default App for File Kind from Command Line

October 3, 2022
What’s Samsung GIF Remaster? New AI instrument you did not know you wanted defined

What’s Samsung GIF Remaster? New AI instrument you did not know you wanted defined

February 2, 2023

Don't miss it

Netflix says it is open to including free streaming ‘FAST’ channels to develop its advertisements enterprise • TechCrunch
Mobile

Netflix crackdown, monetizing ChatGPT and bypassing FB’s 2FA • TechCrunch

February 5, 2023
Selling privateness for camera-based assistive tech
Services & Software

Selling privateness for camera-based assistive tech

February 5, 2023
Elon Musk and Tesla discovered not liable in lawsuit over “funding secured” tweet
Tech

Elon Musk and Tesla discovered not liable in lawsuit over “funding secured” tweet

February 5, 2023
Disney Dreamlight Valley: The place To Get Dry Wooden
Gaming

Disney Dreamlight Valley: The place To Get Dry Wooden

February 5, 2023
Infinix Zero 5G 2023, Infinix Zero 5G 2023 Turbo With MediaTek Dimensity SoCs, 120Hz Shows Launched in India: Worth, Specs
Mobile

Infinix Zero 5G 2023, Infinix Zero 5G 2023 Turbo With MediaTek Dimensity SoCs, 120Hz Shows Launched in India: Worth, Specs

February 5, 2023
Samsung Galaxy S23 Specs vs. Google Pixel 7: Android Telephones In contrast
Mobile

Samsung Galaxy S23 vs. Google Pixel 7: Which Android Telephone Is Higher?

February 5, 2023
T3llam

© 2022 Copyright by T3llam.

Navigate Site

  • Home
  • About Us
  • Disclaimer
  • Contact Us
  • Terms & Conditions
  • Privacy Policy

Follow Us

No Result
View All Result
  • Home
  • App
  • Mobile
    • IOS
  • Gaming
  • Computing
  • Tech
  • Services & Software
  • Home entertainment

© 2022 Copyright by T3llam.

What are cookies
We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept All”, you consent to the use of ALL the cookies. However, you may visit "Cookie Settings" to provide a controlled consent.
Cookie SettingsAccept All
Manage consent

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.
CookieDurationDescription
cookielawinfo-checkbox-analytics11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checkbox-functional11 monthsThe cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
cookielawinfo-checkbox-necessary11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-others11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
cookielawinfo-checkbox-performance11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
viewed_cookie_policy11 monthsThe cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.
Functional
Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.
Performance
Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.
Analytics
Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.
Advertisement
Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.
Others
Other uncategorized cookies are those that are being analyzed and have not been classified into a category as yet.
SAVE & ACCEPT