# mail-boxes-etc/trunk/lib/Helper/Logger.php

MBE eShip, version trunk. 55 lines.

- Page: https://pluginprobe.com/plugins/mail-boxes-etc/trunk/code/lib/Helper/Logger.php
- Raw: https://pluginprobe.com/plugins/mail-boxes-etc/trunk/raw/lib/Helper/Logger.php
- Modified: 2024-08-06T10:16:26+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/mail-boxes-etc/trunk/code/lib/Helper/Logger.php#L10-L20`.

```php
<?php

class Mbe_Shipping_Helper_Logger
{
	public static $log = true;

	private $helper;
	private $pluginVersionMessage;

	public function __construct()
	{
		$this->helper = new Mbe_Shipping_Helper_Data();
		$this->pluginVersionMessage = MBE_ESHIP_PLUGIN_NAME.' version ' . MBE_ESHIP_PLUGIN_VERSION . ' :';
	}

	public function log($message, $force = false)
	{
		if ($this->helper->debug() || $force) {


			$logDirPath = $this->helper->getMbeLogDir(); // returns the path checking if it exists and if it's missing it creates it

			// if the directory already exists but the permissions are wrongs, changes it
			if(file_exists($logDirPath) && substr(sprintf('%o', fileperms($logDirPath)), -4)<>0755 ) {
				chmod( $logDirPath, 0755 );
			}

//			if(substr(sprintf('%o', fileperms(MBE_ESHIP_PLUGIN_LOG_DIR)), -4)<>0755 ) {
//				chmod( MBE_ESHIP_PLUGIN_LOG_DIR, 0755 );
//			}
//
//			if (!file_exists(MBE_ESHIP_PLUGIN_LOG_DIR ) ) {
//				mkdir(MBE_ESHIP_PLUGIN_LOG_DIR , 0755, true);
//			}

			if(!file_exists(trailingslashit($logDirPath) . '.htaccess')) {
				$this->helper->createHtaccessDenyAll($logDirPath);
			}

			$row = date_format(new DateTime(), 'Y-m-d\TH:i:s\Z');
			$row .= " - ";
			$row .= $this->pluginVersionMessage . $message . "\n\r";
			file_put_contents($this->helper->getLogPluginPath(), $row, FILE_APPEND);
		}
	}


	public function logVar($var, $message = null, $force = false)
	{
		if ($message) {
			$this->log($message, $force);
		}
		$this->log(print_r($var, true),$force);
	}
}
```
