Feature: Added fileFormat

Added the opportunity to change the format of the log file, this is not the name. but the format. .log .txt etc
This commit is contained in:
Olai Vike Bøe 2024-05-29 10:51:40 +02:00
parent 6ddf7d8889
commit 40942968ae
4 changed files with 21 additions and 7 deletions

View file

@ -11,15 +11,20 @@ if (-not $dateFormat) {
# Function to log messages with the specified date format # Function to log messages with the specified date format
$logFileName = $config.logging.fileName $logFileName = $config.logging.fileName
$logFileFormat = $config.logging.fileFormat
if (-not $logFileName) { if (-not $logFileName) {
$logFileName = "chrome_downloader.log" $logFileName = "chrome_downloader"
} }
if (-not $logFileFormat) {
$logFileFormat = "log"
}
$logFileNameFormat = $logFileName+"."+$logFileFormat
function Log-Message { function Log-Message {
param ( param (
[string]$message [string]$message
) )
$timestamp = Get-Date -Format $dateFormat $timestamp = Get-Date -Format $dateFormat
Write-Output "[$timestamp] - $message" | Out-File -Append -FilePath "$PSScriptRoot\$logFileName" -Encoding utf8 Write-Output "[$timestamp] - $message" | Out-File -Append -FilePath "$PSScriptRoot\$logFileNameFormat" -Encoding utf8
} }
# Log the start of the script # Log the start of the script

View file

@ -19,7 +19,8 @@ The `config.json` file should be structured as follows:
"checkExist": false "checkExist": false
}, },
"logging": { "logging": {
"fileName": "chrome_downloader.log", "fileName": "chrome_downloader",
"fileFormat": "log",
"logDateFormat": "dd/MM/yyyy HH:mm:ss" "logDateFormat": "dd/MM/yyyy HH:mm:ss"
} }
@ -30,7 +31,8 @@ The `config.json` file should be structured as follows:
- `enableForcedVersion`: A boolean flag to enable downloading and installing the forced update version of Chrome. - `enableForcedVersion`: A boolean flag to enable downloading and installing the forced update version of Chrome.
- `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!** ⚠️ - `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.** ⚠️ - `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 format is `chrome_downloader.log`. - `fileName`: A string defining the name of the log file. The default name is `chrome_downloader`.
- `fileFormat`: A string defining the format of the log file. 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`. - `logDateFormat`: A string defining the format of timestamps in logs. The default format is `dd/MM/yyyy HH:mm:ss`.
@ -110,7 +112,7 @@ You can download the script using `git clone` command. Follow these steps:
2. Navigate to the directory where you want to download the script. 2. Navigate to the directory where you want to download the script.
3. Run the following command: 3. Run the following command:
``` ```
git clone https://github.com/OlaYZen/Chrome-Downloader.git git clone https://forgejo.olayzen.com/OlaYZen/Chrome-Downloader.git
``` ```
This command will clone the repository into your current directory. This command will clone the repository into your current directory.

View file

@ -13,15 +13,21 @@ $forceUpdateFolder = Join-Path -Path $PSScriptRoot -ChildPath "Chrome - VERSION_
# Function to log messages with the specified date format # Function to log messages with the specified date format
$logFileName = $config.logging.fileName $logFileName = $config.logging.fileName
$logFileFormat = $config.logging.fileFormat
if (-not $logFileName) { if (-not $logFileName) {
$logFileName = "chrome_downloader.log" $logFileName = "chrome_downloader.log"
} }
if (-not $logFileFormat) {
$logFileFormat = "log"
}
$logFileNameFormat = $logFileName+"."+$logFileFormat
function Log-Message { function Log-Message {
param ( param (
[string]$message [string]$message
) )
$timestamp = Get-Date -Format $dateFormat $timestamp = Get-Date -Format $dateFormat
Write-Output "[$timestamp] - $message" | Out-File -Append -FilePath "$PSScriptRoot\$logFileName" -Encoding utf8 Write-Output "[$timestamp] - $message" | Out-File -Append -FilePath "$PSScriptRoot\$logFileNameFormat" -Encoding utf8
} }
if ($config.options.enableRegularVersion -and -not $config.options.enableForcedVersion) { if ($config.options.enableRegularVersion -and -not $config.options.enableForcedVersion) {

View file

@ -6,7 +6,8 @@
"checkExist": false "checkExist": false
}, },
"logging": { "logging": {
"fileName": "chrome_downloader.log", "fileName": "chrome_downloader",
"fileFormat": "log",
"logDateFormat": "dd/MM/yyyy HH:mm:ss" "logDateFormat": "dd/MM/yyyy HH:mm:ss"
} }
} }