Our Work

Pimpmylogs Magento

Updated 1 year, 2 months and 8 days ago

Developers need to check logs regularly to debug anything in your Staging or Production Magento ecommerce System. Pimpmylog is good application which makes easier to give access to developers these logs. We have extended this application for Magento for the following:

  • Nginx/Apache logs
  • mysql logs
  • Magento debugging  log
  • Magento Reports
  • Magento System Log and Exception Logs
  • Any other log files from a Specific folder related to custom plugin
  • For Displaying logs on the Browser
  • Added ability to add Complete folder, specific files which matches a specific string
  • We Can add Different format for Different logs using REGX
  • Configured for Display Based on dates.

How to Configure a new Folder in logs.

In config.user.php  file we need to add a new entry in $directories  array.

 Example : 

$directories = array(
'Magento Logs'=>array('match'=>'.log','directory'=>'/var/www/devzeb/var/log/','format'=>'magento'),
);
Now I am adding Magento reports to the logs section. After adding Reports It should be like below.
$directories = array(
'Magento Logs'=>array('match'=>'.log','directory'=>'/var/www/devzeb/var/log/','format'=>'magento'),
'Magento Reports'=>array('match'=>'','directory'=>'/var/www/devzeb/var/report/','format'=>'general')
);

Here 

  • 'Magento Reports'  is the Name which we want to display in frontend dropdown menu.
  • 'directory' Key contains the full path of the directory which we want to Display.
  • 'match' Key contains the string value. It only display the files in logs which are matching the specified String. Empty for matching all the files
  • 'format' Key contains which format the logs should display. By default it will display as it is in file. We can change the format using regx like below
$magentoLogFormat = array (
'type'=> 'PHP',
'regex' => '@^(.*)\-(.*)\-(.*)T(.*)\:(.*)\:(.*)\+(.*)\:(.*)\ (.*)\ \((.*)\)\:\ (((.*) in (.*) on line (.*))|(.*))$@U',
'match' => array (
'Date' => array (
0 => 3,
1 => '-',
2 => 2,
3 => '-',
4 => 1,
5 => ' ',
6 => 4,
7 => ':',
8 => 5,
9 => ':',
10 => 6,
),
'Severity' => 9,
'Error' =>array (
0 => 12,
1 => 13,
),
'File' => 14,
'Line' => 15,
),
'types' => array (
'Date' => 'date:d-m-Y H:i:s',
'Severity' => 'badge:severity',
'File' => 'pre:/-69',
'Line' => 'numeral',
'Error' => 'pre',
),
'exclude' =>
array ('Log' =>
array (
0 => '\/PHP Stack trace:\/',
1 => '\/PHP *[0-9]*\. \/',
),
),
);

Here 'match' array will prepare the format for the Columns using the 'regx' specified above  and will display in the format specified in 'types' key.

Changes Which we have Made for Changing the Menu format and Dynamic files:

  • Removed the Json files Structure and preparing the files list using PHP. 
  • Reading dynamic directories with matching criteria for preparing files list.
  • Based on the Configured tag Logs will display under the Mennu option. Here we want to display it as Date based so Configured main_tag and sub_tag,  where main tag is the Main menu item and Sub tag is the Date of the log.  Using this we are grouping logs based on dates.

Files modified : 

config.user.php

Provided Configuration for adding dynamic paths, different format  and matching criteria

index.php

around 243 line added below code

if(is_array($file_id)){
     $logfiles = array_filter($file_id);
     $tagged .= '<li class="tag-' . get_slug( $tag2 ) . '"><a href="#">' . h( $tag2 );
if ( TAG_DISPLAY_LOG_FILES_COUNT === true ) 
$tagged .= ' <small class="text-muted">(' . count( $logfiles ) . ')</small>';
$tagged .=         '<ul class="dropdown-menu">';
foreach($logfiles as $logfile) {
if(!$logfile) { continue; }
$selected = ( ( isset( $_GET['i'] ) ) && ( $_GET['i'] === $logfile ) ) ? ' active' : '';
$tagged  .= '<li id="file_' . $logfile . '" data-file="' . $logfile . '" class="file_menup' . $selected . '"><a class="file_menu" href="#" title="';
$tagged  .= ( isset( $files[ $logfile ]['included_from'] ) ) ? h( sprintf( __('Log file #%s defined in %s' ) , $logfile , $files[ $logfile ]['included_from'] ) ) : h( sprintf( __( 'Log file #%s defined in main configuration file' ) , $logfile ) );
$tagged  .= '">' . $files[ $logfile ]['display'] . '</a></li>';
}
$tagged .= '</ul>';
$tagged .= '</li>';
}
else
{
    $selected = ( ( isset( $_GET['i'] ) ) && ( $_GET['i'] === $file_id ) ) ? ' active' : '';
    $tagged  .= '<li id="file_' . $file_id . '" data-file="' . $file_id . '" class="file_menup' . $selected . '"><a class="file_menu" href="#" title="';
    $tagged  .= ( isset( $files[ $file_id ]['included_from'] ) ) ? h( sprintf( __('Log file #%s defined in %s' ) , $file_id , $files[ $file_id ]['included_from'] ) ) : h( sprintf( __( 'Log file #%s defined in main configuration file' ) , $file_id ) );
     $tagged  .= '">' . $files[ $file_id ]['display'] . '</a></li>';
}

inc/global.inc.php

Changed in the config_extract_tags() method

if( is_array($tag)) {
$tags[ strval( $tag['main_tag'] ) ][$tag['sub_tag']][] = $fileid;
}
else {
$tags[ strval( $tag ) ][] = $fileid;
}

Screenshots : 

 

For downloading please visit the link: https://github.com/KtreeOpenSource/PimpMyLog-Magento

 

Related Posts