Browse Source

convert plex homepage logger to new logger system
convert sabnzbd homepage logger to new logger system
convert tautulli homepage logger to new logger system

CauseFX 4 years ago
parent
commit
b7a6d3bf64
3 changed files with 23 additions and 11 deletions
  1. 5 4
      api/homepage/plex.php
  2. 14 5
      api/homepage/sabnzbd.php
  3. 4 2
      api/homepage/tautulli.php

+ 5 - 4
api/homepage/plex.php

@@ -671,10 +671,11 @@ trait PlexHomepageItem
 	{
 		if ($this->config['tautulliURL'] && $this->config['tautulliApikey'] && $this->config['homepageUseCustomStreamNames']) {
 			$names = $this->getTautulliFriendlyNames(true);
-			if (json_encode($names) !== $this->config['homepageCustomStreamNames']) {
-				$this->updateConfig(array('homepageCustomStreamNames' => json_encode($names)));
-				$this->config['homepageCustomStreamNames'] = json_encode($names);
-				$this->debug('Updating Tautulli custom names config item', 'SYSTEM');
+			$names = json_encode($names);
+			if ($names !== $this->config['homepageCustomStreamNames']) {
+				$this->updateConfig(array('homepageCustomStreamNames' => $names));
+				$this->config['homepageCustomStreamNames'] = $names;
+				$this->setLoggerChannel('Tautulli')->debug('Updating Tautulli custom names config item', $names);
 			}
 		}
 	}

+ 14 - 5
api/homepage/sabnzbd.php

@@ -49,6 +49,8 @@ trait SabNZBdHomepageItem
 	
 	public function testConnectionSabNZBd()
 	{
+		$this->setLoggerChannel('Sabnzbd Homepage');
+		$this->logger->debug('Starting API Connection Test');
 		if (!empty($this->config['sabnzbdURL']) && !empty($this->config['sabnzbdToken'])) {
 			$url = $this->qualifyURL($this->config['sabnzbdURL']);
 			$url = $url . '/api?mode=queue&output=json&apikey=' . $this->config['sabnzbdToken'];
@@ -66,16 +68,20 @@ trait SabNZBdHomepageItem
 						$message = $data['error'];
 					}
 					$this->setAPIResponse($status, $message, $responseCode, $data);
+					$this->logger->debug('API Connection Test was successful');
 					return true;
 				} else {
 					$this->setAPIResponse('error', $response->body, 500);
+					$this->logger->debug('API Connection Test was unsuccessful');
 					return false;
 				}
 			} catch (Requests_Exception $e) {
+				$this->logger->critical($e, [$url]);
 				$this->setAPIResponse('error', $e->getMessage(), 500);
 				return false;
-			};
+			}
 		} else {
+			$this->logger->debug('URL and/or Token not setup');
 			$this->setAPIResponse('error', 'URL and/or Token not setup', 422);
 			return 'URL and/or Token not setup';
 		}
@@ -121,6 +127,7 @@ trait SabNZBdHomepageItem
 	
 	public function getSabNZBdHomepageQueue()
 	{
+		$this->setLoggerChannel('Sabnzbd Homepage');
 		if (!$this->homepageItemPermissions($this->sabNZBdHomepagePermissions('main'), true)) {
 			return false;
 		}
@@ -133,7 +140,7 @@ trait SabNZBdHomepageItem
 				$api['content']['queueItems'] = json_decode($response->body, true);
 			}
 		} catch (Requests_Exception $e) {
-			$this->writeLog('error', 'SabNZBd Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
+			$this->logger->critical($e, [$url]);
 			$this->setAPIResponse('error', $e->getMessage(), 500);
 			return false;
 		};
@@ -146,7 +153,7 @@ trait SabNZBdHomepageItem
 				$api['content']['historyItems'] = json_decode($response->body, true);
 			}
 		} catch (Requests_Exception $e) {
-			$this->writeLog('error', 'SabNZBd Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
+			$this->logger->critical($e, [$url]);
 			$this->setAPIResponse('error', $e->getMessage(), 500);
 			return false;
 		};
@@ -157,6 +164,7 @@ trait SabNZBdHomepageItem
 	
 	public function pauseSabNZBdQueue($target = null)
 	{
+		$this->setLoggerChannel('Sabnzbd Homepage');
 		if (!$this->homepageItemPermissions($this->sabNZBdHomepagePermissions('main'), true)) {
 			return false;
 		}
@@ -170,7 +178,7 @@ trait SabNZBdHomepageItem
 				$api['content'] = json_decode($response->body, true);
 			}
 		} catch (Requests_Exception $e) {
-			$this->writeLog('error', 'SabNZBd Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
+			$this->logger->critical($e, [$url]);
 			$this->setAPIResponse('error', $e->getMessage(), 500);
 			return false;
 		};
@@ -181,6 +189,7 @@ trait SabNZBdHomepageItem
 	
 	public function resumeSabNZBdQueue($target = null)
 	{
+		$this->setLoggerChannel('Sabnzbd Homepage');
 		if (!$this->homepageItemPermissions($this->sabNZBdHomepagePermissions('main'), true)) {
 			return false;
 		}
@@ -194,7 +203,7 @@ trait SabNZBdHomepageItem
 				$api['content'] = json_decode($response->body, true);
 			}
 		} catch (Requests_Exception $e) {
-			$this->writeLog('error', 'SabNZBd Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
+			$this->logger->critical($e, [$url]);
 			$this->setAPIResponse('error', $e->getMessage(), 500);
 			return false;
 		};

+ 4 - 2
api/homepage/tautulli.php

@@ -66,6 +66,7 @@ trait TautulliHomepageItem
 	
 	public function testConnectionTautulli()
 	{
+		$this->setLoggerChannel('Tautulli Homepage');
 		if (empty($this->config['tautulliURL'])) {
 			$this->setAPIResponse('error', 'Tautulli URL is not defined', 422);
 			return false;
@@ -88,7 +89,7 @@ trait TautulliHomepageItem
 				return false;
 			}
 		} catch (Requests_Exception $e) {
-			$this->writeLog('error', 'Tautulli Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
+			$this->logger->critical($e, [$url]);
 			$this->setAPIResponse('error', $e->getMessage(), 500);
 			return false;
 		}
@@ -131,6 +132,7 @@ trait TautulliHomepageItem
 	
 	public function getTautulliHomepageData()
 	{
+		$this->setLoggerChannel('Tautulli Homepage');
 		if (!$this->homepageItemPermissions($this->tautulliHomepagePermissions('main'), true)) {
 			return false;
 		}
@@ -215,7 +217,7 @@ trait TautulliHomepageItem
 				}
 			}
 		} catch (Requests_Exception $e) {
-			$this->writeLog('error', 'Tautulli Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
+			$this->logger->critical($e, [$url]);
 			$this->setAPIResponse('error', $e->getMessage(), 500);
 			return false;
 		};