TrainingUtils.JOPZ.psm1

function Log-In-File {
    [CmdletBinding()]
    param(
        [Parameter(Mandatory=$true)]
        [string]$Log,
        [Parameter(Mandatory=$true)]
        [string]$Path
    )
    Add-Content -Path $Path -Value $Log
}

function Log {
    [CmdletBinding()]
    param(
        [Parameter(Mandatory=$true, HelpMessage="Tipo de Log")]
        [ValidateSet("INFO", "WARNING", "ERROR", "DEBUG", "VERBOSE")]
        [string]$type,
        [Parameter(Mandatory=$true, HelpMessage="Mensaje a loguear")]
        [string]$log,
        [Parameter(Mandatory=$false, HelpMessage="Ruta para guardar log")]
        [string]$LogFilePath="",
        [Parameter(Mandatory=$false, HelpMessage="Guardar log? true/false")]
        [Boolean]$SaveToDisk=$false,
        [Parameter()]
        [switch]$DebugOnly,
        [Parameter()]
        [switch]$VerboseOnly
        
    )
    $timeStamp  = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
    $showInScreen = $false;
    if (($DebugOnly -and $type -ceq "DEBUG") -or ($VerboseOnly -and $type -ceq "VERBOSE") -or ($type -ceq "INFO" -or $type -ceq "WARNING" -or $type -ceq "ERROR")) {
      $showInScreen = $true
    }

    if($showInScreen){
      Write-Host "[$timeStamp] [$type]: [$log]"
    }

    if($saveToDisk -and $LogFilePath -ne ""){
       Log-In-File -Path $LogFilePath -Log "[$timeStamp] [$type]: [$log]"
    }
}