Skip to content

Commit

Permalink
Fixed logging tables
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Hachmang committed Apr 24, 2014
1 parent 404fe1c commit 2235745
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 22 deletions.
34 changes: 21 additions & 13 deletions app/code/community/Ho/Import/Helper/Log.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ class Ho_Import_Helper_Log extends Mage_Core_Helper_Abstract

protected $_logEntries = array();

function __construct() {
mb_internal_encoding('UTF-8');
}

public function setMinLogLevel($level) {
if (! is_numeric($level)) {
Mage::throwException($this->__('The min log level should be numeric, %s given', $level));
Expand Down Expand Up @@ -143,12 +147,12 @@ protected function _renderCliTable($arrays, $level = Zend_Log::INFO) {
$columns[$col] = 0;
}

if (strlen($col) > $columns[$col]) {
$columns[$col] = strlen($col);
if (mb_strlen($col) > $columns[$col]) {
$columns[$col] = mb_strlen($col);
}

if (strlen($value) > $columns[$col]) {
$columns[$col] = strlen($value);
if (mb_strlen($value) > $columns[$col]) {
$columns[$col] = mb_strlen($value);
}
}
}
Expand All @@ -163,27 +167,27 @@ protected function _renderCliTable($arrays, $level = Zend_Log::INFO) {

$lines = "\n";

$line = '| '.str_pad('key', $columns[0]).' |';
$lineTwo = '+-'.str_pad('-', $columns[0], '-').'-+';
$line = '| '.$this->_mb_str_pad('key', $columns[0]).' |';
$lineTwo = '+-'.$this->_mb_str_pad('-', $columns[0], '-').'-+';
$i = 0;
array_shift($arrays);
foreach($arrays as $key => $array) {
$i++;

$search = preg_match_all('/__.*?__/', $key, $matches);
if ($search) {
$str = str_pad($key, $columns[$i]);
$str = $this->_mb_str_pad($key, $columns[$i]);
foreach ($matches[0] as $match) {
$str = str_replace($match, "\033[31m".str_replace('__','', $match).$this->_getCliColor($level), $str);
}
$padding = count($matches[0]) * 4;
$str = str_pad($str, strlen($str) + $padding);
$str = $this->_mb_str_pad($str, mb_strlen($str) + $padding);
} else {
$str = str_pad($key, $columns[$i]);
$str = $this->_mb_str_pad($key, $columns[$i]);
}
$line .= ' '.$str.' |';

$lineTwo.= '-'.str_pad('-', $columns[$i], '-').'-+';
$lineTwo.= '-'.$this->_mb_str_pad('-', $columns[$i], '-').'-+';
}
$lines.= $lineTwo . "\n";
$lines.= $line . "\n";
Expand All @@ -197,14 +201,14 @@ protected function _renderCliTable($arrays, $level = Zend_Log::INFO) {
$search = preg_match_all('/__.*?__/', $row[$column], $matches);

if ($search) {
$str = str_pad($row[$column], $length);
$str = $this->_mb_str_pad($row[$column], $length);
foreach ($matches[0] as $match) {
$str = str_replace($match, "\033[31m".str_replace('__','', $match).$this->_getCliColor($level), $str);
}
$padding = count($matches[0]) * 4;
$str = str_pad($str, strlen($str) + $padding);
$str = $this->_mb_str_pad($str, mb_strlen($str) + $padding);
} else {
$str = str_pad($row[$column], $length);
$str = $this->_mb_str_pad($row[$column], $length);
}

$line .= ' '.$str.' |';
Expand All @@ -217,6 +221,10 @@ protected function _renderCliTable($arrays, $level = Zend_Log::INFO) {
return $lines;
}

protected function _mb_str_pad( $input, $pad_length, $pad_string = ' ', $pad_type = STR_PAD_RIGHT) {
$diff = strlen($input) - mb_strlen($input);
return str_pad($input, $pad_length + $diff, $pad_string, $pad_type);
}

/**
* When logging to the admin notification inbox.
Expand Down
9 changes: 0 additions & 9 deletions app/code/community/Ho/Import/Model/Import.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,6 @@ public function mapLines($lines)
$errors[$e->getMessage()] = $lines;
}
foreach ($errors as $error => $lines) {
if (strlen($error) > 80) {
$error = substr($error, 0, 77) . ' ..';
}

foreach ($lines as $line) {
$key = $line - 1;
if (isset($entityMap[$key])) {
Expand Down Expand Up @@ -718,11 +714,6 @@ protected function _debugErrors($errors)
$errorLines = array();
$errorsPerLine = array();
foreach ($errors as $error => $lines) {

if (strlen($error) > 80) {
$error = substr($error, 0, 77) . ' ..';
}

$errorLines = array_merge($errorLines, $lines);
foreach ($lines as $line) {

Expand Down

0 comments on commit 2235745

Please sign in to comment.