mylog.ps1 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # Interactive command line mode
  2. function Interactive-Mode {
  3. while ($true) {
  4. Write-Host "`rEnter command (c: Clear log, p: Print errors, l: View log, t: Tail log, m: Copy error, q: Quit): " -NoNewline
  5. $cmd = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown").Character
  6. Write-Host # New line
  7. switch ($cmd) {
  8. 'c' {
  9. Clear-Content -Path "storage\logs\laravel.log"
  10. Write-Host "Log cleared."
  11. }
  12. 'p' {
  13. $errors = Get-Content "storage\logs\laravel.log" -Encoding UTF8 | Select-String "ERROR"
  14. if ($errors) {
  15. Write-Host
  16. Get-Content "storage\logs\laravel.log" -Encoding UTF8 | Select-String "ERROR"
  17. Write-Host
  18. } else {
  19. Write-Host "No errors found."
  20. }
  21. }
  22. 'l' {
  23. Get-Content "storage\logs\laravel.log" -Encoding UTF8 | Out-Host -Paging
  24. }
  25. 't' {
  26. Get-Content "storage\logs\laravel.log" -Encoding UTF8 -Wait -Tail 1000
  27. }
  28. 'q' {
  29. Write-Host "Exiting program"
  30. exit
  31. }
  32. 'm' {
  33. $errors = Get-Content "storage\logs\laravel.log" -Encoding UTF8 | Select-String "ERROR"
  34. if ($errors) {
  35. $firstError = Get-Content "storage\logs\laravel.log" -Encoding UTF8 | Select-String "ERROR" | Select-Object -First 1
  36. $clipboardText = "$firstError`n`nAbove is the error log. Please help me fix this bug."
  37. Set-Clipboard -Value $clipboardText
  38. Write-Host "Error message copied to clipboard. You can ask AI assistant for help."
  39. } else {
  40. Write-Host "No errors found."
  41. }
  42. }
  43. default {
  44. Write-Host "Invalid command. Use 'c' to clear log, 'p' to print errors, 'l' to view log, 't' to tail log, 'm' to copy error, 'q' to quit."
  45. }
  46. }
  47. }
  48. }
  49. # Run interactive mode
  50. Interactive-Mode