Skip to content

Commit e428357

Browse files
committed
Add logging support
* Original implementation: vegetalte-dev@7c3ec61 adapted by @eloimuns
1 parent 37fa6a8 commit e428357

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

src/Helpers/Builds.php

+3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
use \Flight;
2828
use \JX\CmOta\Helpers\Build;
29+
use \JX\CmOta\Helpers\Logger;
2930

3031
class Builds {
3132

@@ -40,6 +41,8 @@ class Builds {
4041
public function __construct() {
4142
// Get the current POST request data
4243
$this->postData = Flight::request()->data;
44+
$log = new Logger();
45+
$log->logWrite(Flight::request()->ip . ' ' . $this->postData['params']['device'] . ' ' . $this->postData['params']['source_incremental']);
4346

4447
// Internal Initialization routines
4548
$this->getBuilds();

src/Helpers/Logger.php

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
namespace JX\CmOta\Helpers;
4+
5+
class Logger {
6+
private $lName = null;
7+
private $handle = null;
8+
9+
public function __construct($logName = null) {
10+
if ($logName) $this->lName = $logName; //Define Log Name!
11+
else $this->lName = "Log"; //Default name
12+
$this->logOpen(); //Begin logging.
13+
}
14+
15+
function __destruct() {
16+
fclose($this->handle); //Close when php script ends (always better to be proper.)
17+
}
18+
19+
//Open Logfile
20+
private function logOpen() {
21+
$today = date('Y-m-d'); //Current Date
22+
$this->handle = fopen('logs/' . $this->lName . '_' . $today, 'a') or exit("Can't open " . $this->lName . "_" . $today); //Open log file for writing, if it does not exist, create it.
23+
}
24+
25+
//Write Message to Logfile
26+
public function logWrite($message) {
27+
$time = date('Y-m-d @ H:i:s -'); //Grab Time
28+
fwrite($this->handle, $time . " " . $message . "\n"); //Output to logfile
29+
}
30+
31+
//Clear Logfile
32+
public function logClear() {
33+
ftruncate($this->handle, 0);
34+
}
35+
}

0 commit comments

Comments
 (0)