magezone/magento2-logviewer

A Magento 2 module with Tracy debug, custom logger, and log view UI

Installs: 6

Dependents: 0

Suggesters: 0

Security: 0

Type:magento2-module

0.1.0 2018-05-29 11:36 UTC

This package is not auto-updated.

Last update: 2024-09-20 03:30:38 UTC


README

Data in log file can be saved in table format. In Magento admin you can assign formatters to table columns:

  1. Go to System > Tools > Log Viewer
  2. On the top of the page click on Manage column formatters
  3. Click on Add New Column Formatter

Form description:

  • Index: number coresponding to the array index of data when creating new log entry.
  • Name: heading for log column on this index.
  • Log File: log file path relative to var/log for which column formatter applies.
  • Formatter Class: Class used to format this column.

Formatter Classes:

  • StringData: Data is converted to string.
  • ExceptionData: Data must implement \Throwable interface. Saves Tracy bluescreen for Exception.
  • StructuredData: Object or array. It is saved in in browserable format.

Using custom logger

You need to add LogViewer Logger to dependancy injection, for example:

public function __construct(
	...
	\Magezone\LogViewer\Logger\Logger $logger
	...
)
...

Logged data must be an array. Each array value corresponds to one column in log view. If column formatter for selected log file and column index is not specified, StringData formatter is used. Number of array values must be constant for a log file. Logging levels are same as in default Monolog logger.

Exception logging example:

...
catch (\Throwable $e) {
	// in Magento admin, there is ExceptionData column formatter for file test.log and index 2
	$this->logger->warning('test.log', ['test log data', 'second column', $e]); 
}
...

Structured data example:

...
// in Magento admin, there is StructuredData column formatter for file test2.log and index 1
$data = ['person' => ['name' => 'Mikhael', 'age' => 24]];
$this->logger->debug('test2.log', ['some column', $data, 'other column']);
...