|
3 | 3 | # installs only expose one app script to the user. |
4 | 4 |
|
5 | 5 | $script:AppName = 'GW Router Logger' |
6 | | -$script:Version = '1.3.0' |
| 6 | +$script:Version = '1.3.1' |
7 | 7 | $script:Publisher = 'Ghostwheel' |
8 | 8 | $script:GitHubOwner = 'GhostwheeI' |
9 | 9 | $script:GitHubRepo = 'GW-Router-Logger' |
10 | 10 | $script:DefaultUdpPort = 514 |
11 | 11 | $script:DefaultTcpPort = 514 |
12 | 12 | $script:DefaultTcpEnabled = $false |
| 13 | +$script:RouterLogBaseName = 'router-current' |
13 | 14 | $script:ActiveLogRotateBytes = 5MB |
14 | 15 | $script:ActiveLogRotateMinutes = 60 |
15 | 16 | $script:MaxCompressedBytes = 100MB |
@@ -723,6 +724,40 @@ function Move-DirectoryContents { |
723 | 724 | } |
724 | 725 | } |
725 | 726 |
|
| 727 | +function Merge-TextFileIntoPath { |
| 728 | + param( |
| 729 | + [Parameter(Mandatory = $true)] [string] $SourcePath, |
| 730 | + [Parameter(Mandatory = $true)] [string] $DestinationPath |
| 731 | + ) |
| 732 | + |
| 733 | + if (-not (Test-Path -LiteralPath $SourcePath)) { |
| 734 | + return |
| 735 | + } |
| 736 | + |
| 737 | + if ([IO.Path]::GetFullPath($SourcePath).TrimEnd('\') -eq [IO.Path]::GetFullPath($DestinationPath).TrimEnd('\')) { |
| 738 | + return |
| 739 | + } |
| 740 | + |
| 741 | + $destinationDirectory = Split-Path -Path $DestinationPath -Parent |
| 742 | + Ensure-Directory -Path $destinationDirectory | Out-Null |
| 743 | + |
| 744 | + if (-not (Test-Path -LiteralPath $DestinationPath)) { |
| 745 | + Move-Item -LiteralPath $SourcePath -Destination $DestinationPath -Force -ErrorAction SilentlyContinue |
| 746 | + return |
| 747 | + } |
| 748 | + |
| 749 | + $sourceContent = Get-Content -LiteralPath $SourcePath -Raw -ErrorAction SilentlyContinue |
| 750 | + if (-not [string]::IsNullOrEmpty($sourceContent)) { |
| 751 | + $destinationHasContent = ((Get-Item -LiteralPath $DestinationPath -ErrorAction SilentlyContinue).Length -gt 0) |
| 752 | + if ($destinationHasContent) { |
| 753 | + Add-Content -LiteralPath $DestinationPath -Value '' -Encoding UTF8 |
| 754 | + } |
| 755 | + Add-Content -LiteralPath $DestinationPath -Value $sourceContent -Encoding UTF8 |
| 756 | + } |
| 757 | + |
| 758 | + Remove-Item -LiteralPath $SourcePath -Force -ErrorAction SilentlyContinue |
| 759 | +} |
| 760 | + |
726 | 761 | function Remove-DirectoryIfEmpty { |
727 | 762 | param([string] $Path) |
728 | 763 |
|
@@ -757,7 +792,7 @@ function Resolve-LogLayout { |
757 | 792 | if (Test-Path -LiteralPath $legacySourceRoot) { |
758 | 793 | $sourceFiles = @(Get-ChildItem -LiteralPath $legacySourceRoot -Force -File -ErrorAction SilentlyContinue) |
759 | 794 | foreach ($file in $sourceFiles) { |
760 | | - Move-Item -LiteralPath $file.FullName -Destination (Join-Path -Path $Settings.SourceLogRoot -ChildPath $file.Name) -Force -ErrorAction SilentlyContinue |
| 795 | + Merge-TextFileIntoPath -SourcePath $file.FullName -DestinationPath (Join-Path -Path $Settings.SourceLogRoot -ChildPath ($script:RouterLogBaseName + '.log')) |
761 | 796 | } |
762 | 797 | } |
763 | 798 | if (Test-Path -LiteralPath $legacyServerArchiveRoot) { |
@@ -1078,7 +1113,7 @@ function New-ListenerScriptBlock { |
1078 | 1113 | $archiveRoot = Join-Path -Path $Settings.RuntimeLogRoot -ChildPath 'archive' |
1079 | 1114 | } |
1080 | 1115 | else { |
1081 | | - $targetPath = Get-SafeLogPath -Directory $Settings.SourceLogRoot -BaseName ($SourceName + '-current') -Suffix '.log' |
| 1116 | + $targetPath = Get-SafeLogPath -Directory $Settings.SourceLogRoot -BaseName $script:RouterLogBaseName -Suffix '.log' |
1082 | 1117 | $archiveRoot = Join-Path -Path $Settings.LogRoot -ChildPath 'archive' |
1083 | 1118 | } |
1084 | 1119 |
|
@@ -1935,9 +1970,7 @@ function Build-ContextMenu { |
1935 | 1970 |
|
1936 | 1971 | function Invoke-SelfTest { |
1937 | 1972 | $config = Get-AppConfig |
1938 | | - Ensure-Directory -Path $config.LogRoot | Out-Null |
1939 | | - Ensure-Directory -Path (Join-Path -Path $config.LogRoot -ChildPath 'sources') | Out-Null |
1940 | | - Ensure-Directory -Path (Join-Path -Path $config.LogRoot -ChildPath 'server') | Out-Null |
| 1973 | + Resolve-LogLayout -Settings $config |
1941 | 1974 | Write-AppLog -Message 'Self-test diagnostic log entry.' -Diagnostic |
1942 | 1975 | 'SELFTEST_OK' |
1943 | 1976 | } |
|
0 commit comments