Files
2025-11-06 20:55:35 +02:00

138 lines
4.1 KiB
PowerShell

<#
.SYNOPSIS
BTGO Telegram Bot - View Logs Script
.DESCRIPTION
Afiseaza logurile serviciului in timp real
#>
$ScriptDir = Split-Path -Parent $PSCommandPath
$ProjectDir = Resolve-Path (Join-Path $ScriptDir "..\..\..") | Select-Object -ExpandProperty Path
$LogDir = Join-Path $ProjectDir "logs"
$StdoutLog = Join-Path $LogDir "telegram_bot_stdout.log"
$StderrLog = Join-Path $LogDir "telegram_bot_stderr.log"
function Show-Menu {
Clear-Host
Write-Host ""
Write-Host ("=" * 80) -ForegroundColor Cyan
Write-Host " BTGO TELEGRAM BOT - VIEWER LOGS" -ForegroundColor Yellow
Write-Host ("=" * 80) -ForegroundColor Cyan
Write-Host ""
Write-Host "Logs directory: $LogDir" -ForegroundColor Cyan
Write-Host ""
Write-Host "Selecteaza optiune:" -ForegroundColor Yellow
Write-Host ""
Write-Host " 1. Vizualizare stdout (output normal)"
Write-Host " 2. Vizualizare stderr (erori)"
Write-Host " 3. Tail stdout (timp real - ultim 30 linii)"
Write-Host " 4. Tail stderr (timp real - ultim 30 linii)"
Write-Host " 5. Deschide director logs in Explorer"
Write-Host " 6. Sterge toate logurile"
Write-Host " 0. Iesire"
Write-Host ""
}
function View-Stdout {
Clear-Host
Write-Host ("=" * 80) -ForegroundColor Cyan
Write-Host "STDOUT LOG" -ForegroundColor Yellow
Write-Host ("=" * 80) -ForegroundColor Cyan
Write-Host ""
if (Test-Path $StdoutLog) {
Get-Content $StdoutLog
} else {
Write-Host "[INFO] Log-ul nu exista inca" -ForegroundColor Yellow
}
Write-Host ""
Read-Host "Apasa Enter pentru a reveni la meniu"
}
function View-Stderr {
Clear-Host
Write-Host ("=" * 80) -ForegroundColor Cyan
Write-Host "STDERR LOG" -ForegroundColor Yellow
Write-Host ("=" * 80) -ForegroundColor Cyan
Write-Host ""
if (Test-Path $StderrLog) {
Get-Content $StderrLog
} else {
Write-Host "[INFO] Log-ul nu exista inca" -ForegroundColor Yellow
}
Write-Host ""
Read-Host "Apasa Enter pentru a reveni la meniu"
}
function Tail-Stdout {
Clear-Host
Write-Host ("=" * 80) -ForegroundColor Cyan
Write-Host "STDOUT TAIL - TIMP REAL (Apasa Ctrl+C pentru a opri)" -ForegroundColor Yellow
Write-Host ("=" * 80) -ForegroundColor Cyan
Write-Host ""
if (Test-Path $StdoutLog) {
Get-Content $StdoutLog -Wait -Tail 30
} else {
Write-Host "[INFO] Log-ul nu exista inca" -ForegroundColor Yellow
Start-Sleep -Seconds 2
}
}
function Tail-Stderr {
Clear-Host
Write-Host ("=" * 80) -ForegroundColor Cyan
Write-Host "STDERR TAIL - TIMP REAL (Apasa Ctrl+C pentru a opri)" -ForegroundColor Yellow
Write-Host ("=" * 80) -ForegroundColor Cyan
Write-Host ""
if (Test-Path $StderrLog) {
Get-Content $StderrLog -Wait -Tail 30
} else {
Write-Host "[INFO] Log-ul nu exista inca" -ForegroundColor Yellow
Start-Sleep -Seconds 2
}
}
function Open-LogsExplorer {
if (Test-Path $LogDir) {
explorer $LogDir
} else {
Write-Host "[INFO] Directorul logs nu exista" -ForegroundColor Yellow
Start-Sleep -Seconds 2
}
}
function Clear-AllLogs {
Write-Host ""
Write-Host "[AVERTIZARE] Stergi TOATE logurile?" -ForegroundColor Yellow
$confirm = Read-Host "Confirma (Y/N)"
if ($confirm -eq "Y" -or $confirm -eq "y") {
Remove-Item (Join-Path $LogDir "*.log") -Force -ErrorAction SilentlyContinue
Write-Host "[OK] Loguri sterse" -ForegroundColor Green
} else {
Write-Host "[INFO] Anulat" -ForegroundColor Cyan
}
Start-Sleep -Seconds 2
}
# Main loop
do {
Show-Menu
$choice = Read-Host "Optiune (0-6)"
switch ($choice) {
"1" { View-Stdout }
"2" { View-Stderr }
"3" { Tail-Stdout }
"4" { Tail-Stderr }
"5" { Open-LogsExplorer }
"6" { Clear-AllLogs }
"0" {
Write-Host ""
Write-Host "Bye!" -ForegroundColor Green
exit 0
}
default {
Write-Host "[EROARE] Optiune invalida!" -ForegroundColor Red
Start-Sleep -Seconds 1
}
}
} while ($true)