fixed ps scripts
This commit is contained in:
104
sf-logs-tail.ps1
104
sf-logs-tail.ps1
@@ -8,38 +8,38 @@
|
||||
A user-friendly wrapper around 'sf apex tail log' that provides real-time
|
||||
debug log monitoring with filtering, formatting, and intelligent output colorization.
|
||||
|
||||
.PARAMETER o
|
||||
.PARAMETER to
|
||||
Target org username or alias
|
||||
|
||||
.PARAMETER UserId
|
||||
.PARAMETER ui
|
||||
Specific user ID to monitor (default: current user)
|
||||
|
||||
.PARAMETER Level
|
||||
.PARAMETER lv
|
||||
Log level: ERROR, WARN, INFO, DEBUG, FINE, FINER, FINEST
|
||||
|
||||
.PARAMETER Duration
|
||||
.PARAMETER dr
|
||||
How long to tail logs in minutes (default: 30)
|
||||
|
||||
.PARAMETER Filter
|
||||
.PARAMETER ft
|
||||
Filter log entries containing pattern
|
||||
|
||||
.PARAMETER ApexOnly
|
||||
.PARAMETER ax
|
||||
Show only Apex-related log entries
|
||||
|
||||
.PARAMETER NoColors
|
||||
.PARAMETER nc
|
||||
Disable colored output
|
||||
|
||||
.PARAMETER Verbose
|
||||
.PARAMETER ve
|
||||
Enable verbose output with timestamps
|
||||
|
||||
.PARAMETER Help
|
||||
.PARAMETER hp
|
||||
Show this help message
|
||||
|
||||
.EXAMPLE
|
||||
.\sf-logs-tail.ps1
|
||||
.\sf-logs-tail.ps1 -Level DEBUG -Duration 60
|
||||
.\sf-logs-tail.ps1 -Filter "MyClass" -ApexOnly
|
||||
.\sf-logs-tail.ps1 -o sandbox -UserId USER123
|
||||
.\sf-logs-tail.ps1 -lv DEBUG -dr 60
|
||||
.\sf-logs-tail.ps1 -ft "MyClass" -ax
|
||||
.\sf-logs-tail.ps1 -to sandbox -ui USER123
|
||||
|
||||
.NOTES
|
||||
This script automatically checks for Salesforce CLI installation and runs
|
||||
@@ -49,20 +49,26 @@
|
||||
#>
|
||||
|
||||
param(
|
||||
[string]$o,
|
||||
[string]$UserId,
|
||||
[string]$to,
|
||||
[string]$ui,
|
||||
[ValidateSet("ERROR", "WARN", "INFO", "DEBUG", "FINE", "FINER", "FINEST")]
|
||||
[string]$Level,
|
||||
[int]$Duration = 30,
|
||||
[string]$Filter,
|
||||
[switch]$ApexOnly,
|
||||
[switch]$NoColors,
|
||||
[switch]$Verbose,
|
||||
[switch]$Help
|
||||
[string]$lv,
|
||||
[int]$dr = 30,
|
||||
[string]$ft,
|
||||
[switch]$ax,
|
||||
[switch]$nc,
|
||||
[switch]$ve,
|
||||
[switch]$hp
|
||||
)
|
||||
|
||||
# Show help if no parameters provided
|
||||
if (-not ($to -or $ui -or $lv -or $dr -ne 30 -or $ft -or $ax -or $nc -or $ve -or $hp)) {
|
||||
Get-Help $MyInvocation.MyCommand.Path -Detailed
|
||||
exit 0
|
||||
}
|
||||
|
||||
# Show help if requested
|
||||
if ($Help) {
|
||||
if ($hp) {
|
||||
Get-Help $MyInvocation.MyCommand.Path -Detailed
|
||||
exit 0
|
||||
}
|
||||
@@ -181,7 +187,7 @@ if (-not (Test-SalesforceCLI)) {
|
||||
}
|
||||
|
||||
# Validate duration
|
||||
if ($Duration -lt 1) {
|
||||
if ($dr -lt 1) {
|
||||
Write-Host "Error: Duration must be at least 1 minute" -ForegroundColor Red
|
||||
exit 1
|
||||
}
|
||||
@@ -190,19 +196,19 @@ if ($Duration -lt 1) {
|
||||
$sfArgs = @("apex", "tail", "log")
|
||||
|
||||
# Add optional parameters
|
||||
if ($o) {
|
||||
if ($to) {
|
||||
$sfArgs += "--target-org"
|
||||
$sfArgs += $o
|
||||
$sfArgs += $to
|
||||
}
|
||||
|
||||
if ($UserId) {
|
||||
if ($ui) {
|
||||
$sfArgs += "--user-id"
|
||||
$sfArgs += $UserId
|
||||
$sfArgs += $ui
|
||||
}
|
||||
|
||||
if ($Level) {
|
||||
if ($lv) {
|
||||
$sfArgs += "--debug-level"
|
||||
$sfArgs += $Level
|
||||
$sfArgs += $lv
|
||||
}
|
||||
|
||||
# Set up signal handlers
|
||||
@@ -212,39 +218,39 @@ Set-SignalHandlers
|
||||
Write-Host "📡 Starting Debug Log Tail" -ForegroundColor Blue
|
||||
Write-Host "===========================" -ForegroundColor Blue
|
||||
|
||||
if ($o) {
|
||||
Write-Host "Target org: $o" -ForegroundColor Cyan
|
||||
if ($to) {
|
||||
Write-Host "Target org: $to" -ForegroundColor Cyan
|
||||
}
|
||||
|
||||
if ($UserId) {
|
||||
Write-Host "User ID: $UserId" -ForegroundColor Cyan
|
||||
if ($ui) {
|
||||
Write-Host "User ID: $ui" -ForegroundColor Cyan
|
||||
} else {
|
||||
Write-Host "User: Current user" -ForegroundColor Cyan
|
||||
}
|
||||
|
||||
if ($Level) {
|
||||
if ($lv) {
|
||||
Write-Host "Log level: " -ForegroundColor Cyan -NoNewline
|
||||
Write-ColorizedLogLevel $Level
|
||||
Write-ColorizedLogLevel $lv
|
||||
Write-Host ""
|
||||
}
|
||||
|
||||
Write-Host "Duration: $Duration minutes" -ForegroundColor Cyan
|
||||
Write-Host "Duration: $dr minutes" -ForegroundColor Cyan
|
||||
|
||||
if ($Filter) {
|
||||
Write-Host "Filter: $Filter" -ForegroundColor Cyan
|
||||
if ($ft) {
|
||||
Write-Host "Filter: $ft" -ForegroundColor Cyan
|
||||
}
|
||||
|
||||
if ($ApexOnly) {
|
||||
if ($ax) {
|
||||
Write-Host "Mode: Apex-only logs" -ForegroundColor Yellow
|
||||
}
|
||||
|
||||
if ($Verbose) {
|
||||
if ($ve) {
|
||||
Write-Host "Verbose: Enabled (with timestamps)" -ForegroundColor Yellow
|
||||
}
|
||||
|
||||
# Color settings
|
||||
$showColors = -not $NoColors
|
||||
if ($NoColors) {
|
||||
$showColors = -not $nc
|
||||
if ($nc) {
|
||||
Write-Host "Colors: Disabled" -ForegroundColor Gray
|
||||
}
|
||||
|
||||
@@ -253,7 +259,7 @@ Write-Host "Press Ctrl+C to stop tailing logs" -ForegroundColor Yellow
|
||||
Write-Host ""
|
||||
|
||||
# Display the command being run
|
||||
if ($Verbose) {
|
||||
if ($ve) {
|
||||
Write-Host "Executing: sf $($sfArgs -join ' ')" -ForegroundColor Gray
|
||||
Write-Host ""
|
||||
}
|
||||
@@ -265,14 +271,14 @@ try {
|
||||
& sf @sfArgs 2>$null
|
||||
} -ArgumentList $sfArgs
|
||||
|
||||
$timeoutTime = (Get-Date).AddMinutes($Duration)
|
||||
$timeoutTime = (Get-Date).AddMinutes($dr)
|
||||
|
||||
while ((Get-Date) -lt $timeoutTime -and $job.State -eq "Running") {
|
||||
$output = Receive-Job $job
|
||||
|
||||
foreach ($line in $output) {
|
||||
if (Test-ShowLogEntry $line $Filter $ApexOnly) {
|
||||
Write-FormattedLogEntry $line $showColors $Verbose
|
||||
if (Test-ShowLogEntry $line $ft $ax) {
|
||||
Write-FormattedLogEntry $line $showColors $ve
|
||||
}
|
||||
}
|
||||
|
||||
@@ -282,8 +288,8 @@ try {
|
||||
# Get any remaining output
|
||||
$finalOutput = Receive-Job $job
|
||||
foreach ($line in $finalOutput) {
|
||||
if (Test-ShowLogEntry $line $Filter $ApexOnly) {
|
||||
Write-FormattedLogEntry $line $showColors $Verbose
|
||||
if (Test-ShowLogEntry $line $ft $ax) {
|
||||
Write-FormattedLogEntry $line $showColors $ve
|
||||
}
|
||||
}
|
||||
|
||||
@@ -299,7 +305,7 @@ try {
|
||||
|
||||
Write-Host ""
|
||||
if ($exitCode -eq 124) {
|
||||
Write-Host "⏰ Log tail timed out after $Duration minutes" -ForegroundColor Yellow
|
||||
Write-Host "⏰ Log tail timed out after $dr minutes" -ForegroundColor Yellow
|
||||
} elseif ($exitCode -eq 0) {
|
||||
Write-Host "✅ Log tail completed successfully" -ForegroundColor Green
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user