Easily add logs anywhere in your Magento 2 code

Overview

Magento 2 Simple Log

Easily add logs anywhere in the code (like Magento 1).

Requirements

Requires Magento 2 in any version.

Installation

Add the Log.php file in theapp/code directory.

Description

\Log::add(
    mixed $message,
    int $level = 6,
    ?string $fileName = null
)

Parameters

  • message: the data to log (any type)
  • level: the error level from 0 to 7
  • fileName: the log file name in the var/log directory, app.log if null

Return Values

The method returns the number of bytes that were written to the log file (0 on failure).

Examples

\Log::add('Hello World!');

\Log::add('Panic!', \Log::ERR);

\Log::add([1, 2, 3], \Log::DEBUG);

try {
    throw new \Exception('Error message');
} catch (\Exception $exception) {
    \Log::add($exception, \Log::ERR);
}

\Log::add('This is a debug', \Log::DEBUG, 'custom_debug.log');

Results

app.log

2021-10-07 14:55:01 | INFO       | Hello World!
2021-10-07 14:55:02 | ERROR      | Panic!
2021-10-07 14:55:03 | DEBUG      | Array
(
    [0] => 1
    [1] => 2
    [2] => 3
)
2021-10-07 14:36:05 | ERROR       | Error message
#0 /var/www/magento2/pub/index.php(35): Magento\Framework\App\Bootstrap->run()
#1 {main}

custom_debug.log

2021-10-07 14:55:04 | DEBUG      | This is a debug
You might also like...
A tool that allows to quickly export data from Magento 1 and Magento 2 store and import it back into Magento 2

Simple Import / Export tool A tool that allows to quickly export data from Magento 1 and Magento 2 store and import it back into Magento 2. Table data

[ONLY Magento 2.0.x Compatible] Code samples for Magento developers

Synopsis This project is a collection of samples to demonstrate technologies introduced in Magento 2. You will find the most simple extension along wi

Quickly and easily preview and test your Magento 2 order confirmation page, without hacks or spending time placing new order each time
Quickly and easily preview and test your Magento 2 order confirmation page, without hacks or spending time placing new order each time

Preview Order Confirmation Page for Magento 2 For Magento 2.0.x, 2.1.x, 2.2.x and 2.3.x Styling and testing Magento's order confirmation page can be a

Preload your sweet sweet code to opcache with a composer command, making your code faster to run.

Composer Preload Preload your sweet sweet code to opcache with a composer command, making your code run faster. Composer Preload is a composer plugin

The package provides the ability to write logs into the database synchronously or asynchronously, along with other logging channels.

Laravel database log channel The package provides the ability to write logs into the database synchronously or asynchronously, along with other loggin

Tango is a command-line tool for analyzing access logs 💃
Tango is a command-line tool for analyzing access logs 💃

Tango Tool to get insights from the server access logs Tango is a dependency-free command-line tool for analyzing access logs 💃 Currently, work on th

Provides the ability to notify developers of error logs via email or SMS.

🔔 Dev Notify Plugin 🚨 Requires OctoberCMS 2.0 ✨ What does this plugin do? Provides the ability to notify developers of error logs via email or SMS.

Unterstützung bei der DSGVO-konformen Umsetzung von ein oder mehreren REDAXO-Websites, indem Logs und Daten nach festgelegten Regeln gelöscht werden.
Unterstützung bei der DSGVO-konformen Umsetzung von ein oder mehreren REDAXO-Websites, indem Logs und Daten nach festgelegten Regeln gelöscht werden.

Auto-Delete-Addon für REDAXO 5.x Löscht alte Logs und Datensätze via Cronjob. Features YForm-Feld datestamp_auto_delete Ein Feld für YForm, das wie da

Add the W3C payment request on Magento 2
Add the W3C payment request on Magento 2

Payment Request API for Magento 2 About This Magento Extension will allow you to use the W3C's payment request api for checkout in Magento 2. The Paym

Owner
Matthieu Vion
Matthieu Vion
EBook-Apps - The eBook Apps is a web application that helps you browse ebooks from anywhere using your smartphone and laptop.

⚡️ eBook Apps The eBook Apps is a web application that helps you browse ebooks from anywhere using your smartphone and laptop. ?? Getting Started To s

Ahmad Fauzy 32 Nov 14, 2022
Quickly execute Composer package binaries from anywhere. ⚡️

✨ Help support the maintenance of this package by sponsoring me. cpx Quickly execute Composer package binaries from anywhere. ⚡️ Installation Run the

Ryan Chandler 57 Dec 25, 2022
Xero - a digital currency that allows instant payments to anyone, anywhere

Xeros is a digital currency that allows instant payments to anyone, anywhere. Xeros has been written completely in PHP and mostly follows the technical design of Bitcoin. Xeros uses P2P technology to operate with no central server.

Kladskull 79 Dec 26, 2022
Easily add sub domains to your CakePHP application using route prefixes

Easily add sub domains to your CakePHP application using route prefixes. Based on code created by chinpei215.

multidimension.al 4 Feb 28, 2019
Testing your OpenApi documentation and your code easily.

Raven - How to test your API documentation and behavior. This library was written to allow testing OpenAPI documentation easily. It also allows verify

CH Studio 30 Dec 6, 2022
❄️ Magento 2 Snowflake module allow you to add snow and even more on your site and make winter fun.

❄️ Magento 2 Snowflake module allow you to add snow and even more on your site and make winter fun.

OpenGento 6 Apr 30, 2022
Simple user settings facade for Hyperf. Settings are stored as JSON in a single database column, so you can easily add it to an existing table.

hyperf-user-settings Simple user settings util for hyperf Settings are stored as JSON in a single database column, so you can easily add it to an exis

lysice 1 Oct 15, 2021