Logger.php 859 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
10
11
<?php
/**
 * Created by PhpStorm.
 * User: crose
 * Date: 2/18/16
 * Time: 5:30 PM
 */

namespace qfq;

require_once(__DIR__ . '/../Constants.php');
12
require_once(__DIR__ . '/../exceptions/UserFormException.php');
13
14
15
16
17
18
19
20

class Logger {

    /**
     * Haengt $msg an $filename an
     *
     * @param $msg
     * @param $filename
21
     * @throws UserFormException
22
23
24
25
     */
    public static function logMessage($msg, $filename) {

        if (!$handle = fopen($filename, 'a')) {
26
            throw new UserFormException("Error - cannot open. File: " . $filename . " ( CWD: " . getcwd() . ")", ERROR_IO_OPEN);
27
28
        }

29

30
        if (fwrite($handle, $msg . PHP_EOL) === FALSE) {
31
            throw new UserFormException("Error - cannot write. File: " . $filename . " ( CWD: " . getcwd() . ")", ERROR_IO_WRITE);
32
33
34
35
36
37
        }

        fclose($handle);
    } // logMessage()

}