1<?php
2/**
3 * Write string to log file and/or print it to screen.
4 *
5 * Example:
6 * log_msg(__LINE__, compact(''));
7 *
8 */
9function log_msg($lineNumber, $data) {
10    global $offlineConf;
11
12    if (($offlineConf['logWriteToFile']) || ($offlineConf['logPrintToScreen'])) {
13        // Assemble output-string:
14        $dateStr = date('Y-m-d');
15        $timeStr = date('H:i:s');
16        $outputStr = "$timeStr L$lineNumber\n";
17        if (gettype($data) == 'array') {
18            foreach ($data as $key=>$element)  {
19             $outputStr .= sprintf("%-20s", $key) . $element . "\n";
20            }
21        } else {
22            // $data contains just a string (i.e. no array-elements)
23            $outputStr .=  $data . "\n\n";
24        }
25
26        // Print out the string $outputStr or write it to file
27        if ($offlineConf['logPrintToScreen']) {
28            // Print to screen:
29            echo $outputStr;
30        }
31
32        if ($offlineConf['logWriteToFile']) {
33			if ($offlineConf['offlineMode'] != 'dryrun') {
34				// Write to file:
35				$fileNameWithPathStr = $offlineConf['logDirectory'] . '/' . $offlineConf['logDefaultFileName'];
36				$filehandle = fopen($fileNameWithPathStr, 'a+');
37					fputs($filehandle, $outputStr);
38				fclose($filehandle);
39			}
40        }
41    }
42}
43
44
45?>