From d6512495b6089b1c5acd483ff182b0a3334dbfe4 Mon Sep 17 00:00:00 2001 From: Olai Date: Thu, 30 May 2024 09:05:22 +0200 Subject: [PATCH] Feature: clearLogs, A boolean flag to enable clearing of the log(s) file(s). This will clear the content inside of the log file(s). --- Downloader.ps1 | 22 ++++++++++++++++++---- README.md | 12 +++++++----- config.json | 6 ++++-- 3 files changed, 29 insertions(+), 11 deletions(-) diff --git a/Downloader.ps1 b/Downloader.ps1 index 84799fc..e6c18d8 100644 --- a/Downloader.ps1 +++ b/Downloader.ps1 @@ -38,6 +38,20 @@ if (-not $amazonworkspacelogFileFormat) { $amazonworkspacelogFileNameFormat = $amazonworkspacelogFileName+"."+$amazonworkspacelogFileFormat +if ($config.chrome.logging.clearLogs) { + # Construct the full path to the log file + $logFilePathchrome = Join-Path -Path $PSScriptRoot -ChildPath $chromelogFileNameFormat + # Clear the contents of the log file + Set-Content -Path $logFilePathchrome -Value '' +} + +if ($config.amazonWorkspace.logging.clearLogs) { + # Construct the full path to the log file + $logFilePathworkspaces = Join-Path -Path $PSScriptRoot -ChildPath $amazonworkspacelogFileNameFormat + # Clear the contents of the log file + Set-Content -Path $logFilePathworkspaces -Value '' +} + function chrome-Log-Message { param ( [string]$message @@ -93,9 +107,9 @@ if ($config.chrome.options.checkExist) { Remove-Item $testPath -Recurse -Force } - # Output the subfolders + # Output the folders foreach ($subfolder in $subfolders) { - chrome-Log-Message "Info: The subfolder '$subfolder\' has been deleted." + chrome-Log-Message "Info: The folder '$subfolder\' has been deleted." } } if ($config.amazonWorkspace.options.checkExist) { @@ -111,10 +125,10 @@ if ($config.amazonWorkspace.options.checkExist) { Remove-Item $amazonworkspacetestPath -Recurse -Force } - # Output the subfolders + # Output the folders foreach ($amazonworkspacesubfolder in $amazonworkspacesubfolders) { try { - amazonworkspace-Log-Message "Info: The subfolder '$amazonworkspacesubfolder\' has been deleted." + amazonworkspace-Log-Message "Info: The folder '$amazonworkspacesubfolder\' has been deleted." } catch { Write-Host "Error logging message: $_" } diff --git a/README.md b/README.md index bea2e39..6127a3e 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,8 @@ The `config.json` file should be structured as follows: "logging": { "fileName": "google_chrome", "fileFormat": "log", - "logDateFormat": "dd'/'MM'/'yyyy HH:mm:ss" + "logDateFormat": "dd'/'MM'/'yyyy HH:mm:ss", + "clearLogs": false } }, "amazonWorkspace":{ @@ -34,7 +35,8 @@ The `config.json` file should be structured as follows: "logging": { "fileName": "amazon_workspace", "fileFormat": "log", - "logDateFormat": "dd'/'MM'/'yyyy HH:mm:ss" + "logDateFormat": "dd'/'MM'/'yyyy HH:mm:ss", + "clearLogs": false } } } @@ -45,10 +47,10 @@ The `config.json` file should be structured as follows: - `download`: A boolean flag to enable downloading and installing Amazon Workspaces. - `folderNumberedVersion`: A boolean flag to enable the automatic renaming of the folder to the newest version of Chrome. ⚠️ **This option requires administrative privileges when executing the script!** ⚠️ - `checkExist`: A boolean flag to delete old Chrome folders when the script is executed. ⚠️ **This action will delete your Chrome folders, so ensure you have backups if you wish to retain them.** ⚠️ -- `fileName`: A string defining the name of the log file. The default name is `google_chrome` and `amazon_workspace`. -- `fileFormat`: A string defining the format of the log file. The default format is `log`. +- `fileName`: A string defining the name of the log(s) file(s). The default name is `google_chrome` and `amazon_workspace`. +- `fileFormat`: A string defining the format of the log(s) file(s). The default format is `log`. - `logDateFormat`: A string defining the format of timestamps in logs. The default format is `dd/MM/yyyy HH:mm:ss`. - +- `clearLogs`: A boolean flag to enable clearing of the log(s) file(s). This will clear the content inside of the log file(s). ### Date Configuration diff --git a/config.json b/config.json index 13bc0d4..022987f 100644 --- a/config.json +++ b/config.json @@ -9,7 +9,8 @@ "logging": { "fileName": "google_chrome", "fileFormat": "log", - "logDateFormat": "dd'/'MM'/'yyyy HH:mm:ss" + "logDateFormat": "dd'/'MM'/'yyyy HH:mm:ss", + "clearLogs": false } }, "amazonWorkspace":{ @@ -21,7 +22,8 @@ "logging": { "fileName": "amazon_workspace", "fileFormat": "log", - "logDateFormat": "dd'/'MM'/'yyyy HH:mm:ss" + "logDateFormat": "dd'/'MM'/'yyyy HH:mm:ss", + "clearLogs": false } } } \ No newline at end of file