| 1 |
<?php |
| 2 |
|
| 3 |
class Mbe_Shipping_Helper_Logger |
| 4 |
{ |
| 5 |
public static $log = true; |
| 6 |
|
| 7 |
private $helper; |
| 8 |
private $pluginVersionMessage; |
| 9 |
|
| 10 |
public function __construct() |
| 11 |
{ |
| 12 |
$this->helper = new Mbe_Shipping_Helper_Data(); |
| 13 |
$this->pluginVersionMessage = MBE_ESHIP_PLUGIN_NAME.' version ' . MBE_ESHIP_PLUGIN_VERSION . ' :'; |
| 14 |
} |
| 15 |
|
| 16 |
public function log($message, $force = false) |
| 17 |
{ |
| 18 |
if ($this->helper->debug() || $force) { |
| 19 |
|
| 20 |
|
| 21 |
$logDirPath = $this->helper->getMbeLogDir(); // returns the path checking if it exists and if it's missing it creates it |
| 22 |
|
| 23 |
// if the directory already exists but the permissions are wrongs, changes it |
| 24 |
if(file_exists($logDirPath) && substr(sprintf('%o', fileperms($logDirPath)), -4)<>0755 ) { |
| 25 |
chmod( $logDirPath, 0755 ); |
| 26 |
} |
| 27 |
|
| 28 |
// if(substr(sprintf('%o', fileperms(MBE_ESHIP_PLUGIN_LOG_DIR)), -4)<>0755 ) { |
| 29 |
// chmod( MBE_ESHIP_PLUGIN_LOG_DIR, 0755 ); |
| 30 |
// } |
| 31 |
// |
| 32 |
// if (!file_exists(MBE_ESHIP_PLUGIN_LOG_DIR ) ) { |
| 33 |
// mkdir(MBE_ESHIP_PLUGIN_LOG_DIR , 0755, true); |
| 34 |
// } |
| 35 |
|
| 36 |
if(!file_exists(trailingslashit($logDirPath) . '.htaccess')) { |
| 37 |
$this->helper->createHtaccessDenyAll($logDirPath); |
| 38 |
} |
| 39 |
|
| 40 |
$row = date_format(new DateTime(), 'Y-m-d\TH:i:s\Z'); |
| 41 |
$row .= " - "; |
| 42 |
$row .= $this->pluginVersionMessage . $message . "\n\r"; |
| 43 |
file_put_contents($this->helper->getLogPluginPath(), $row, FILE_APPEND); |
| 44 |
} |
| 45 |
} |
| 46 |
|
| 47 |
|
| 48 |
public function logVar($var, $message = null, $force = false) |
| 49 |
{ |
| 50 |
if ($message) { |
| 51 |
$this->log($message, $force); |
| 52 |
} |
| 53 |
$this->log(print_r($var, true),$force); |
| 54 |
} |
| 55 |
} |