log.ps1 859 B

123456789101112131415161718192021222324
  1. Get-Content -Path .\logs\rajesh.log -Wait | ForEach-Object {
  2. if ($_ -match '^\[(.*?)\] <(.*?)> \[(.*?)\] (.*)') {
  3. $timestamp = $matches[1]
  4. $fileInfo = $matches[2]
  5. $level = $matches[3]
  6. $message = $matches[4]
  7. switch ($level) {
  8. 'INFO' { $color = 'Cyan' }
  9. 'DBUG' { $color = 'Gray' }
  10. 'WARN' { $color = 'Yellow' }
  11. 'EROR' { $color = 'Red' }
  12. 'FTAL' { $color = 'Magenta' }
  13. default { $color = 'White' }
  14. }
  15. Write-Host "[$timestamp]" -ForegroundColor DarkGray -NoNewline
  16. Write-Host " <$fileInfo>" -ForegroundColor DarkCyan -NoNewline
  17. Write-Host " [$level]" -ForegroundColor $color -NoNewline
  18. Write-Host " $message" -ForegroundColor White
  19. } else {
  20. Write-Host $_ -ForegroundColor White
  21. }
  22. }