functions/Write-SimpleLog.ps1

function Write-SimpleLog {
    param (
        [Parameter(Mandatory = $true)]
        [string] $message,
        [Parameter(Mandatory = $false)]
        [ValidateSet("DEBUG", "INFO", "WARNING", "ERROR", "VERBOSE")]
        [string] $type = "INFO",
        [Parameter(Mandatory = $false)]
        [string] $category = "GENERAL"
    )

    if ([string]::IsNullOrEmpty($script:LogPath) -or $script:LogInitDate -ne (Get-Date).Date) {
        Initialize-Log -LogPath ("{0}\log.log" -f $PWD.Path)
    }

    if ($script:LogPrint -and $type -eq "VERBOSE") {
        Write-Verbose $message
    }

    if ($type -eq "INFO") {
        Write-Host $message
    }

    if ($type -eq "WARNING") {
        Write-Warning $message
    }

    if ($type -eq "ERROR") {
        Write-Host $message -ForegroundColor Red
    }

    $finalLogMessageText = ("{0};{1};{2};{3}" -f (get-date).ToString("dd/MM/yyyy HH:mm"), $type, $category.ToUpper(), $message) 
    foreach ($secret in $script:LogSecrets) {
        $finalLogMessageText = $finalLogMessageText.Replace($secret, "***SECRET***")
    }

    if ($script:LogPrint -or (-not $script:LogPrint -and $type -ne "VERBOSE")) {
        try {
            $finalLogMessageText | Out-File -Path $script:LogPath -Append -Encoding ascii -ErrorAction Stop
        }
        catch {
            Write-Host "CRITICAL LOGGING ERROR: Failed to write to log file '$script:LogPath'. Error: $_" -ForegroundColor Red
        }
    }
}