Write-Log.psm1

Enum errorLevel
{
    INFO
    SUCCESS
    WARNING
    ERROR
    DEBUG
}

Function Write-Log
{
    param(
        [errorLevel][Parameter(Mandatory=$true)]$errorLevel,
        [string]$message,
        [string]$stack = $null
    )
    $date = Get-Date -Format "yyyy-MM-dd HH:mm:ss.fff"
   $errorTab =@(("[INFO]","Yellow"),("[SUCCESS]","Green"),("[WARNING]","Yellow"),("[ERROR]","Red"),("[DEBUG]","DarkYellow"))
   if([int]$errorLevel -gt $errorTab.Count)
   {
       Write-Host $message
   }
   else
   {
    $write = [string]::Format("{0} {1} {2} {3}",$date,$errorTab[[int]$errorLevel][0],$message,$stack)
    Write-Host $write -ForegroundColor $errorTab[[int]$errorLevel][1]
    $write | Out-File -append ([string]::Concat($($MyInvocation.ScriptName.TrimEnd('.ps1')),"_log.txt"))
   }
}
Export-ModuleMember -Function 'Write-Log'