File: log.php

package info (click to toggle)
phamm 0.6.2-1.2
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 2,180 kB
  • ctags: 828
  • sloc: php: 2,963; xml: 893; perl: 541; sh: 468; makefile: 62; python: 57
file content (62 lines) | stat: -rw-r--r-- 1,458 bytes parent folder | download | duplicates (2)
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
56
57
58
59
60
61
62
<?php

class PhammLog
{
    private $day;
    private $hour;
    private $ip;
    private $resultLabel;
    private $logFile;
    private $log_row;

    public function __construct()
    {
        $this->day = date('Y'.'-'.'m'.'-'.'d');
        $this->hour = date ('H'.':'.'i'.':'.'s');
        $this->ip = $_SERVER["REMOTE_ADDR"];
    }

    /**
    * Write a log in to file
    *
    * TODO see:
    * Log the operations in to file
    * http://www.w3.org/Daemon/User/Config/Logging.html#common-logfile-format
    *
    * @package Phamm
    * @author Alessandro De Zorzi <adezorzi@rhx.it>
    *
    * @param string $pn
    * @param string $user
    * @param string $operation
    * @param bool $result
    **/
    public function phamm_log ($pn,$user,$operation,$result)
    {
        if (PHAMM_LOG == 1)
        {
            if (!$pn)
                $pn = 'phamm';

            if ($result)
                $this->resultLabel = 'OK';
            else
                $this->resultLabel = 'FAILED';

            // Set the file in Append mode
            $this->logFile = fopen (LOG_FILE,'a');

            // Prepare the log string
            $this->log_row = "$this->ip - $user [$this->day $this->hour] \"$pn : $operation\" $this->resultLabel\n";

            // Write the log in to file
            fwrite ($this->logFile,$this->log_row);

            // Close the file
            fclose ($this->logFile);
        }

        return true;
    }
//
}