aboutsummaryrefslogtreecommitdiffstats
path: root/public/system/library/googleshopping/log.php
diff options
context:
space:
mode:
Diffstat (limited to 'public/system/library/googleshopping/log.php')
-rw-r--r--public/system/library/googleshopping/log.php55
1 files changed, 55 insertions, 0 deletions
diff --git a/public/system/library/googleshopping/log.php b/public/system/library/googleshopping/log.php
new file mode 100644
index 0000000..74a5281
--- /dev/null
+++ b/public/system/library/googleshopping/log.php
@@ -0,0 +1,55 @@
+<?php
+
+namespace googleshopping;
+
+/**
+* Log class
+*/
+class Log {
+ private $handle;
+
+ /**
+ * Constructor
+ *
+ * @param string $filename
+ */
+ public function __construct($filename, $max_size = 8388608) {
+ $file = DIR_LOGS . $filename;
+
+ clearstatcache(true);
+
+ if ((!file_exists($file) && !is_writable(DIR_LOGS)) || (file_exists($file) && !is_writable($file))) {
+ // Do nothing, as we have no permissions
+ return;
+ }
+
+ if (file_exists($file) && filesize($file) >= $max_size) {
+ $mode = 'wb';
+ } else {
+ $mode = 'ab';
+ }
+
+ $this->handle = @fopen(DIR_LOGS . $filename, $mode);
+ }
+
+ /**
+ *
+ *
+ * @param string $message
+ */
+ public function write($message) {
+ if (is_resource($this->handle)) {
+ fwrite($this->handle, date('Y-m-d G:i:s') . ' - ' . print_r($message, true) . "\n");
+ }
+ }
+
+ /**
+ *
+ *
+ */
+ public function __destruct() {
+ if (is_resource($this->handle)) {
+ fclose($this->handle);
+ }
+ }
+}