WMS_MAIN/search_logs.ps1
liufumingren 8cf2c5befa 1
2026-05-20 16:31:29 +08:00

42 lines
1.5 KiB
PowerShell

$targetTs = "2026-05-20 02:20:00"
$kws = @(
'print-retry-compensation',
'print_retry_compensation\\.js',
'retryFailed',
'触发补打',
'任务执行完成',
'SCHEDULE /__schedule\?path=D:\\\\wms\\\\app\\\\schedule\\\\print_retry_compensation\\.js'
)
$sqlPart = "FROM `wms_print_record` AS `PrintRecord` WHERE ((`PrintRecord`.`send_status` = 'send_failed' OR `PrintRecord`.`print_status` IN ('print_failed', 'timeout'))"
$results = New-Object System.Collections.Generic.List[string]
$file = Get-Item "logs/wms/wms-web.log"
$lines = Get-Content $file.FullName
for ($i = 0; $i -lt $lines.Count; $i++) {
$line = $lines[$i]
if ($line -match '^(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})') {
$ts = $matches[1]
if ($ts -ge $targetTs) {
foreach ($k in $kws) {
if ($line -match $k) {
$item = "$($file.Name):$($i+1):$line"
$results.Add($item)
Write-Output $item
break
}
}
}
}
}
if ($results.Count -lt 5) {
$sqlSearch = $sqlPart.Replace("`", "")
for ($i = 0; $i -lt $lines.Count; $i++) {
$line = $lines[$i]
if ($line -match '^(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})') {
if ($matches[1] -ge $targetTs -and $line.Contains($sqlSearch)) {
$item = "$($file.Name):$($i+1):$line"
if (-not $results.Contains($item)) { Write-Output $item }
}
}
}
}