Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,21 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [2.3.1] - 2026-06-29

### Fixed

- `Clear-SPSLog` no longer filters on an undefined `$logFileName` variable (which
resolved to `*`, accidentally working but never targeting `.log` files
specifically). It now takes a `-Filter` parameter (default `*.log`) and honors
`-Retention 0` to disable pruning (#42).

### Changed

- Log retention is no longer hardcoded to 180 days: new config setting
`LogRetentionDays` (default 180, 0 disables pruning), mirroring
`JsonHistoryRetentionDays` (#42).

## [2.3.0] - 2026-06-29

### Added
Expand Down
14 changes: 14 additions & 0 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# SPSWeather - Release Notes

## [2.3.1] - 2026-06-29

### Fixed

- `Clear-SPSLog` now actually targets `.log` files (it was filtering on an
undefined variable). Retention 0 disables pruning.

### Changed

- New config setting `LogRetentionDays` (default 180, 0 disables) replaces the
hardcoded 180-day retention, mirroring `JsonHistoryRetentionDays`.

A full list of changes can be found in the [change log](CHANGELOG.md).

## [2.3.0] - 2026-06-29

### Added
Expand Down
4 changes: 4 additions & 0 deletions src/Config/CONTOSO-PROD.example.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@
# pruning. Default: 30.
JsonHistoryRetentionDays = 30

# LogRetentionDays: how many days of *.log transcript files are kept under
# Logs\ by Clear-SPSLog. 0 disables pruning. Default: 180.
LogRetentionDays = 180

# Farms : one entry per trusted farm to check. Server is the short name; the
# Domain above is appended to build the FQDN targeted for remoting. SqlServers
# is OPTIONAL: the SQL client alias(es) (cliconfg) or server name(s) this farm
Expand Down
33 changes: 16 additions & 17 deletions src/Modules/SPSWeather.Common/Public/Clear-SPSLog.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,34 @@

[Parameter()]
[System.UInt32]
$Retention = 180
$Retention = 180,

[Parameter()]
[System.String]
$Filter = '*.log'
)

if ($Retention -eq 0) {
Write-Verbose -Message "Clear-SPSLog: retention is 0, pruning disabled."
return
}

if (Test-Path $path) {
# Get the current date
$Now = Get-Date
# Define LastWriteTime parameter based on $days
$LastWrite = $Now.AddDays(-$Retention)
# Get files based on lastwrite filter and specified folder
$files = Get-Childitem -Path $path -Filter "$($logFileName)*" | Where-Object -FilterScript {
$_.LastWriteTime -le "$LastWrite"
}
$files = Get-Childitem -Path $path -Filter $Filter -File -ErrorAction SilentlyContinue |
Where-Object -FilterScript { $_.LastWriteTime -le $LastWrite }
if ($files) {
Write-Output '--------------------------------------------------------------'
Write-Output "Cleaning log files in $path ..."
Write-Output "Cleaning files matching '$Filter' in $path (older than $Retention days) ..."
foreach ($file in $files) {
if ($null -ne $file) {
Write-Output "Deleting file $file ..."
Remove-Item $file.FullName | out-null
}
else {
Write-Output 'No more log files to delete'
Write-Output '--------------------------------------------------------------'
}
Write-Output "Deleting file $($file.FullName) ..."
Remove-Item -Path $file.FullName -Force -ErrorAction SilentlyContinue
}
}
else {
Write-Output '--------------------------------------------------------------'
Write-Output "$path - No needs to delete log files"
Write-Output "$path - No needs to delete files matching '$Filter'"
Write-Output '--------------------------------------------------------------'
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Modules/SPSWeather.Common/SPSWeather.Common.psd1
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@{
RootModule = 'SPSWeather.Common.psm1'
ModuleVersion = '2.3.0'
ModuleVersion = '2.3.1'
GUID = 'c39bd612-8520-4e65-9037-80060894d654'
Author = 'Jean-Cyril DROUHIN'
CompanyName = 'luigilink'
Expand Down
3 changes: 2 additions & 1 deletion src/SPSWeather.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ else {
$sqlDiskThreshold = if ($null -ne $envCfg.SQLDiskFreeThresholdPercent) { [int]$envCfg.SQLDiskFreeThresholdPercent } else { 15 }
$sqlBackupMaxAge = if ($null -ne $envCfg.SQLBackupMaxAgeDays) { [int]$envCfg.SQLBackupMaxAgeDays } else { 3 }
$jsonHistoryRetentionDays = if ($null -ne $envCfg.JsonHistoryRetentionDays) { [int]$envCfg.JsonHistoryRetentionDays } else { 30 }
$logRetentionDays = if ($null -ne $envCfg.LogRetentionDays) { [int]$envCfg.LogRetentionDays } else { 180 }
$pathHistoryFolder = Join-Path -Path $pathResultsFolder -ChildPath 'history'
Add-SPSWeatherEvent -Message "SPSWeather $spsWeatherVersion started for $Application/$Environment on $env:COMPUTERNAME." -EntryType 'Information' -EventID 1000
foreach ($spFarm in $spFarms) {
Expand Down Expand Up @@ -473,7 +474,7 @@ else {
}

# Clean the folder of log files
Clear-SPSLog -path $pathLogsFolder -Retention 180
Clear-SPSLog -path $pathLogsFolder -Retention $logRetentionDays

# Send Email
if ($EnableSmtp) {
Expand Down
2 changes: 1 addition & 1 deletion tests/SPSWeather.Common.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Describe 'SPSWeather.Common module' {
}

It 'manifest version is 2.0.0 or higher' {
(Test-ModuleManifest -Path $modulePath).Version | Should -BeGreaterOrEqual ([version]'2.3.0')
(Test-ModuleManifest -Path $modulePath).Version | Should -BeGreaterOrEqual ([version]'2.3.1')
}

It 'exports exactly the expected public functions' {
Expand Down
Loading