aboutsummaryrefslogtreecommitdiffstats
path: root/public/system/library/googleshopping/log.php
blob: 74a52811d4817d904b3ac5032ff270a100560e14 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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);
        }
    }
}