Skip to content

Commit

Permalink
feat: increase php log level if running trunk plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
dkaser committed Nov 1, 2024
1 parent 8fbecdb commit dc166b9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,22 @@ private static function send_usage(string $url, array $content): int
return -1;
}

public static function setPHPDebug(): void
{
$version = parse_ini_file('/var/local/emhttp/plugins/tailscale/tailscale.ini');

if ( ! $version) {
Utils::logmsg("Could not retrieve system data, skipping debug check.");
return;
}

if ((($version['BRANCH'] ?? "") == "trunk") && ! defined("TAILSCALE_TRUNK")) {
error_reporting(E_ALL);
define("TAILSCALE_TRUNK", true);
self::logmsg("Trunk plugin installed, enabling debug mode", true);
}
}

public static function sendUsageData(Config $config): void
{
$endpoint = "https://plugin-usage.edacerton.win/";
Expand Down Expand Up @@ -191,8 +207,15 @@ public static function run_command(string $command, bool $alwaysShow = false, bo
return $output;
}

public static function logmsg(string $message): void
public static function logmsg(string $message, bool $debug = false): void
{
if ($debug) {
if (defined("TAILSCALE_TRUNK")) {
$message = "DEBUG: " . $message;
} else {
return;
}
}
$timestamp = date('Y/m/d H:i:s');
$filename = basename($_SERVER['PHP_SELF']);
file_put_contents("/var/log/tailscale-utils.log", "{$timestamp} {$filename}: {$message}" . PHP_EOL, FILE_APPEND);
Expand Down
2 changes: 2 additions & 0 deletions src/usr/local/emhttp/plugins/tailscale/include/common.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@
Utils::logmsg("Caught exception in {$file} : " . $e->getMessage());
}
}

Utils::setPHPDebug();

0 comments on commit dc166b9

Please sign in to comment.