Device Log to Server Log

This commit is contained in:
Václav Španinger 2020-07-28 15:40:48 +02:00
parent 98c603494d
commit 7df378d794
2 changed files with 16 additions and 6 deletions

View File

@ -8,9 +8,8 @@ class EndpointsApi extends ApiController{
$command = "null";
//Log
$logManager = new LogManager();
$logManager->setLevel(LOGLEVEL);
$logManager = new LogManager('../logs/api/'. date("Y-m-d").'.log');
$logManager->setLevel(LOGLEVEL);
//Token Checks
if ($obj['token'] == null || !isset($obj['token'])) {
@ -62,7 +61,7 @@ class EndpointsApi extends ApiController{
], 401);
}
//Diagnostic/Log Data Save
//Diagnostic
if (isset($obj['settings'])){
$data = ['mac' => $obj['settings']["network"]["mac"], 'ip_address' => $obj['settings']["network"]["ip"]];
if (array_key_exists("firmware_hash", $obj['settings'])) {
@ -75,6 +74,16 @@ class EndpointsApi extends ApiController{
], 200);
}
//Log Data Save
if (isset($obj['logs'])){
foreach ($deviceLogs as $log) {
$logManager = new LogManager('../logs/devices/'. date("Y-m-d").'.log');
$logManager->setLevel(LOGLEVEL);
$logManager->write("[Device Log Msg] Device_ID " . $deviceId . "->" . $log, LogRecordType::ERROR);
unset($logManager);
}
}
// Issuing command
if ($command == "null"){
$device = DeviceManager::getDeviceByToken($obj['token']);
@ -148,7 +157,7 @@ class EndpointsApi extends ApiController{
}
} else {
if (count(SubDeviceManager::getAllSubDevices($deviceId)) == 0) {
SubDeviceManager::create($deviceId, 'on/off', UNITS[$key]);
//SubDeviceManager::create($deviceId, 'on/off', UNITS[$key]);
//RecordManager::create($deviceId, 'on/off', 0);
}
@ -177,5 +186,6 @@ class EndpointsApi extends ApiController{
$this->response($jsonAnswer);
// this method returns response as json
unset($logManager)
}
}

View File

@ -13,7 +13,7 @@ class UpdatesApi {
header('Content-type: text/plain; charset=utf8', true);
$logManager = new LogManager('../logs/ota/'. date("Y-m-d").'.log');
$logManager->setLevel(LOGLEVEL);
$logManager->write("[Updater] Client Connected", LogRecordTypes::WARNING);
$logManager->write("[Updater] Client Connected", LogRecordTypes::INFO);
//Filtrování IP adress
@ -42,7 +42,7 @@ class UpdatesApi {
$deviceName = $device['name'];
$deviceId = $device['device_id'];
//logfile write
$logManager->write("[Device] device_ID " . $deviceId . " was just updated to new version", LogRecordTypes::WARNING);
$logManager->write("[Device] device_ID " . $deviceId . " was just updated to new version", LogRecordTypes::INFO);
$logManager->write("[Device] version hash: " . md5_file($localBinary), LogRecordTypes::INFO);
//notification
$notificationMng = new NotificationManager;